Metrics and alerts for logs ΒΆ

This guide shows how to use Loki metrics for monitoring log patterns and creating alerts.

Monitoring error rates using log metrics ΒΆ

To monitor error rates using the loki:service:loglevel:count1m metric:

  1. Access Grafana and create a new panel

  2. Use this PromQL query to calculate error percentage:

    promql

    Important: The loki:service:loglevel:count1m metric is already pre-aggregated for 1-minute intervals. Do not use rate() or increase() functions with it.

  3. Configure visualization as a graph or gauge

Logs per application for a team in Grafana

Common log monitoring queries ΒΆ

Monitor high error volume:

promql

Show trends over time:

promql

Compare error rates across clusters:

promql

Creating Prometheus alerts for logs ΒΆ

To create an alert for high error rates in your logs, add a PrometheusRule to your application:

yaml