How do I write a Prometheus query that returns the value of a label?

kmoe :

I'm making a Grafana dashboard and want a panel that reports the latest version of our app. The version is reported as a label in the app_version (say) metric like so:

app_version_updated{instance="eu99",version="1.5.0-abcdefg"}

I've tried a number of Prometheus queries to extract the version label as a string from the latest member of this time series, to no effect.

For example, the query

count(app_version_updated) by (version)

returns a {version="1.5.0-abcdefg"} element with a value of 1. When put in a Grafana dashboard in a single value panel, this doesn't display the version string but instead the count value (1).

How can I construct a Prometheus query that returns the version string?

Marcus Rickert :

My answer tries to elaborate on Carl's answer. I assume that the GUI layout may have changed a little since 2016, so it took me while to find the "name" option.

Assuming you have a metric as follows:

# HELP db2_prometheus_adapter_info Information on the state of the DB2-Prometheus-Adapter
# TYPE db2_prometheus_adapter_info gauge
db2_prometheus_adapter_info{app_state="UP") 1.0

and you would like to show the value of the label app_state.

Follow these steps:

  • Create a "SingleStat" visualization.
  • Go to the "Queries" tab:
    • Enter the name (here db2_prometheus_adapter_info) of the metric.
    • Enter the label name as the legend using the {{[LABEL]}} notation (here {{app_state}}).
    • Activate the "instant" option.

Settings in Queries Tab

  • Go to the "Visualization" tab:
    • Choose the value "Name" under "Value - Stat".

Setting in Visualization Tab

Note on the "Instant" setting: This setting switches from a range query to a simplified query only returning the most recent value of the metric (also see What does the "instant" checkbox in grafana graphs based on prometheus do?). If not activated, the panel will show an error as soon as there is more than one distinct value for the label in the history of the metric. For a "normal" metric you would remedy this by choosing "current" in the "Value - Stat" option. But doing so here prevents your label value to be shown.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Prometheus: how to get label_value() in query

How can I scrape label value using prometheus query from metrics and set alerts

How do I write an "or" logical operator on Prometheus or Grafana

How do I use label in this part of this query?

How do I write a function that returns itself?

How to check if a query returns a null value and add it to a label text?

How do I query an API latency Error Budget from Prometheus

How do I place a slider value in label?

How do I write VBA code such that my formula returns the value in the selected cell?

How do I write a Django ORM query that searches for a value that is close but doesn't exceed a certain other value?

How do I write this Postgres Query?

How do I write this update query?

How do I write this linq inner query?

How do I write this JPQL query?

How can I write a query to do this?

How do I write a media query for Gmail?

How do i write a group by query in PostgreSQL

How do I write this PL/SQL query?

How do you write a mysql query that returns the latest respective records?

How do I write an SQL query that gives me the amount of times a value is repeated in a table?

How can I bind label content with value from query?

Can I remove or rename to a non unique value the instance label in prometheus?

How can I write a function template that returns either a reference or a value?

How do I write a function that returns another function?

How do I write a Spring Controller method that returns an image?

How do I write an iterator that returns references to itself?

How do I write an IF statement in excel that returns a mix of formulas and text?

How do I write a function that returns both a dataframe and a ggplot?

How can I group labels in a Prometheus query?