Home › Guides › Grafana alerting tutorial

Grafana Alerting Tutorial: Email Alerts Step by Step

This is the companion page to my Grafana alerting video. We start from an empty Grafana 13 and end with a real email: [FIRING:1] High CPU usage, about a minute after a server's CPU goes over 80%. Then a RESOLVED email when it calms down. Every value below is the one I used on camera.

You will build a contact point, an alert rule and a real test. At the end you will set the timings that decide how often Grafana emails you, so alerts don't turn into spam.

How Grafana alerting works

Grafana alerting has three parts:

Alert rulequery + condition→ Notification policywhere it goes→ Contact pointemail, Slack, Teams, webhook

Every alert moves through these states:

StateWhat it means
NormalThe condition is false. Nothing to do.
PendingThe condition is true, but not for long enough yet.
FiringThe condition stayed true for the whole pending period. Notifications go out.
ResolvedThings are fine again. You get a second email saying so.

The lab

My setup: Grafana 13.3 (OSS) in Docker, Prometheus 3.7, and a Linux server called web-01 (Ubuntu 24.04) running node_exporter. Email goes to Mailpit, a test inbox, so you can see every message without touching a real mailbox. Any data source that supports alerting works the same way.

If you want the same lab, here is the compose.yaml:

services:
  grafana:
    image: grafana/grafana:13.3.2
    ports: ["3000:3000"]
    environment:
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: admin
      GF_SMTP_ENABLED: "true"
      GF_SMTP_HOST: mailpit:1025
      GF_SMTP_FROM_ADDRESS: [email protected]
      GF_SMTP_FROM_NAME: Grafana
      GF_SERVER_ROOT_URL: http://localhost:3000
    volumes:
      - ./provisioning:/etc/grafana/provisioning
  prometheus:
    image: prom/prometheus:v3.7.3
    command: ["--config.file=/etc/prometheus/prometheus.yml", "--web.enable-lifecycle"]
    ports: ["9090:9090"]
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
  mailpit:
    image: axllent/mailpit:v1.34
    ports: ["8025:8025"]

prometheus.yml scrapes node_exporter on the server. Replace SERVER with your server's IP address. The instance: web-01 label gives the server a readable name in alerts.

global:
  scrape_interval: 15s
scrape_configs:
  - job_name: node
    static_configs:
      - targets: ["SERVER:9100"]
        labels: { instance: web-01 }

And provisioning/datasources/prometheus.yaml adds Prometheus to Grafana as the default data source:

apiVersion: 1
datasources:
  - name: Prometheus
    uid: prometheus
    type: prometheus
    url: http://prometheus:9090
    isDefault: true
    jsonData: { timeInterval: 15s }

On the server itself, install node_exporter and stress-ng (we use it later to load the CPU):

sudo apt install -y prometheus-node-exporter stress-ng

Start the stack with docker compose up -d. Grafana is on http://localhost:3000 and the Mailpit inbox is on http://localhost:8025. In Grafana, open Explore and you should see web-01's CPU.

Lab password. admin / admin is fine on a laptop. Change it for anything that faces a network you don't control.

Step 1: tell Grafana about your SMTP server

Grafana can only send email when it knows an SMTP server. Without it, an email contact point saves fine and then never delivers. On a normal install, that is the [smtp] section in grafana.ini:

[smtp]
enabled = true
host = smtp.example.com:587
user = ...
password = ...
from_address = [email protected]

In Docker, use the same settings as environment variables. Every grafana.ini option becomes GF_<SECTION>_<KEY>:

GF_SMTP_ENABLED=true
GF_SMTP_HOST=smtp.example.com:587
GF_SMTP_USER=...
GF_SMTP_PASSWORD=...
[email protected]

In my lab, Grafana sends to Mailpit (axllent/mailpit) instead, with GF_SMTP_HOST=mailpit:1025. Mailpit accepts everything on port 1025 and shows it in its web inbox. It needs no user or password. Restart Grafana after you change SMTP settings.

Tip: set the root URL. Grafana's emails contain links to open the rule or silence it. They are built from GF_SERVER_ROOT_URL (root_url in grafana.ini). Set it to the address your team actually uses, or the links point to the wrong host.

Step 2: create an email contact point

  1. In Grafana, open Alerting and click Manage contact points.
  2. Click New contact point.
  3. Name: Ops email.
  4. Integration: Email.
  5. Addresses: [email protected]. You can add several, separated by commas.
  6. Click Save contact point.

Step 3: test it before you rely on it

Edit the contact point and click Test, then Send test notification. A message with the subject [FIRING:1] TestAlert should land in the inbox.

If it arrives, email works. Anything that goes wrong later is in the rule, not in the delivery. If it doesn't, fix SMTP first (see If no email arrives).

Step 4: create the alert rule

Open Alerting → Alert rules and click New alert rule. The form has six steps.

1. Name

High CPU usage.

2. Query and alert condition

Pick the Prometheus data source, switch the query editor from Builder to Code and type:

100 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[1m])) * 100

Click Run queries to see the current value. Below it is the alert condition: When query is above. Type 80. Click Preview alert rule condition and you see every server with its state. Normal, for now.

Turn on Advanced options to see what Grafana builds underneath:

3. Folder and labels

