SRE • Monitoring • Prometheus
Prometheus Commands & PromQL Cheat Sheet
Practical Prometheus commands, promtool utilities, PromQL queries, monitoring, alerting, recording rules, configuration, Kubernetes monitoring and production troubleshooting.
What is Prometheus?
Prometheus is a monitoring and alerting system that collects time-series metrics from monitored targets. PromQL is its query language for selecting, aggregating and analyzing those metrics.
Prometheus Command Categories
Jump directly to the Prometheus and PromQL commands you need.
Prometheus Setup and Version
6Prometheus commands for prometheus setup and version.
View commands →Prometheus Docker
6Prometheus commands for prometheus docker.
View commands →Prometheus Configuration
6Prometheus commands for prometheus configuration.
View commands →Prometheus Targets and Scraping
5Prometheus commands for prometheus targets and scraping.
View commands →PromQL Basics
6Prometheus commands for promql basics.
View commands →PromQL Label Selectors
6Prometheus commands for promql label selectors.
View commands →PromQL Aggregation
8Prometheus commands for promql aggregation.
View commands →PromQL Rates and Counters
5Prometheus commands for promql rates and counters.
View commands →PromQL CPU and Memory
4Prometheus commands for promql cpu and memory.
View commands →PromQL Disk and Filesystem
4Prometheus commands for promql disk and filesystem.
View commands →PromQL HTTP and Application Monitoring
4Prometheus commands for promql http and application monitoring.
View commands →PromQL Histograms
6Prometheus commands for promql histograms.
View commands →PromQL Operators
5Prometheus commands for promql operators.
View commands →Recording Rules
4Prometheus commands for recording rules.
View commands →Alerting Rules
5Prometheus commands for alerting rules.
View commands →Promtool Configuration Validation
6Prometheus commands for promtool configuration validation.
View commands →Promtool Health Checks
4Prometheus commands for promtool health checks.
View commands →Promtool Querying
4Prometheus commands for promtool querying.
View commands →Promtool Debugging
3Prometheus commands for promtool debugging.
View commands →Promtool Rule Testing
3Prometheus commands for promtool rule testing.
View commands →Prometheus HTTP API
6Prometheus commands for prometheus http api.
View commands →Prometheus Runtime and Reload
6Prometheus commands for prometheus runtime and reload.
View commands →Prometheus Storage
4Prometheus commands for prometheus storage.
View commands →Prometheus Query Performance
3Prometheus commands for prometheus query performance.
View commands →Kubernetes Monitoring
6Prometheus commands for kubernetes monitoring.
View commands →Production Troubleshooting
8Prometheus commands for production troubleshooting.
View commands →CI/CD Prometheus Workflow
6Prometheus commands for ci/cd prometheus workflow.
View commands →Recommended Prometheus Workflow
8Prometheus commands for recommended prometheus workflow.
View commands →Showing 147 commands across 28 categories.
Prometheus Setup and Version
6 commandsprometheus --versionDisplay the installed Prometheus version.
prometheus --helpDisplay Prometheus command-line help.
prometheus --help-longDisplay detailed Prometheus command-line options.
prometheus --config.file=prometheus.ymlStart Prometheus using a specified configuration file.
prometheus --web.listen-address=0.0.0.0:9090Configure the address and port used by the Prometheus web server.
prometheus --log.level=debugStart Prometheus with debug-level logging.
Prometheus Docker
6 commandsdocker pull prom/prometheusDownload the official Prometheus container image.
docker run -p 9090:9090 prom/prometheusRun Prometheus in Docker and expose port 9090.
docker run -p 9090:9090 -v ./prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheusRun Prometheus with a custom configuration file.
docker run -d --name prometheus -p 9090:9090 prom/prometheusRun Prometheus as a detached Docker container.
docker logs prometheusView Prometheus container logs.
docker restart prometheusRestart the Prometheus container.
Prometheus Configuration
6 commandsprometheus --config.file=prometheus.ymlSpecify the Prometheus configuration file.
promtool check config prometheus.ymlValidate a Prometheus configuration file.
promtool check config prometheus.yml --lint=allValidate configuration and apply available lint checks.
prometheus --config.file=prometheus.yml --config.auto-reloadEnable automatic configuration reload behavior.
curl -X POST http://localhost:9090/-/reloadTrigger a configuration reload when the lifecycle endpoint is enabled.
kill -HUP <prometheus-pid>Reload Prometheus configuration by sending SIGHUP on supported systems.
Prometheus Targets and Scraping
5 commandscurl http://localhost:9090/api/v1/targetsQuery Prometheus target information through the HTTP API.
curl http://localhost:9090/api/v1/targets?state=activeQuery active Prometheus targets.
curl http://localhost:9090/metricsView Prometheus's own exposed metrics.
curl http://localhost:9100/metricsView metrics exposed by a Node Exporter endpoint.
promtool check service-discovery prometheus.yml <job>Inspect service discovery and relabeling for a configured job.
PromQL Basics
6 commandsupReturn the health status of scraped targets.
up{job="node"}Select target health metrics for the node job.
node_cpu_seconds_totalQuery the Node Exporter CPU time metric.
node_memory_MemAvailable_bytesQuery available system memory exposed by Node Exporter.
node_filesystem_avail_bytesQuery available filesystem space.
http_requests_totalQuery an HTTP request counter metric.
PromQL Label Selectors
6 commandsup{job="node"}Select series where the job label equals node.
up{job!="node"}Select series where the job label is not node.
up{job=~"node|api"}Select series whose job label matches a regular expression.
up{job!~"test.*"}Exclude series whose job label matches a regular expression.
http_requests_total{status="500"}Select HTTP requests with a 500 status label.
http_requests_total{method="GET",status="200"}Select HTTP requests matching multiple labels.
PromQL Aggregation
8 commandssum(up)Calculate the sum of selected series.
avg(up)Calculate the average value across series.
min(up)Return the minimum value across series.
max(up)Return the maximum value across series.
count(up)Count the number of returned series.
sum by (job) (up)Aggregate target status by job.
sum by (instance) (up)Aggregate target status by instance.
sum without (instance) (up)Aggregate while excluding the instance label from grouping.
PromQL Rates and Counters
5 commandsrate(http_requests_total[5m])Calculate the per-second average increase of a counter over five minutes.
irate(http_requests_total[5m])Calculate the per-second rate using the most recent samples.
increase(http_requests_total[1h])Calculate the total counter increase over one hour.
sum(rate(http_requests_total[5m]))Calculate the total request rate across selected series.
sum by (status) (rate(http_requests_total[5m]))Calculate request rate grouped by HTTP status.
PromQL CPU and Memory
4 commands100 * (1 - avg(rate(node_cpu_seconds_total{mode="idle"}[5m])))Estimate overall CPU utilization from idle CPU time.
100 * (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)Calculate memory utilization percentage.
sum by (instance) (rate(node_cpu_seconds_total[5m]))Calculate CPU time rate grouped by instance.
node_memory_MemTotal_bytes - node_memory_MemAvailable_bytesCalculate used memory in bytes.
PromQL Disk and Filesystem
4 commandsnode_filesystem_avail_bytes{fstype!="tmpfs"}Query available filesystem space while excluding tmpfs.
100 * (1 - node_filesystem_avail_bytes / node_filesystem_size_bytes)Calculate filesystem usage percentage.
node_filesystem_readonly == 1Find filesystems mounted as read-only.
node_filesystem_avail_bytes / 1024 / 1024 / 1024Convert available filesystem space from bytes to GiB.
PromQL HTTP and Application Monitoring
4 commandssum(rate(http_requests_total[5m]))Calculate application request rate.
sum(rate(http_requests_total{status=~"5.."}[5m]))Calculate HTTP 5xx error rate.
100 * sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m]))Calculate the percentage of requests returning HTTP 5xx responses.
histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))Calculate the 95th percentile request latency from a classic histogram.
PromQL Histograms
6 commandsrate(http_request_duration_seconds_bucket[5m])Calculate the per-second rate for histogram buckets.
sum by (le) (rate(http_request_duration_seconds_bucket[5m]))Aggregate histogram bucket rates.
histogram_quantile(0.50, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))Calculate the 50th percentile latency.
histogram_quantile(0.90, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))Calculate the 90th percentile latency.
histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))Calculate the 95th percentile latency.
histogram_quantile(0.99, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))Calculate the 99th percentile latency.
PromQL Operators
5 commandsnode_memory_MemTotal_bytes - node_memory_MemAvailable_bytesSubtract available memory from total memory.
node_filesystem_avail_bytes / node_filesystem_size_bytesCalculate the filesystem availability ratio.
rate(http_requests_total[5m]) * 60Convert a per-second rate into an approximate per-minute rate.
up == 0Select targets whose up value is zero.
node_filesystem_avail_bytes < 10737418240Find filesystems with less than approximately 10 GiB available.
Recording Rules
4 commandspromtool check rules rules.ymlValidate Prometheus recording and alerting rules.
promtool test rules test.ymlRun unit tests for Prometheus rules.
record: job:http_requests:rate5mExample recording rule name for a reusable five-minute request rate.
expr: sum by (job) (rate(http_requests_total[5m]))Example PromQL expression used by a recording rule.
Alerting Rules
5 commandspromtool check rules alerts.ymlValidate alerting rules before deployment.
promtool test rules alerts-test.ymlUnit test alerting rules.
alert: HighCPUUsageExample alert name for high CPU utilization.
expr: cpu_usage > 80Example alert expression for CPU utilization.
for: 5mRequire an alert expression to remain active for a specified duration.
Promtool Configuration Validation
6 commandspromtool --helpDisplay promtool command-line help.
promtool check config prometheus.ymlValidate Prometheus configuration.
promtool check rules rules.ymlValidate rule files.
promtool check web-config web.ymlValidate Prometheus web configuration.
promtool check metricsValidate metrics supplied through standard input.
curl -s http://localhost:9090/metrics | promtool check metricsValidate metrics exposed by a running Prometheus server.
Promtool Health Checks
4 commandspromtool check healthyCheck whether the Prometheus server is healthy.
promtool check readyCheck whether the Prometheus server is ready.
promtool check healthy --url=http://localhost:9090Check Prometheus health at a specific URL.
promtool check ready --url=http://localhost:9090Check Prometheus readiness at a specific URL.
Promtool Querying
4 commandspromtool query instant http://localhost:9090 upRun an instant PromQL query against Prometheus.
promtool query range http://localhost:9090 'rate(http_requests_total[5m])'Run a range query against Prometheus.
promtool query series http://localhost:9090Query series information from Prometheus.
promtool query labels http://localhost:9090 __name__Query label values from Prometheus.
Promtool Debugging
3 commandspromtool debug metrics http://localhost:9090Fetch Prometheus metrics debugging information.
promtool debug pprof http://localhost:9090Fetch profiling information from Prometheus.
promtool debug all http://localhost:9090Fetch available Prometheus debug information.
Promtool Rule Testing
3 commandspromtool test rules test.ymlRun Prometheus rule unit tests.
promtool test rules test.yml --run <test-name>Run selected rule test groups.
promtool test rules test.yml --junit results.xmlWrite rule test results in JUnit XML format.
Prometheus HTTP API
6 commandscurl http://localhost:9090/api/v1/query?query=upExecute an instant PromQL query through the HTTP API.
curl 'http://localhost:9090/api/v1/query_range?query=up&start=<start>&end=<end>&step=15s'Execute a range PromQL query through the HTTP API.
curl http://localhost:9090/api/v1/targetsRetrieve target information through the API.
curl http://localhost:9090/api/v1/rulesRetrieve configured recording and alerting rules.
curl http://localhost:9090/api/v1/alertsRetrieve currently active alerts.
curl http://localhost:9090/api/v1/label/__name__/valuesRetrieve metric name label values.
Prometheus Runtime and Reload
6 commandscurl http://localhost:9090/-/healthyCheck the Prometheus HTTP health endpoint.
curl http://localhost:9090/-/readyCheck the Prometheus HTTP readiness endpoint.
curl -X POST http://localhost:9090/-/reloadReload configuration when lifecycle management is enabled.
curl http://localhost:9090/api/v1/status/configRetrieve the current Prometheus configuration.
curl http://localhost:9090/api/v1/status/runtimeinfoRetrieve Prometheus runtime information.
curl http://localhost:9090/api/v1/status/flagsRetrieve Prometheus runtime flag values.
Prometheus Storage
4 commandsprometheus --storage.tsdb.path=/prometheusConfigure the local TSDB storage path.
prometheus --storage.tsdb.retention.time=15dConfigure time-based local data retention.
prometheus --storage.tsdb.retention.size=20GBConfigure a size-based local data retention limit.
prometheus --storage.tsdb.wal-compressionEnable WAL compression.
Prometheus Query Performance
3 commandsprometheus --query.max-concurrency=20Configure the maximum number of concurrent queries.
prometheus --query.max-samples=50000000Limit the number of samples a query can load.
prometheus --query.timeout=2mConfigure the maximum execution time for queries.
Kubernetes Monitoring
6 commandskubectl get pods -n monitoringList monitoring namespace pods.
kubectl get servicemonitors -AList ServiceMonitor resources across namespaces.
kubectl get prometheusrules -AList PrometheusRule resources across namespaces.
kubectl logs -n monitoring <prometheus-pod>View Prometheus pod logs.
kubectl port-forward -n monitoring svc/prometheus 9090:9090Forward Prometheus web access to local port 9090.
kubectl describe pod -n monitoring <prometheus-pod>Inspect the Prometheus pod when troubleshooting Kubernetes deployment issues.
Production Troubleshooting
8 commandspromtool check config prometheus.ymlValidate configuration before restarting Prometheus.
promtool check rules rules.ymlValidate recording and alerting rules.
promtool check healthyCheck Prometheus health.
promtool check readyCheck Prometheus readiness.
curl http://localhost:9090/api/v1/targetsInspect target health and scrape status.
curl http://localhost:9090/api/v1/alertsInspect active alerts.
curl http://localhost:9090/api/v1/status/runtimeinfoInspect Prometheus runtime information.
curl http://localhost:9090/api/v1/status/tsdbInspect TSDB statistics and storage information.
CI/CD Prometheus Workflow
6 commandspromtool check config prometheus.ymlValidate Prometheus configuration in CI.
promtool check rules rules.ymlValidate alerting and recording rules in CI.
promtool test rules tests.ymlRun Prometheus rule tests in CI.
promtool check metrics < metrics.promValidate exported metrics during automated testing.
docker build -t prometheus-monitoring:latest .Build a custom Prometheus monitoring image.
docker run -d --name prometheus -p 9090:9090 prometheus-monitoring:latestRun the validated Prometheus image.
Recommended Prometheus Workflow
8 commandsprometheus --versionConfirm the installed Prometheus version.
promtool check config prometheus.ymlValidate the Prometheus configuration.
promtool check rules rules.ymlValidate recording and alerting rules.
promtool test rules tests.ymlRun rule unit tests.
prometheus --config.file=prometheus.ymlStart Prometheus using the validated configuration.
promtool check readyConfirm that Prometheus is ready.
curl http://localhost:9090/api/v1/targetsVerify target discovery and scrape status.
curl http://localhost:9090/api/v1/alertsVerify active alert state.
Common Prometheus Workflow
prometheus --versionpromtool check config prometheus.ymlpromtool check rules rules.ymlpromtool test rules tests.ymlprometheus --config.file=prometheus.ymlpromtool check readycurl http://localhost:9090/api/v1/targets