How to calculate error percentage in the alert

Query A

SELECT
  toString(statusCode) AS HTTP_Status_Code,
  timestamp_min AS time,
  cnt_all AS http
FROM akamai.summary_vod
WHERE
  timestamp_min >= now() - INTERVAL 6 MINUTE
  AND timestamp_min <  now() - INTERVAL 3 MINUTE
  AND workflow = 'ssai'
  AND secondaryWorkflow='segments'
  AND streamId = '81733'
  AND HTTP_Status_Code = '504'
  AND failover = 'TD-failover'
GROUP BY
  HTTP_Status_Code,
  time
ORDER BY
  time

Query B

SELECT
  toString(statusCode) AS HTTP_Status_Code,
  timestamp_min AS time,
  cnt_all AS http
FROM akamai.summary_vod
WHERE
  timestamp_min >= now() - INTERVAL 6 MINUTE
  AND timestamp_min <  now() - INTERVAL 3 MINUTE
  AND workflow = 'ssai'
  AND secondaryWorkflow='segments'
  AND streamId = '81733'
  AND HTTP_Status_Code = '200'
GROUP BY
  HTTP_Status_Code,
  time
ORDER BY
  time

I want the query to print 502, 503, 504 in the same query then I’ll use expression(Math) to calculate percentage error (5xx*2)/200. Can I do it individually for 502, 503 and 504

  • What Grafana version and what operating system are you using?

  • What are you trying to achieve?

  • How are you trying to achieve it?

  • What happened?

  • What did you expect to happen?

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • Did you follow any online instructions? If so, what is the URL?

Since you have a SQL engine, you can just do the math in SQL. For example, you can remove the status code, and filter on HTTP_Status_Code LIKE ‘50%’, that would give you all errors in query A.

here the challenge I’m facing is, I want math to be calculated on 502/200, 503/200 etc

And you want alert on each code individually or on the sum of them ?