The folder also decides who can see and edit the rule. Click New folder and create Linux.

Labels are optional, but they are what notification policies use to route alerts. Click Add labels and add severity = critical. We use it in step 8.

4. Evaluation behavior

Rules are checked in groups. Click New evaluation group, name it linux, interval 1m. Grafana checks the rule every minute.

SettingValueWhy
Pending period1m CPU has to stay above 80 for a full minute before the alert fires. A short spike won't wake anyone up.
Keep firing foroptional The opposite: it keeps the alert firing for a while after CPU drops. A value that flaps around 80 doesn't send you ten emails.
Alert state if no dataAlerting Under Configure no data and error handling. If the server stops sending data at all, a dead server alerts you too.

5. Configure notifications

Pick the Ops email contact point.

6. Configure the notification message

The summary can use templates. This is the one from the video:

CPU on {{ $labels.instance }} is {{ printf "%.0f" $values.A.Value }}%

$labels.instance is the server's name. $values.A is the value of query A, the CPU usage. printf "%.0f" rounds it to a whole number.

The description and a runbook URL are optional. The person who gets this email at three in the morning will thank you for them.

Tip: example values. These were not typed in the video. Adapt them.

Description: CPU on {{ $labels.instance }} has been above 80% for over a minute. Check the top processes with top or htop.

Runbook URL: https://wiki.example.com/runbooks/high-cpu

Click Save.

Step 5: trigger it for real

On the server, load every CPU core for ten minutes:

stress-ng --cpu 0 --timeout 600s

--cpu 0 starts one worker per CPU core. Ctrl+C stops it early.

Step 6: pending, firing, email, resolved

  1. Pending. Back in Grafana, in the alert rule list. After the next evaluation the rule is Pending: CPU is high, and the one-minute clock is running.
  2. Firing. One minute later, it is Firing.
  3. Active notifications shows every firing alert right now, grouped the way they will be sent, with its labels: severity=critical and instance=web-01.
  4. The email. The subject says [FIRING:1] and the rule name, High CPU usage. Inside is the summary with web-01 and the value, the labels, and links to open the rule or to silence it.
  5. Resolved. Stop the load with Ctrl+C. On the next evaluation the rule goes back to Normal, and Grafana sends a [RESOLVED] email, so you know it is over.

Step 7: notification policies and timings

This is the setting that decides how often you get emails. Open Alerting → Notification configuration, then the Notification policies tab. The Default policy handles every alert, and its three timings are the defaults:

TimingDefaultShown asWhat it does
Group wait30sWait 30s to group Grafana waits a moment, so alerts that fire together arrive in one email.
Group interval5mWait 5m before sending updates New alerts in the same group wait at least that long.
Repeat interval4hRepeated every 4h While an alert keeps firing, you get it again only every four hours.

Don't set the repeat interval too low. An email every few minutes for the same problem teaches your team to ignore Grafana.

Tip: give the default policy a contact point. In my lab the default policy sends to Ops email. Check yours with Edit on the default policy, so alerts that reach the tree always go somewhere.

Step 8: route critical alerts to on-call

This is where labels pay off.

  1. Create a second email contact point, for example On-call team with [email protected], the same way as in step 2.
  2. On the default policy, click Add route to add a child policy.
  3. Matcher: severity = critical.
  4. Contact point: On-call team. Save it with Add route.

Now critical alerts go to the on-call team. Everything else stays on the default policy.

Rules that pick a contact point directly skip this tree. Our High CPU rule chose Ops email in step 5 of the rule form, so it still goes to Ops email, whatever its labels say. The child policy only applies to rules that use notification policies.

Tip: to route the High CPU rule through the tree, edit the rule and in step 5 choose Use notification policy instead of a contact point.

Step 9: silence alerts for maintenance

Planned maintenance? Use a silence instead of disabling the rule.

  1. Open Alerting → Silences and create a new silence.
  2. Keep the default two-hour window.
  3. Add a matcher: instance = web-01.
  4. Add a comment saying why, for example Kernel update on web-01.
  5. Click Save silence.

The rule still runs, but no emails go out for web-01 until the silence ends. Every firing email also has a link to silence that alert.

If no email arrives

Start with the Test button on the contact point. If the test fails too, it is the SMTP settings, and Grafana's log shows the exact error.

What you seeWhere to look
The test notification fails or never arrives SMTP: host, port, user, password, or enabled = true missing. Read Grafana's log. In Docker: docker compose logs grafana (tip).
The test arrives, the alert email doesn't The rule. Is it Firing, or still Pending? Does it use the right contact point, or a policy that sends somewhere else?
The rule never leaves Normal Run the query and check the value really goes above 80. Check that the condition is set on expression C.
Too many emails for one problem Repeat interval on the policy, and Keep firing for on the rule.

Watch the video

The whole walkthrough on Grafana 13, from an empty Grafana to the FIRING and RESOLVED emails, notification timings and silences:

Related

Want alerting that pages the right person?

One rule and one inbox is a start. A real setup needs rules that catch the problems that matter, routing by team and severity, and timings nobody learns to ignore. I'm a Grafana Champion, and I set up monitoring and observability through KorFlux. Tell me what you run and I'll tell you how I'd set up the alerting.