How to show latest value of a label for combination of two other labels

  • What Grafana version and what operating system are you using?
    I’m using the latest version of Grafana on MacOS 13.5.2 (22G91) (Ventura).

  • What are you trying to achieve?
    I have prometheus Gauge metrics that I’m sending to Grafana. Each metric has 4 labels: id, name, power, last_seen. Last seen is an enum of different buckets: “< 5m”, “< 1h”, “< 1 d”, “< 3d”. I’m currently able to display a table of my results using “Instant” so I get the latest metric for each combination of “name” and “id” together. However I also want to display the “last_seen” value for the latest (because I’m using Instant) metric. The issue is, and I think this might be a problem with my data model, I get multiple rows for each combination of “name” and “id” for every different “last_seen” value.

  • How are you trying to achieve it?
    I’m using the following PromQL query in Grafana: max by(id, name, last_seen) (my_metric)

  • What happened?
    I get multiple rows for each unique combination of id and name. I understand this is how time series databases work, but I don’t know how else to basically get the “latest” value for last_seen and join it to the unique combination of “id” and “name”. Any ideas?

  • What did you expect to happen?
    I want there to be one row for each combination of “id” and “name” with the latest “last_seen” value.