将 Grafana 配置为仅在查询匹配超过 4 分钟时才发出警报

Configure Grafana to alert only if the query matches for more than 4 minutes

我有一个像这样的 Grafana 指标:

SELECT
  UNIX_TIMESTAMP(time) as time_sec,
  sum(average_hashrate_eth) as value,
  'total hashrate' as metric
FROM status_rig
group by time;

有这样的警报:

WHEN last()query(A, 5m, now) IS BELOW 800

如何让它仅在该查询低于 800 且仅超过 4 分钟时发出警报?

谢谢。

假设指标的 time-frequency 是 60 秒,时间是 DATETIME 类型。

试试这个:

  SELECT
   UNIX_TIMESTAMP(time) as time_sec,
   SUM(case when average_hashrate_eth < 800 THEN 1 ELSE 0 END) as counter,
   SUM(average_hashrate_eth) as value,
   'total hashrate' as metric
  FROM status_rig
  WHERE time between (now()-interval 5 minute) and now()
  HAVING counter>=5;

如果值保持低于 800

,这将为您提供从当前时间算起最后五分钟的 average_hashrate_eth 总和

您只需更新警报配置即可使用:

当 max() of query(A, 4m, now) 低于 800