Discover and Query a Metric
A 5-step recipe with Prometheus. We can help you get access.
Recipe · 5 steps
Discover and Query a Metric
with Prometheus
Discover a metric, inspect its metadata and labels, then evaluate it.
- List every metric name in the TSDB by reading the values of the special __name__ label. This is how query UIs build metric autocomplete.
- Read the metric type (counter, gauge, histogram, summary) and help string scraped from the targets exposing this metric. The type decides whether rate(), increase(), or a bare selector is the correct query.
- List the label names actually present on this metric, restricted by the series selector so the result is scoped to the metric under investigation.
- Resolve the selector to the concrete label sets it matches. An empty result here means the selector matches nothing and any query built on it will return no data.
- Evaluate the PromQL expression at a single point in time and return the resulting vector.
What you'll need to have ready
- metricName: The metric name to inspect (e.g. http_requests_total).
- seriesSelector: A series selector used to resolve concrete series (e.g. http_requests_total{job="api"}).
- query: The PromQL expression to evaluate (e.g. rate(http_requests_total[5m])).
- evaluationTime: Optional evaluation timestamp as a Unix timestamp or RFC3339 string. Defaults to current server time when omitted.
For your developer
Arazzo workflow prometheus:discover-and-query-metric, 5 operations: getLabelValues → getMetricMetadata → getLabelNames → querySeries → queryInstant. Specs on APIs.io.