Get label values from Prometheus
List labels with Grafana or the HTTP API, expose them in query results, and attach metadata with correctly directed vector matching.
Prometheus metric queries return samples with labels attached. A label value such as method="GET" is metadata, not a string that replaces a sample's value. To list possible label values, use Grafana's variable editor or the label-values API. To show labels beside measurements, group or enrich the query result.
Filter a metric by label
http_requests_total{method="GET", status="200"}
This selects matching series and returns their labels and samples. Label matchers include =, !=, =~, and !~. A sample can be a float or a native histogram; “PromQL values are always numbers” is too broad, and the language also has limited string-literal support. Neither feature provides a general label-to-string projection operator.
Show one result for each label value
sum by (method) (http_requests_total)
A table can show each method alongside its summed counter value. That sum is a cumulative measurement across the currently selected series, not a request count for the dashboard period. For an estimated period total, aggregate increase() instead. If only the set of currently represented methods matters, group by (method) (http_requests_total) produces a value of one for each group.
Populate a Grafana dropdown
In a Prometheus query variable, select the Label values query type, metric http_requests_total, and label method. The classic variable syntax is:
label_values(http_requests_total, method)
This is Grafana variable syntax, not a PromQL function. Outside Grafana, request /api/v1/label/method/values, optionally using match[], start, and end to constrain the label lookup. Label metadata APIs are not a substitute for evaluating which series currently produce a result; returned metadata can outlive active samples.
Attach an information label to another measurement
up * on (job, instance) group_left (version) app_version_info
Assume app_version_info has value one and exactly one series per (job, instance). The expression keeps the left-hand measurement and copies version from the right. If your info metric is scraped under another job, use verified matching identity labels instead of blindly copying this key.
The original metric must still have a matching info series. A failed target may retain its last info sample briefly, then lose that series to staleness; this join is not guaranteed to display version metadata indefinitely for a down target.
Common questions
What distinguishes group_left and group_right? They declare which side may contain multiple matching series: left or right. The other side must be unique for the matching key. The label list copies selected labels from the unique side. This depends on series multiplicity, not on which metric has fewer labels.
Can I query just the text GET? Use the label API or a dashboard variable for enumeration. In a normal metric query, inspect or display method as a label attached to a result.
References
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan