How to Configure Email Alerts in Grafana

In this article, we will learn how to configure email alerts in Grafana, a powerful open-source platform used for monitoring and observability. Email alerts are an essential feature of Grafana’s alerting system, providing immediate notification of critical events or anomalies detected in monitored metrics. By setting up email alerts, users can stay informed about important changes in their systems and take proactive measures to address any issues.

Prerequisites

  • AWS Account with Ubuntu 22.04 LTS EC2 Instance.
  • Basic knowledge of AWS services, Prometheus and Grafana.

Step #1:Install Prometheus on Ubuntu

Download the latest version of Prometheus from the GitHub repository using the following command.

wget https://github.com/prometheus/prometheus/releases/download/v2.30.0/prometheus-2.30.0.linux-amd64.tar.gz
How to Configure Email Alerts in Grafana 1

extract the downloaded archives.

tar xvfz prometheus-2.30.0.linux-amd64.tar.gz

The command extracts the contents of the file prometheus-2.30.0.linux-amd64.tar.gz

How to Configure Email Alerts in Grafana 2

now navigate to the extracted directory using following command.

cd prometheus-2.30.0.linux-amd64
How to Configure Email Alerts in Grafana 3

navigate to the /etc/systemd/system, this is where typically systemd unit files are located, which are used for managing services on Linux systems.

cd /etc/systemd/system
How to Configure Email Alerts in Grafana 4

now lets create a service for Prometheus named prometheus.service.

sudo vi prometheus.service
How to Monitor Redis with Prometheus and Grafana 9

add the following content into it.

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/home/ubuntu/prometheus-2.30.0.linux-amd64/prometheus --config.file=/home/ubuntu/prometheus-2.30.0.linux-amd64/prometheus.yml
Restart=always

[Install]
WantedBy=default.target
How to Monitor Redis with Prometheus and Grafana 10

Now our prometheus.service is created.

After this

Reload the daemon service, enable, and start the Prometheus service:

sudo systemctl daemon-reload
sudo systemctl enable prometheus.service
sudo systemctl start prometheus.service
How to Configure Email Alerts in Grafana 5

now Verify the status of the Prometheus service using following command:

sudo systemctl status prometheus.service
How to Configure Email Alerts in Grafana 6

If your service is running properly then you can run prometheus by running

Public IP:9090 which is default port for prometheus in url.

How to Monitor Redis with Prometheus and Grafana 13

Step #2:Install Grafana on Ubuntu

First import the GPG key used by the Grafana package.

wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
How to Configure Email Alerts in Grafana 7

then add the Grafana repository to the APT sources.

sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
How to Configure Email Alerts in Grafana 8

After adding the repository update the package lists

sudo apt update
How to Configure Email Alerts in Grafana 9

then install the grafana.

sudo apt install grafana
How to Configure Email Alerts in Grafana 10

Start and enable the Grafana service.

sudo systemctl start grafana-server
sudo systemctl enable grafana-server
How to Configure Email Alerts in Grafana 11

and if everything works fine and your service is running properly then run grafana by running your Public IP:3000 which is default port of grafana in searchbar.

you will see the login page of grafana (UI) user interface

Grafana uses admin as a default username and password.

How to Monitor Redis with Prometheus and Grafana 19

it will ask for changing the password you can change it or skip it.

How to Monitor Redis with Prometheus and Grafana 20

then you will see the welcome page of grafana.

How to Monitor Redis with Prometheus and Grafana 21

Step #3:Configure SMTP Settings

To enable email alerts, Grafana requires SMTP (Simple Mail Transfer Protocol) configuration. SMTP settings specify the email server through which Grafana will send alert notifications.

So first we need to retrieve the password to give in smtp configuration.

Go to your google account.. Then go to security.

How to Configure Email Alerts in Grafana 12

In the How you sign in to Google, select 2-step verification.

How to Configure Email Alerts in Grafana 13

Enter your google account password to verify it’s you.

How to Configure Email Alerts in Grafana 14

Scroll down and select the App passwords

How to Configure Email Alerts in Grafana 15

Now Enter the app name for which you wanted to get the app password like Grafana.

And click on Create to create it

How to Configure Email Alerts in Grafana 16

the password will be generated. Note it down cause will be using it in SMTP configuration.

How to Configure Email Alerts in Grafana 17

