prometheus
30 commands
30 shown
Query Prometheus via curl
Ad-hoc PromQL query from CLI
curl -sG 'http://prometheus:9090/api/v1/query' --data-urlencode 'query=up' | jq .
Instant query via promtool
Run an instant PromQL query using promtool
promtool query instant http://prometheus:9090 'up{job="kubelet"}'
Range query via curl
Query Prometheus for a time range via HTTP API
curl -sG 'http://prometheus:9090/api/v1/query_range' --data-urlencode 'query=rate(http_requests_total[5m])' --data-urlencode 'start=2024-01-01T00:00:00Z' --data-urlencode 'end=2024-01-01T01:00:00Z' --data-urlencode 'step=60s' | jq .
Check alert rules
Validate Prometheus alert/recording rule files for syntax
promtool check rules rules.yml
Silence active alert
Create a silence to mute alert notifications during maintenance
amtool silence add --alertmanager.url=http://alertmanager:9093 alertname=<name> --duration=2h --comment='Maintenance'
List silences
Show all active silences in Alertmanager
amtool silence query --alertmanager.url=http://alertmanager:9093
Expire silence
Immediately end an active silence
amtool silence expire <id> --alertmanager.url=http://alertmanager:9093
Check alertmanager config
Validate Alertmanager configuration file
amtool check-config alertmanager.yml
List active alerts
Show all firing alerts in Alertmanager
amtool alert query --alertmanager.url=http://alertmanager:9093
Reload Prometheus config
Hot-reload Prometheus configuration without restart
curl -X POST http://prometheus:9090/-/reload
Query instant vector
Run an instant PromQL query via HTTP API
curl -sG 'http://prometheus:9090/api/v1/query' --data-urlencode 'query=up' | jq '.data.result'
Range query for graph data
Fetch time-series data over a range for a rate metric
curl -sG 'http://prometheus:9090/api/v1/query_range' --data-urlencode 'query=rate(http_requests_total[5m])' --data-urlencode 'start=1h' --data-urlencode 'end=now' --data-urlencode 'step=60'
Top N series by value
PromQL: top 10 pods by CPU usage rate
topk(10, sum by (pod) (rate(container_cpu_usage_seconds_total[5m])))
Disk usage alert rule
PromQL expression: fire when root disk > 85% used
100 - (node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"} * 100) > 85
Reload Prometheus config
Hot reload Prometheus config and rules without restart
curl -X POST http://prometheus:9090/-/reload
List active alerts
Show only firing alerts with name and severity
curl -s http://prometheus:9090/api/v1/alerts | jq '.data.alerts[] | select(.state=="firing") | {name: .labels.alertname, severity: .labels.severity}'
List all metric names
Count total metric names and preview first 20
curl -s http://prometheus:9090/api/v1/label/__name__/values | jq '.data | length, .[0:20]'
Series cardinality per job
PromQL: count active time series grouped by job label
count by (job) ({__name__=~".+"})
Silence an alert
Create an Alertmanager silence for 2 hours
amtool silence add alertname=HighMemory --duration=2h --comment='Investigating'
Check TSDB status
View TSDB head stats: chunks and active series
curl -s http://prometheus:9090/api/v1/status/tsdb | jq '{head_chunks: .data.headStats.numChunks, series: .data.headStats.numSeries}'
95th percentile latency from histogram
p95 latency per job; note: always aggregate _bucket by le before histogram_quantile
histogram_quantile(0.95, sum by(le,job)(rate(http_request_duration_seconds_bucket[5m])))
Predict disk full window
alert when linear trend predicts disk full within 4h based on last 6h
predict_linear(node_filesystem_avail_bytes{mountpoint="/"}[6h], 4*3600) < 0
Detect dead target with absent
fires when no series match; catches a job that vanished from discovery entirely
absent(up{job="node"} == 1)
Rewrite label with label_replace
extract/derive a new label via regex capture; useful for joins and tidy dashboards
label_replace(node_uname_info, "host", "$1", "nodename", "(.+)")
Max of per-second rate over window
subquery: peak 5m rate sampled each minute over the last hour; spot bursts
max_over_time(rate(node_network_receive_bytes_total[5m])[1h:1m])
Aggregate keeping all labels but instance
without() keeps every label except instance; cleaner than listing many by() labels
sum without(instance) (rate(http_requests_total{code=~"5.."}[5m]))
Recording rule for expensive ratio
precompute SLO error ratio to keep dashboards and alerts fast
groups:
- name: slo
rules:
- record: job:request_errors:ratio5m
expr: sum by(job)(rate(http_requests_total{code=~"5.."}[5m])) / sum by(job)(rate(http_requests_total[5m]))
Validate rules and config with promtool
lint before reload; run in CI to catch broken expr/yaml before deploy
promtool check rules rules.yml && promtool check config prometheus.yml
Instant query from CLI
run PromQL without a browser; great for scripted top-N investigations
promtool query instant http://localhost:9090 'topk(5, sum by(pod)(rate(container_cpu_usage_seconds_total[5m])))'
Find cardinality offenders in TSDB
lists highest-cardinality metrics and label pairs; first stop for memory blowups
promtool tsdb analyze /prometheus --limit 20
no commands match