Nov 28, 2026 / 01:00 PM UTC

    Grafana Alerting with Prometheus: An Error-Rate Walkthrough

    Build a Grafana error-rate alert with Prometheus queries, a traffic check and a clear response plan. Treat the thresholds here as teaching examples, then adjust them to your service’s real expectations.

    This walkthrough uses a Grafana-managed alert rule and a Prometheus data source. It is not a Prometheus YAML rule. The fictional checkout service exports http_requests_total with job, environment and three-digit status labels. Change those names to match your instrumentation.

    Define the problem before the threshold

    The question is: “Are enough checkout requests failing that someone should investigate?” For this example, the condition is a server-error percentage above 5%, with more than 10 requests per second, sustained through a five-minute pending period.

    Those numbers are not universal best practices. A payment system, a background task and a low-traffic internal service need different decisions. Choose thresholds and notification urgency from the impact on users.

    1. Query A: calculate the server-error percentage

    PromQL A: server errors as a percentage of requests.

    100 *
    sum(rate(http_requests_total{
      job="checkout", environment="production", status=~"5.."
    }[5m]))
    /
    sum(rate(http_requests_total{
      job="checkout", environment="production"
    }[5m]))

    The numerator selects HTTP 5xx responses. The denominator includes all responses in the same service and environment. Applying rate before sum handles individual counter resets before aggregation. The result is a percentage, so 2 means 2%, not 0.02%.

    The fixed [5m] window is deliberate. Alert evaluation runs on the server and must not depend on a viewer’s dashboard variables. Check that the window contains enough samples for your scrape interval. Source: Prometheus rate().

    2. Query B: check the traffic volume

    PromQL B: total checkout requests per second.

    sum(
      rate(http_requests_total{
        job="checkout", environment="production"
      }[5m])
    )

    A single failure in very little traffic can produce a large percentage. Query B gives the rule context. In this example, both queries use sum without grouping, so each returns one service-level series with matching labels. If you later group by service or region, keep the label sets compatible when combining expressions.

    Make sure the application exports the expected error series, including zero-valued counters where appropriate. An absent error series is not automatically a numeric zero. Review Prometheus instrumentation guidance when designing the metrics.

    3. Combine the two conditions in Grafana

    1. Create a Grafana-managed alert rule and select your Prometheus data source.
    2. Add queries A and B above. Use instant queries when the editor offers that mode, so each returns a current numeric result.
    3. Add a Math expression C that checks the error percentage and request rate together.
    4. Use C as the alert condition with a threshold above zero. If your version requires a separate Threshold expression, create one for C and select that as the condition.
    5. Preview the result before enabling notifications.

    Grafana Math expression C:

    ($A > 5) && ($B > 10)

    Grafana expressions reference query identifiers with a dollar sign. The logical condition is true only when both comparisons are true. If you use range queries instead of instant results, reduce each series to a number before applying the final threshold. Source: Grafana expression queries; queries and conditions.

    4. Choose evaluation and pending settings separately

    The evaluation interval controls how often Grafana checks the rule. The pending period controls how long a breached condition must persist before firing. For this teaching example, start with a one-minute evaluation interval and a five-minute pending period.

    The five-minute rate window and five-minute pending period do different jobs. One smooths the input calculation; the other waits for a sustained condition. Actual notification timing also depends on evaluation alignment, ingestion delays and notification policies. Source: Grafana alert-rule evaluation.

    5. Decide what No Data and Error should mean

    An empty result, a failed query and a healthy service are different situations. Review the rule’s No Data and Error handling explicitly. Do not mark missing telemetry as healthy simply to remove an inconvenient alert.

    A service that intentionally stops receiving traffic may need different handling from a service that must be available continuously. Use a separate availability or missing-telemetry check where appropriate. Document that decision so an on-call engineer can tell which signal failed. Source: Grafana No Data and Error states.

    6. Make the notification useful

    Give the rule a clear name, such as “Checkout sustained server errors.” Add the affected service, environment, owner and a short investigation link. Explain what the percentage counts and which dashboard to open first.

    Route the alert to the appropriate contact point and notification policy. Send a test to an agreed test destination, then verify both the firing and resolved messages. A rule evaluating correctly does not prove that a message reaches the right person.

    Test normal, failing and low-traffic cases

    • 100 requests/second with 2% server errors: the example condition is false.
    • 100 requests/second with 10% server errors: the numeric condition is true; the pending period must still complete before firing.
    • 1 request/second with 100% server errors: the example traffic gate is false. Decide whether a separate low-volume alert is needed.
    • No matching metric or a data-source failure: inspect the configured No Data or Error behavior.

    The request-rate and error-percentage expressions were checked with synthetic counters using promtool v3.7.3. In the normal fixture, they returned 100 requests/second and 2%. This validates the PromQL calculation, not Grafana’s notification delivery or your production environment. Run the complete rule through your own test environment before relying on it.

    Before enabling the rule

    • The metric names and labels match real exported data.
    • The threshold and traffic gate have an owner and a reason.
    • The evaluation interval, pending period and No Data behavior are explicit.
    • Queries return compatible labels and numeric results.
    • Both firing and resolved notifications have been tested.
    • The notification links to a useful investigation guide.

    For the dashboard behind the alert, use our Grafana dashboard best-practices guide. The goal is a signal that leads to a useful action, with enough context for the person receiving it.

    Login

    to interact with this post.

    Social.
    Snapshot.

    Instantly create a share-worthy social post for this post.

    Social Snapshot
    Explore similar content