Build your query and set the condition
You’ll build a query that watches QuickPizza for server errors, then confirm when the alert fires.
Use Builder mode instead of writing PromQL. Keep the condition as Is above 0.
On the New alert rule page, choose the data source that holds the metric you want to alert on.
grafanacloud-play-prom is filled in for you.
Optionally, toggle Explain on. Grafana describes each part of your query in plain language.
Confirm Builder is selected so you can build the query without writing PromQL.
You’ve prepared the query editor. Next, build the metric query.
In the Metric drop-down, paste
quickpizza_server_http_requests_total, then select it from the list.This counter tracks HTTP requests for QuickPizza services and includes a response status label.
In the Label filters row, open the Label drop-down and select status.
Open the operator drop-down and change = to =~ so one filter can match every 5xx status code.
In the Select value box, enter
5.., then press Enter.That regex matches any three-digit status that starts with 5.
The metric is a counter that only increases. Add a range function to count new errors over the last 5 minutes. Optionally sum across services so the alert uses one total.
Click + Operations. In the Operations drop-down, select Range functions / Increase, then set the Range to 5m.
Optionally, click + Operations again and select Aggregations / Sum.
Click Run queries.
Check that your query matches sum(increase(quickpizza_server_http_requests_total{status=~"5.."}[5m])) and that Run queries succeeds.
Next, confirm the alert condition.
In the Alert condition section, confirm Is above is selected and the value is 0.
Click Preview alert rule condition to evaluate the condition against your query.
The result may show Normal or Firing, depending on whether the query is above 0 right now.
Your query and alert condition are set. Next, you create a folder and add labels.