用于查询 Prometheus 及兼容 PromQL 的引擎(Thanos、Cortex、VictoriaMetrics、Grafana Mimir、Grafana Tempo...)的命令行工具——即时查询、范围查询
promql-cli (github.com/nalbury/promql-cli) is a Go CLI for querying, analyzing, and visualizing Prometheus metrics, plus PromQL fundamentals.
Read the relevant reference file(s) before executing tasks:
FileWhen to readreferences/installation.mdUser needs to install promql-cli or set up configuration (hosts, auth, token, password, multi-host)references/usage.mdUser wants to discover metrics/exporters/labels, run queries, or choose output formatsreferences/graphing.mdUser wants to visualize Prometheus data as an ASCII chart in the terminalreferences/debugging.mdUser is investigating a performance issue, latency, errors, or saturationreferences/promql-reference.mdUser needs help writing PromQL, understanding metric types, functions, or aggregations
For most tasks, read references/usage.md. For PromQL help, read references/promql-reference.md. When debugging, read both references/debugging.md and references/promql-reference.md.
Before running any query, verify that a host is configured:
bash
promql 'up' # succeeds if host is reachable; fails with connection error if not configured
# or
promql --host xxx 'up'
Recognize these errors as a configuration/auth problem and refer to references/installation.md:
ErrorCausedial tcp ... connection refusedNo host running at the configured addressdial tcp ... no such hostHostname not resolved — wrong host in configerror querying prometheus: ...401...Bearer token missing or invaliderror querying prometheus: ...403...Token valid but insufficient permissionsplease specify an authentication typeAuth flags partially set — use config file instead
If any of these appear, do not create config files on behalf of the user — config files may contain credentials (tokens, passwords) that must never pass through an LLM. Instead, guide the user to set it up themselves:
"Please create
~/.promql-cli.yamlmanually with your Prometheus host (and credentials if needed). Seereferences/installation.mdfor the exact format. Let me know once it's ready."
Only after the user confirms the config is in place should you proceed with queries.
bash
promql 'up' # instant query
promql 'rate(http_requests_total[5m])' --start 1h # range query (ASCII graph)
promql 'up' --output csv # CSV output
promql 'up' --output json # JSON output
promql metrics # list all metric names
promql labels <metric> # list labels for a metric
promql meta <metric> # show metric type and help
promql --config ~/.promql-cli-prod.yaml 'up' # target a specific host
rate() on counters, never raw values — raw counters only ever increase; the absolute value is meaningless. rate() gives the per-second change rate, which is what you actually care about.le in the by clause before histogram_quantile() — the function needs all le buckets to interpolate percentiles; dropping le early produces NaN or wrong results.--output graph for range queries — ASCII sparklines convey trend direction (rising, falling, spiking) in a compact format that LLMs parse well; raw timestamp tables require mental modeling.~/.promql-cli.yaml and ~/.promql_token, chmod 600 — passing tokens as CLI args exposes them in shell history and process listings.This skill is not exhaustive. Please refer to the official promql-cli documentation and examples for up-to-date information. Context7 can help as a discoverability platform.
If you encounter a bug or unexpected behavior in promql-cli itself, open an issue at https://github.com/nalbury/promql-cli/issues.