[prometheus-users] Adding a label based on metric value

74 views
Skip to first unread message

Kalle Narinen

unread,
Apr 2, 2020, 9:16:14 AM4/2/20
to Prometheus Users
HI, we would like to add a status label based on metric value.
Is there a way to do this?

-Kalle

Brian Candler

unread,
Apr 2, 2020, 11:17:01 AM4/2/20
to Prometheus Users
What is it you're trying to achieve?

By changing the set of labels on a metric, you've changed it to a completely different timeseries.  This is probably not what you want.  (The timeseries is *defined* by the bag of labels on it).

You can add labels and annotations to alerts: this is standard functionality of alerting rules.

Kalle Narinen

unread,
Apr 2, 2020, 11:37:35 AM4/2/20
to Brian Candler, Prometheus Users
hi, metric is having values that indicates status and we would like to convert them somehow to be more human readable e.g. to be consumed by statusMap Grafana dashboard.
I don't mind them being then different metric when adding e.g a status label.

-Kalle

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/59c178e5-03bb-4f65-88ab-791183ff5322%40googlegroups.com.

Brian Candler

unread,
Apr 2, 2020, 11:45:11 AM4/2/20
to Prometheus Users
Grafana can do that for you.  This is for metric "apcups_status_numeric" that returns 0, 1, 2, 3 etc:

grafana-panel.png


Corresponding panel configuration - under "Visualization"

grafana-value-mappings.png


Kalle Narinen

unread,
Apr 2, 2020, 11:57:50 AM4/2/20
to Brian Candler, Prometheus Users
hi, yes, I found that this is possible for single stat but I forgot to mention that I need them in the graph.

-Kalle

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.

Brian Candler

unread,
Apr 2, 2020, 12:28:12 PM4/2/20
to Prometheus Users
What if you configure a single panel with multiple queries, each with their own legend?

grafana-multi-query.png



Otherwise, if you have 10 different status values I think you should be able to use recording rules to make 10 different timeseries with different labels, which is what you originally asked for.

Conventionally, when representing data this way in prometheus, you'd make each series have value 0 or 1 at each instant (so every timeseries is contiguous, and you don't have issues around staleness).  I haven't tested it, but try something like:


groups:
  - name: foo
    rules:
      - record: foo:annotated
        expr: foo == bool 0
        labels:
          status: xxx

      - record: foo:annotated
        expr: foo == bool 1
        labels:
          status: yyy

      - record: foo:annotated
        expr: foo == bool 2
        labels:
          status: zzz
      ... etc

If you're going to do this, it may be better to modify the exporter if you can, since it will know better all the possible status values and labels.

Kalle Narinen

unread,
Apr 2, 2020, 1:55:41 PM4/2/20
to Brian Candler, Prometheus Users
Ok, Thanks. I will try them out

Sent from my iPhone

On 2. Apr 2020, at 19.28, Brian Candler <b.ca...@pobox.com> wrote:


What if you configure a single panel with multiple queries, each with their own legend?

<grafana-multi-query.png>



--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages