Uptime SLA in percentage for metric

26 views
Skip to first unread message

Raúl Lopez

unread,
Jun 24, 2024, 8:36:06 AM (13 days ago) Jun 24
to Prometheus Users
Hello,
I need to know in percentage the time my service has been available in the last month, last week, etc (dynamic value).
The metric in question can return the values; 0, 1 and 2.

0 -> OK
1 -> Warning
2 -> KO

The idea I have is to disregard value 1 and only treat my service as KO when it has returned value 2. I am trying to build in a Grafana visualisation for the SLA in percentage that my service has been available according to the time range that the user specifies in the dashboard.

I've been doing some research and it seems that for this kind of cases it is not as simple as for example for those endpoints where Blackbox is used for example (as I cannot use probe_success).

Could someone help me?
Thank you in advance.

Regards.

Ben Kochie

unread,
Jun 24, 2024, 8:38:03 AM (13 days ago) Jun 24
to Raúl Lopez, Prometheus Users
IMO you need to fix your service metrics. Prometheus best practice is to follow the pattern of probe_success. Boolean values are far easier to handle.

--
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/a26d17b9-b507-413a-89d7-f95ca49ef725n%40googlegroups.com.

Brian Candler

unread,
Jun 24, 2024, 8:50:18 AM (13 days ago) Jun 24
to Prometheus Users
A PromQL query like  "mymetric == bool 2" will return 1 when the value is 2, and 0 otherwise.

You'll likely need to run this inside a subquery if you're doing time range aggregation over it. But if Grafana is doing the summarization that might not be necessary.

Ben Kochie

unread,
Jun 24, 2024, 10:55:31 AM (13 days ago) Jun 24
to Brian Candler, Prometheus Users
Hopefully https://github.com/prometheus/prometheus/pull/14095 is accepted. It would make these kinds of queries much easier and faster. No subquery required.

Reply all
Reply to author
Forward
0 new messages