In my previous blog, we created the first Grafana dashboard. Now in this blog, we will create our first monitoring Grafana alert.
Before creating monitoring alerts, we need to add the notification channel through which we will be notified. Here, we will be adding slack as the notification channel.
Slack notification channel:
First, open the URL http://localhost:3000 in the browser and log in to the Grafana. Then click on the “Notification Channels” option at the left-hand side.
Then click on “Add Channel” button and you will get the following screen:
Then, select the Slack from Type field and provide the Slack webhook URL. (Other fields are not mandatory). We can set up other alerts as well by selecting the option from Type field. For slack webhook URL, please see the guide here.
Few key points:
- If you want to add this channel to all the alerts by default then tick the checkbox for “Send on all alerts”.
- If you want reminders then tick the checkbox for “Send reminders” and reminder frequency time.
You can test the setup by clicking on “Send Test” button at the bottom. After setting up all the fields, just click on the Save button. For more details, check out here.
Now let’s create the alert.
Go to Dashboard → Manage → (Please find these options at left-hand side). Click on Dashboard Edit to set alerts:
Go to the Alert section of the dashboard and create an alert there:
In alert section, Set the Alert Config and Notification as per the requirement.
In alert config, we need to add the conditions. We can add multiple conditions here. We need to use either AND or OR to make the relationship between multiple conditions.
As a condition, we get only 5 options:
- IS ABOVE
- IS BELOW
- IS OUTSIDE RANGE
- IS WITHIN RANGE
- HAS NO VALUE
You will find “Evaluate every” option there which takes 2 values:
- every: Within how many seconds/minutes conditions need to be evaluated
- for: For how long the condition needs to be evaluated.
For ex: Evaluate every 20s for 40s.
It means conditions will be evaluated in every 20 seconds but for 40 seconds. It means it will be evaluated 2 times.
Alert is having 3 states:
- OK: When the overall value of conditions are false
- Pending: When the overall value of conditions is true
- Alerting: When the overall value of condition is true continuously until the value of for.
If we take the above example then it will go in alerting mode when the conditions get true for continuous 40 seconds.
Here, we add the notification channel where alert needs to be sent and the alert message. For more details, check out here.
That’s it. I hope, it will be helpful for you and you will be able to create your first alert easily.