Linux command
promtool 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Check Prometheus config syntax
promtool check config [prometheus.yml]
Check alerting rules
promtool check rules [rules.yml]
Test alerting rules
promtool test rules [test.yml]
Query Prometheus metrics
promtool query instant [http://localhost:9090] "[up]"
Query range of metrics
promtool query range [http://localhost:9090] "[up]" --start [1h]
Validate metrics exposition
curl -s [http://localhost:9100/metrics] | promtool check metrics
Debug metrics parsing
promtool debug metrics [http://localhost:9090]
说明
promtool is the command-line utility for Prometheus, the popular monitoring and alerting system. It validates configuration, tests rules, and queries metrics. Configuration checking catches syntax errors and invalid settings before applying changes. This prevents Prometheus from failing to start due to configuration issues. Rule validation ensures alerting and recording rules are syntactically correct. Combined with unit testing (test rules), you can verify alert behavior before deployment. Test files specify sample data and expected alert states. Query commands execute PromQL queries against running Prometheus servers. Instant queries return current values; range queries return time series data. This enables scripting and automation around Prometheus data. The tsdb subcommand provides direct TSDB (time series database) manipulation: analyzing, benchmarking, and maintaining the storage layer.
参数
- check config _FILE_
- Validate Prometheus configuration file.
- check rules _FILES_
- Validate alerting/recording rules.
- check metrics
- Validate metrics format from stdin.
- test rules _FILES_
- Unit test alerting rules.
- query instant _SERVER_ _QUERY_
- Execute instant query.
- query range _SERVER_ _QUERY_
- Execute range query.
- query labels _SERVER_ _LABEL_
- Query label values.
- query series _SERVER_ _MATCH_
- Query time series.
- debug pprof _TYPE_
- Get debug profiling data.
- debug metrics _SERVER_
- Debug metrics endpoint.
- debug all _SERVER_
- Get all debug information.
- tsdb _subcommand_
- TSDB database operations (`analyze`, `dump`, `create-blocks-from`, `list`, `bench write`).
- check service-discovery _FILE_ _JOB_
- Validate service-discovery configuration.
- check web-config _FILE_
- Validate Prometheus web / TLS configuration.
- push metrics _URL_ _FILE_
- Push a file of Prometheus exposition to the given remote write endpoint.
- --start _TIME_
- Query start time.
- --end _TIME_
- Query end time.
- --step _DURATION_
- Query step interval.
FAQ
What is the promtool command used for?
promtool is the command-line utility for Prometheus, the popular monitoring and alerting system. It validates configuration, tests rules, and queries metrics. Configuration checking catches syntax errors and invalid settings before applying changes. This prevents Prometheus from failing to start due to configuration issues. Rule validation ensures alerting and recording rules are syntactically correct. Combined with unit testing (test rules), you can verify alert behavior before deployment. Test files specify sample data and expected alert states. Query commands execute PromQL queries against running Prometheus servers. Instant queries return current values; range queries return time series data. This enables scripting and automation around Prometheus data. The tsdb subcommand provides direct TSDB (time series database) manipulation: analyzing, benchmarking, and maintaining the storage layer.
How do I run a basic promtool example?
Run `promtool check config [prometheus.yml]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does check config _FILE_ do in promtool?
Validate Prometheus configuration file.