Reputation: 415
I have a Grafana metrics like this:
SELECT
UNIX_TIMESTAMP(time) as time_sec,
sum(average_hashrate_eth) as value,
'total hashrate' as metric
FROM status_rig
group by time;
With an alert like this:
WHEN last()
of query(A, 5m, now) IS BELOW 800
How do I make this to only alert when this query is below 800 for more than 4 minutes only?
Thanks.
Upvotes: 0
Views: 1273
Reputation: 2176
You can just update your alert config to use:
WHEN max() of query(A, 4m, now) IS BELOW 800
Upvotes: 1
Reputation: 4751
Assuming time-frequency of metric is 60 seconds and time is of DATETIME
Type.
Try this:
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;
This will give you the sum of average_hashrate_eth
of last five minute from current time if value remains below 800
Upvotes: 0