now open /etc/grafana/grafana.ini file.

sudo nano /etc/grafana/grafana.ini
How to Configure Email Alerts in Grafana 18

edit it as shown below.

[smtp]
enabled = true
host = smtp.gmail.com:587   
user = [email protected]    
password = your app password 
skip_verify = true        
from_address = [email protected]
from_name = Grafana
How to Configure Email Alerts in Grafana 19

save it and restart the grafana server.

sudo systemctl restart grafana-server
How to Configure Email Alerts in Grafana 20

Step #4:Add Prometheus as a data source in Grafana

Now go to the Grafana welcome page. Go to the Home in the left top corner.

Then go to the Connections and select the Data sources option.

How to Monitor Redis with Prometheus and Grafana 38

Click on Add Data Source

How to Configure Email Alerts in Grafana 21

Search for Prometheus in the search bar and select it.

How to Monitor Redis with Prometheus and Grafana 39

In connection, in Prometheus server URL, give the server url on which our prometheus is running.

How to Configure Email Alerts in Grafana 22

after this click on save and test button. You will see the message for prometheus being successfully queried.

How to Monitor Redis with Prometheus and Grafana 41

Step #5:Add a Contact points

Get back to the Grafana home page and select the Alerting > Contact points.

How to Configure Email Alerts in Grafana 23

click on Add contact point.

How to Configure Email Alerts in Grafana 24

Give a appropriate name to your contact point. Like Grafana.

Select Email as a Integration

Then in addresses give the email id or id’s with comma separating them.

And click on Test to test it.

How to Configure Email Alerts in Grafana 25

Click on Send test notification .

How to Configure Email Alerts in Grafana 26

Now open your email id you’ve given, there you can see the test alert. Click on it.

How to Configure Email Alerts in Grafana 27
How to Configure Email Alerts in Grafana 28

after this go back to grafana and click on save contact point to save it.

How to Configure Email Alerts in Grafana 29

Step #6:Configure the Notification Policies

Now in alerting select the Notification policies.

How to Configure Email Alerts in Grafana 30

There will be a default policy click and edit it.

How to Configure Email Alerts in Grafana 31

Change the default contact point to the one we had created. Here it is Grafana.

Then click on Update default policy.

How to Configure Email Alerts in Grafana 32

Step #7:Configure Alert Rules to get email alerts

Now in Alerting Select the Alert rules .

How to Configure Email Alerts in Grafana 33

select the New alert rule.

How to Configure Email Alerts in Grafana 34

Here Enter alert rule name to identify your alert.

Define the query and alert condition.

  • metric: process_cpu_seconds_total
  • label filters: instance = localhost:9090
How to Configure Email Alerts in Grafana 35

This query would retrieve the total CPU time consumed by all processes over time.

Now Select the Grafana-managed as Rule type. In the Expressions, set Threshold as alert condition and change the IS ABOVE to 0.7

When setting “IS ABOVE” to 0.7, you’re specifying that the alert should trigger when the value of the metric being monitored is above 70%. This value could represent a percentage, ratio, or any other unit depending on the metric being monitored.

How to Configure Email Alerts in Grafana 36

In Set evaluation behavior, create a new folder to store rule and evaluation group.

here folder name is CPU time.

Evaluation group name is CPU time and evaluation interval is 30 seconds which tells how often the rule is evaluated. Click on Create.

How to Configure Email Alerts in Grafana 37

Change the pending period to 30 seconds. It should be equal to evaluation interval or less than it.

Finally click on Save rule and exit to trigger the email alerts.

How to Configure Email Alerts in Grafana 38

Now wait of 30 seconds till it fire the alert

Check your email box.

How to Configure Email Alerts in Grafana 39

as you can see our alert is fired successfully.

with this you can receive timely Email alerts.

How to Configure Email Alerts in Grafana 40

Conclusion:

Configuring email alerts in Grafana enables you to receive immediate notifications about critical events or anomalies detected in your monitoring data. By following the steps outlined in this guide, you can set up email notification channels, define alert rules, and ensure that you receive timely alerts via email. Effective alerting enhances your ability to monitor and respond to changes in your system’s health and performance, ultimately improving overall reliability and uptime.

Related Articles:

How to Monitor Redis with Prometheus and Grafana

Reference:

Grafana Installation official page

Prasad Hole

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap