Indonesia Website Awards
Indonesia Website Awards

Hello everyone, in my post this time, I will continue my discussion about server monitoring. Some time ago I have posted about Server Monitoring with Grafana, Prometheus and node_exporter. This time, what I will discuss are 5 easy steps to create grafana email alerts with gmail. Alerts or warnings are very important in monitoring a server. By implementing this warning, it will be easier for all of us to carry out monitoring, especially if monitoring has to be carried out 24 hours non-stop. By using the alerting feature in Grafana, we can receive real-time reports from the server regarding the current status of the server we have. Alright, let’s get started :

 

1. Allow Access for less secure apps on GMail Account

Because we are going to use gmail to send alerts, we need to first enable access for the less secure apps on the email account that we want to use. I will not explain how, you can googling about how, or you can read Google’s guide on Controll access to less secure apps. If done, you can proceed to step 2.

 

2. Test Sending Email with SSMTP

After giving access permission for less secure apps, do a test using ssmtp on your server. If ssmtp is not installed, install it first using :

#Installation SSMTP for Ubuntu
sudo apt-get update
sudo apt-get install ssmtp

#Installation SSMTP for CentOS
sudo yum install epel-release
sudo yum update
sudo yum install ssmtp

When finished, open the ssmtp configuration file in /etc/ssmtp/ssmtp.conf with your favorite editor, then edit or add the following configuration :

root=example@gmail.com
mailhub=smtp.gmail.com:587
FromLineOverride=YES
AuthUser=example@gmail.com
AuthPass=yourPassword
UseTLS=YES
UseSTARTTLS=YES

Customize your email with a password from your GMail, then save it.

Then use the following command to test sending email via CLI :

echo "E-Mail Testing" | ssmtp example@gmail.com

Check your email inbox to see if the email was successfully sent via CLI. If it is successful, you can proceed to step 3.

 

3. Configure Grafana SMTP

The next step you need to do is configure SMTP Grafana. Access the grafana configuration file with your editor in /etc/grafana/grafana.ini, then go to the [smtp] section, after that change or add the configuration so that it looks like this :

[smtp]
enabled = true
host = smtp.gmail.com:587
user = example@gmail.com
password = Password
skip_verify = true
from_address = example@gmail.com
from_name = whateverYouWant

Customize your email with a password from your GMail, then save it. After that, restart the Grafana service.

 

4. Settings for Grafana Email Alerts

go to step 4, we will set up Grafana email notification. First of all, access your Grafana via a browser. Then create a new notification channel for notification via email. follow these steps :

  • Access your Grafana via browser,
  • Go to Alerting > Notofication channel,
  • Click New channel,
  • fill in the data as needed, specifically for the Type column, choose Email, for example like this

create grafana email alerts

  • Click Send Test for sending email testing,
  • Check your email inbox, If the test send an email is successful, there will be an email like this :

grafana test sending email

  • If it is successful, click Save to save the configuration

 

5. Creating Grafana Email Alerts on Each Panel

Okay, we come to the last step. After everything is ready, you only need to create alerts on each panel that you want. In creating grafana alerts, you can define various conditions that trigger the alert. For example, I will create a simple alert on the panel that monitors the status of server memory usage, where the alert will be triggered if the server memory usage exceeds 70%.

  • Access your Grafana via browser
  • Edit panel for which you want to create an alert,
  • Choose Alert menu,
  • Click Create Alert,
  • Fill in data in the rules and conditions (triggers) as needed, in my example the condition is “WHEN avg() OF query (A,5m,now) IS ABOVE 70″,
  • In the No Data & Error Handling section you can adjust it as needed,
  • Fill in the data in the Notification section. in the send to column, you can select the channel that you created in the previous step. Then in the message section you can enter the message you want,
  • Click Test rule to test alert,
  • When it’s okay, click Apply to save.

You can see the visualization in the animated GIF below :

create grafana email alerts

create grafana email alerts

 

Do this step 5 on each panel where you want to install alert notification.

 

Well, that’s information about 5 easy steps to create grafana email alerts with gmail that I can share with all of you. Hopefully this information can be useful. Thank you 😀

 

 


1 Comment

Domeny XMC · 16 May 2022 at 11:32 am

I sincerely took delight in reading your site, you explained some first-rate points. I want to bookmark your post. I saved you to delicious and yahoo bookmarks. I will attempt to revisit to your site and examine more posts.

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *