PromQL query to find the duration of each firing alert

给你一囗甜甜゛ 提交于 2020-12-15 06:09:34

问题


I am creating a Grafana dashboard to see the total alert count for each firing alert and the duration ( means it should capture how long alerts have been firing state).

PromQL query used to capture the total alert count is as follows,

count by (alertname,customerName) (changes(customer_ALERTS[24h]))

Idea is to add two more column in the Grafana table panel having the alert count and the duration

Now i need to get the query to capture the duration for each alerts. Can somebody please share some thoughts?


回答1:


If you know the evaluation interval for alerts, then the following PromQL query could be used for calculating the duration in seconds for alerts in firing state over the last 24 hours:

count_over_time(customer_ALERTS[24h]) * <evaluation_interval_in_seconds>

The query assumes that customer_ALERTS contains non-empty values when alert is firing and has no any values when the alert isn't firing. If the customer_ALERTS contains zero values when the alert isn't firing and one values when the alert is firing, then the following query should be used instead for determining the duration of alerts in firing state in seconds:

avg_over_time(customer_ALERTS[24h]) * 24 * 3600

If customer_ALERTS contains other values for firing / not firing state, then PromQL subqueries could be used for counting samples in firing state. Take a look also at MetricsQL functions such as lifetime(m[d]), share_gt_over_time(m[d], gt) or count_gt_over_time(m[d], gt).



来源:https://stackoverflow.com/questions/64510338/promql-query-to-find-the-duration-of-each-firing-alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!