Path

Build a Prometheus query and set the alert condition.

Estimated time: 2 min

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.

  1. 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.

  2. Optionally, toggle Explain on. Grafana describes each part of your query in plain language.

  3. Confirm Builder is selected so you can build the query without writing PromQL.

You’ve prepared the query editor. Next, build the metric query.

  1. Select the quickpizza_server_http_requests_total metric. This counter records HTTP requests and includes a status label.

  2. In the Label filters row, open the Label drop-down and select status.

  3. Open the status operator menu and select =~. The operator needs to match a regex, not one status code.

  4. Type 5.. in Select value and press Enter. Do not choose 500 from the suggestions.

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.

  1. Open Operations, then select Range functions > Increase and set Range to 5m.

  2. Optionally, click + Operations again and select Aggregations / Sum.

  3. 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.

  1. In the Alert condition section, confirm Is above is selected and the value is 0.

  2. 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.