Skip to main content

Sending Email Alerts in Grafana

Let's first understand what a typical workflow to send email based alerts in Grafana looks like.

Email Alert Workflow in Grafana

Setting up SMTP Configuration in Grafana

  1. Edit the Grafana Configuration File:

    • Locate the grafana.ini file in your installation directory (e.g., /etc/grafana/grafana.ini for Linux).
    • Open it for editing using a text editor, such as nano or vim.
  2. Configure SMTP Settings:

    • In the [smtp] section of the configuration file, update the following fields:

      [smtp]
      enabled = true
      host = smtp.your-email-provider.com:587
      user = your_email@example.com
      password = your_email_password
      from_address = grafana@example.com
      from_name = Grafana Alerts
    • Replace smtp.your-email-provider.com, your_email@example.com, and your_email_password with your SMTP provider's details.

  3. Save and Restart Grafana:

    • Save the changes to the grafana.ini file.

    • Restart the Grafana service to apply the new configuration:

      sudo systemctl restart grafana-server
  4. Test SMTP Configuration:

    • Log in to Grafana and navigate to Alerting > Notification channels.
    • Click New notification channel, select Email, and enter a valid email address.
    • Send a test email to verify the SMTP settings.

Configuring Email Alerts in Grafana

Here’s how you can configure and send alerts in Grafana after setting up SMTP:

1. Set Up Notification Channels

  • Log in to Grafana and go to Alerting > Notification channels.
  • Click New Notification Channel and choose Email as the type.
  • Fill in the following details:
    • Name: Give the channel a name, e.g., Email Alerts.
    • Email Addresses: Add one or more email addresses separated by commas.
    • (Optional) Default Channel: Check this box if you want this channel to be the default notification channel.
  • Click Send Test to verify the configuration.
  • Save the notification channel.

2. Create an Alert Rule

  • Navigate to the dashboard where you want to set up alerts.
  • Click the Panel Title and select Edit.
  • Switch to the Alert tab and click Create Alert.
  • Configure the alert:
    • Conditions: Define conditions for the alert based on the metrics (e.g., when CPU usage exceeds 80%).
    • Evaluate Every: Set how often the alert should evaluate (e.g., every 1m).
    • For: Define how long the condition must be met before triggering the alert.
  • Add a Notification:
    • Select the email notification channel you configured earlier.
  • Save the changes.

3. Test the Alert

  • After saving, trigger the conditions for the alert and ensure an email notification is sent.