{"id":8584,"date":"2021-04-10T13:02:38","date_gmt":"2021-04-10T10:02:38","guid":{"rendered":"https:\/\/kifarunix.com\/?p=8584"},"modified":"2024-03-19T08:23:52","modified_gmt":"2024-03-19T05:23:52","slug":"configure-grafana-email-alerting","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/configure-grafana-email-alerting\/","title":{"rendered":"Configure Grafana Email Alerting"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to configure Grafana Email alerting. <em>Grafana alerting allows you to attach rules to your dashboard panels.<\/em> <em>When you save the dashboard, Grafana extracts the alert rules into a separate alert rule storage and schedules them for evaluation.<\/em> <em>When an alert changes state, it sends out notifications<\/em> through various channels including Email, Slack, Google Hangout Chat or <a aria-label=\"several other integrations (opens in a new tab)\" href=\"https:\/\/grafana.com\/docs\/grafana\/latest\/alerting\/notifications\/#list-of-supported-notifiers\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">several other integrations<\/a>.<\/p>\n\n\n\n<p>Note that Alerting is only available in Grafana v4.0 and above and is only supported on graph panels, at least as at now.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring Grafana Email Alerting<\/h2>\n\n\n\n<p>There are several notification channels that you can configure your Grafana to sent alerts through. However, this tutorial focuses on using Email alerting.<\/p>\n\n\n\n<p>To demonstrate Grafana Email alerting, we have created dashboards for monitoring system metrics using Prometheus and Grafana. See the dashboard below for visualizing the load average for a system.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"895\" height=\"422\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-cpu-load-average.png\" alt=\"\" class=\"wp-image-8615\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-cpu-load-average.png?v=1618041151 895w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-cpu-load-average-768x362.png?v=1618041151 768w\" sizes=\"(max-width: 895px) 100vw, 895px\" \/><\/figure><\/div>\n\n\n<p>To easily demonstrate Grafana email alerting, we will setup Grafana to sent alerts when the load for the last 1, 5, 15 mins is 3.00,2.00,1.00.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Grafana SMTP settings<\/h3>\n\n\n\n<p>Before Grafana can be able to sent email alerts, you need to configure how alerts will be relayed.<\/p>\n\n\n\n<p>In this demo, we will configure Grafana to Gmail relay to sent out emails. You can use any of your preferred mail servers.<\/p>\n\n\n\n<p>Hence, open the Grafana configuration file and navigate to <strong>smtp<\/strong> section.<\/p>\n\n\n\n<p>Check the values for the highlighted lines and replace them accordingly.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/grafana\/grafana.ini<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[smtp]\n<strong>enabled = true\nhost = smtp.gmail.com:587 \nuser = username@gmail.com<\/strong>\n<strong># If the password contains # or ; you have to wrap it with triple quotes. Ex \"\"\"#password;\"\"\"\npassword = \"\"\"pass123#\"\"\"\n<\/strong>;cert_file =\n;key_file =\n<strong>skip_verify = true\nfrom_address = admin@grafana.kifarunix-demo.com\nfrom_name = Grafana<\/strong><\/code><\/pre>\n\n\n\n<p>Pay attention to the line, <strong># If the password contains # or ; you have to wrap it with triple quotes. Ex &#8220;&#8221;&#8221;#password;&#8221;&#8221;&#8221;<\/strong>.<\/p>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<p>Restart Grafana service;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart grafana-server<\/code><\/pre>\n\n\n\n<p>Note: If you are using Gmail relay, ensure that you turn on <a href=\"https:\/\/myaccount.google.com\/lesssecureapps\" target=\"_blank\" aria-label=\"less secure apps (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">less secure apps<\/a> to sent mails.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Add Grafana Notification Channel<\/h3>\n\n\n\n<p>Click Alerting icon (bell like icon) on the Grafana side bar and then click <strong>Notification channel<\/strong>. This should open up the Alerts and Notifications page;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1495\" height=\"408\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-settings.png\" alt=\"Configure Grafana Email Alerting\" class=\"wp-image-8631\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-settings.png?v=1618048383 1495w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-settings-768x210.png?v=1618048383 768w\" sizes=\"(max-width: 1495px) 100vw, 1495px\" \/><\/figure>\n\n\n\n<p>Click <strong>Add Channel<\/strong> to create a new Email notification channel<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Set the name of the channel<\/li>\n\n\n\n<li>Choose the channel notification method, <strong>Email<\/strong> is used in this case.<\/li>\n\n\n\n<li>Enter addresses of the recipients. Multiple addresses are separated using semi-colon.<\/li>\n\n\n\n<li>Select your notification settings;<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1190\" height=\"935\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/add-notification-channel-1.png\" alt=\"\" class=\"wp-image-8636\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/add-notification-channel-1.png?v=1618074624 1190w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/add-notification-channel-1-768x603.png?v=1618074624 768w\" sizes=\"(max-width: 1190px) 100vw, 1190px\" \/><\/figure>\n\n\n\n<p>Once you have configured your channel settings, click <strong>Test<\/strong> to verify email deliverability.<\/p>\n\n\n\n<p>If all is fine, you should get <strong>Test notification sent<\/strong>.<\/p>\n\n\n\n<p>Also, you should receive Test notification email on your recipient inbox.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1508\" height=\"884\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-test-alert.png\" alt=\"\" class=\"wp-image-8603\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-test-alert.png?v=1617823162 1508w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-test-alert-768x450.png?v=1617823162 768w\" sizes=\"(max-width: 1508px) 100vw, 1508px\" \/><\/figure>\n\n\n\n<p>If not, check Grafana logs;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>tail -f \/var\/log\/grafana\/grafana.log<\/code><\/pre>\n\n\n\n<p>Save the Channel, when done testing.<\/p>\n\n\n\n<p>Click on the title of the graph panel that you want to configure alerts for and click <strong>Edit<\/strong>. For example in our case, we have a graph for CPU load average.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"895\" height=\"422\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/edit-grafana-panel.png\" alt=\"\" class=\"wp-image-8630\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/edit-grafana-panel.png?v=1618048275 895w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/edit-grafana-panel-768x362.png?v=1618048275 768w\" sizes=\"(max-width: 895px) 100vw, 895px\" \/><\/figure><\/div>\n\n\n<p>When the panel is opened for editing, click on the <strong>Alert<\/strong> tab.<\/p>\n\n\n\n<p>Next, click <strong>Create Alert<\/strong> to setup your alerting;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set the rule name and frequency for evaluation of your threshold before an alert is sent out (we set it to evaluate a threshold for 1 min every 1 mins for easy demo).<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1096\" height=\"168\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-rule-settings.png\" alt=\"\" class=\"wp-image-8617\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-rule-settings.png?v=1618043703 1096w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-rule-settings-768x118.png?v=1618043703 768w\" sizes=\"(max-width: 1096px) 100vw, 1096px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set the rule conditions based on the number of queries your graph panel have. So we have three queries and hence three conditions of each Query.<\/li>\n<\/ul>\n\n\n\n<p>The queries<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1374\" height=\"332\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-queries.png\" alt=\"\" class=\"wp-image-8618\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-queries.png?v=1618043883 1374w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-queries-768x186.png?v=1618043883 768w\" sizes=\"(max-width: 1374px) 100vw, 1374px\" \/><\/figure>\n\n\n\n<p>The Conditions:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1025\" height=\"239\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-conditions.png\" alt=\"\" class=\"wp-image-8619\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-conditions.png?v=1618043946 1025w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-conditions-768x179.png?v=1618043946 768w\" sizes=\"(max-width: 1025px) 100vw, 1025px\" \/><\/figure>\n\n\n\n<p>When you set the conditions, an icon shown in the screenshot below is set on the graph panel;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1367\" height=\"308\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-sign-on-graph.png\" alt=\"\" class=\"wp-image-8622\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-sign-on-graph.png?v=1618045609 1367w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/alert-sign-on-graph-768x173.png?v=1618045609 768w\" sizes=\"(max-width: 1367px) 100vw, 1367px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>No data and error handling settings<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"141\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/no-data-alert-handling.png\" alt=\"\" class=\"wp-image-8620\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/no-data-alert-handling.png?v=1618044149 786w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/no-data-alert-handling-768x138.png?v=1618044149 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Choose the Notification channel created earlier by clicking <strong>Send to<\/strong>.<\/li>\n\n\n\n<li>Set the notification message body. You can create your custom message as you see fit;<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1477\" height=\"345\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-alert_channel-message-body.png\" alt=\"\" class=\"wp-image-8626\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-alert_channel-message-body.png?v=1618047260 1477w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-alert_channel-message-body-768x179.png?v=1618047260 768w\" sizes=\"(max-width: 1477px) 100vw, 1477px\" \/><\/figure>\n\n\n\n<p>Save the dashboard when done setting the alert rule and conditions and notifications.<\/p>\n\n\n\n<p>Test the alerting by clicking on <strong>Test rule<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1048\" height=\"846\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-alert-test-rule.png\" alt=\"\" class=\"wp-image-8623\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-alert-test-rule.png?v=1618045753 1048w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-alert-test-rule-768x620.png?v=1618045753 768w\" sizes=\"(max-width: 1048px) 100vw, 1048px\" \/><\/figure>\n\n\n\n<p>Now your graph panel shows like as below with all the values of the last 1,5,15 mins load average within the range. With green line showing the threshold is fine.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"896\" height=\"302\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-graph-with-alert_set.png\" alt=\"\" class=\"wp-image-8627\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-graph-with-alert_set.png?v=1618047822 896w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-graph-with-alert_set-768x259.png?v=1618047822 768w\" sizes=\"(max-width: 896px) 100vw, 896px\" \/><\/figure><\/div>\n\n\n<p>Now, we need to simulate the CPU usage by running the command below;<\/p>\n\n\n\n<p>run the command below like four times on the terminal;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>i=1; while [ $i -le 4 ]; do yes &gt; \/dev\/null &amp; ((i++)); done<\/code><\/pre>\n\n\n\n<p>Watch the CPU hike using htop\/top or w commands as you view your grafana graph.<\/p>\n\n\n\n<p>Once you see the red line, that is when the alert if fired.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"339\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-alerts-fired.png\" alt=\"\" class=\"wp-image-8628\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-alerts-fired.png?v=1618048085 912w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-alerts-fired-768x285.png?v=1618048085 768w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><\/figure><\/div>\n\n\n<p>The mail alert notification;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1475\" height=\"761\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-email-alerts.png\" alt=\"Configure Grafana Email Alerting\" class=\"wp-image-8629\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-email-alerts.png?v=1618048135 1475w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/04\/grafana-email-alerts-768x396.png?v=1618048135 768w\" sizes=\"(max-width: 1475px) 100vw, 1475px\" \/><\/figure>\n\n\n\n<p>And there you go.<\/p>\n\n\n\n<p>Other Tutorials;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-elk-stack-alerting-with-elastalert\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Configure ELK Stack Alerting with ElastAlert<\/a><\/p>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/monitor-ssl-tls-certificate-expiry-with-prometheus-and-grafana\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Monitor SSL\/TLS Certificate Expiry with Prometheus and Grafana<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/monitoring-gitlab-metrics-with-prometheus-and-grafana\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Monitoring Gitlab Metrics with Prometheus and Grafana<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to configure Grafana Email alerting. Grafana alerting allows you to attach rules to your dashboard panels. When you<\/p>\n","protected":false},"author":3,"featured_media":8628,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[72,301,121,294,933],"tags":[3414,3420,3419,3418,3415,3421,3416,3417],"class_list":["post-8584","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-monitoring","category-grafana","category-howtos","category-prometheus","category-telegraf","tag-configure-grafana-email-alerting","tag-create-alerts-grafana","tag-grafana-alert-rules","tag-grafana-alerts","tag-grafana-alerts-via-mail","tag-grafana-create-alerts","tag-grafana-gmail-relay","tag-grafana-smtp-settings","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8584"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=8584"}],"version-history":[{"count":10,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8584\/revisions"}],"predecessor-version":[{"id":21851,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8584\/revisions\/21851"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/8628"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=8584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=8584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=8584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}