Prometheus query to count unique label values

30 views
Skip to first unread message

Shilpa Akhilesh

unread,
Nov 11, 2020, 11:41:53 AM11/11/20
to Prometheus Users
Hi, 
 am  looking for a way to count the unique label values and show each count for each customer name. Here are my metrics. I need to get the count as apple=1, orange=1. 

    customer_alerts(alertname="a", customername="apple")
     customer_alerts(alertname="b", customername="orange")
     customer_alerts(alertname="a",, customername="apple")

    i tried the below query and it is showing the total count as 2, but i would like to show the count map to each customer name. How can I do that?

    Example: apple=1, orange=1

    (count(count by (alertname)(customer_alerts[24h])))

    Please note I am using grafana to create the dashboard.

     Thanks,
      Shilpa

Matthias Rampke

unread,
Nov 11, 2020, 3:34:06 PM11/11/20
to Shilpa Akhilesh, Prometheus Users
You can directly use the count function for this:

count by(customer) (customer_alerts)

/MR

--
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/d91b04be-5089-4744-9f19-c5b46a621429n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages