promtool - Tooling for the Prometheus monitoring system
promtool check config|rules|metrics ...
promtool test rules <test.yml>...
promtool query instant|range <server> <expr>
Options you will use
check config <file>...- Validate prometheus.yml and every rule file it references. Exit 1 on error. Warns about missing file_sd files.
check rules <file>...- Validate rule files: YAML, field names, every expr parses, recording rule names are valid metric names.
check metrics- Lint exposition text read from stdin: counters without _total, missing HELP, non-base units. Exit 3 on problems.
test rules <file>...- Unit-test rules against synthetic series (input_series, alert_rule_test, promql_expr_test). Only FIRING alerts are compared; labels and annotations must match exactly.
query instant <server> <expr>- Run an instant query. --time=<rfc3339|unix> to evaluate in the past.
query range <server> <expr>- Run a range query. --start, --end, --step.
query labels <server> <name>- List values of a label.
Examples
$ promtool check config /etc/prometheus/prometheus.ymlthe first thing to run after any edit, before reloading
$ promtool query instant http://localhost:9090 'sum by (job) (up)'query from the shell
$ promtool test rules slo_test.ymlprove an alert fires, without waiting for an outage
$ curl -s localhost:9100/metrics | promtool check metricslint what an exporter exposes
Gotchas
- Series notation in tests: "0+10x5" is 0 10 20 30 40 50, "_" is a missing sample, "stale" a staleness marker, "1x3" is 1 1 1 1.
- Test time starts at 0; eval_time is relative to it.
Taught in
Try promtool in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.