Setup alerts in Grafana 10 with example

Learning Software
6 Jan 202427:33

Summary

TLDRThis video tutorial offers a comprehensive guide on setting up alerts in Grafana, a powerful visualization and analytics platform. It covers the essentials of alerting concepts, such as rules, states, contact points, and notification policies. The presenter demonstrates creating an alert rule using a PostgreSQL data source, with a practical example of monitoring temperature thresholds. Viewers learn how to send notifications via Gmail and visualize alerts on dashboards, gaining insights into real-time data monitoring and proactive alert management.

Takeaways

  • 😀 Grafana is a powerful platform for data visualization, analytics, and alerting, allowing users to create interactive dashboards.
  • 🔍 The tutorial focuses on setting up alerts in Grafana using a PostgreSQL data source for real-time data monitoring.
  • 📈 The example demonstrates visualizing and alerting based on temperature data from a sensor in a PostgreSQL database.
  • ⚠️ Alerts are triggered when the temperature exceeds a specified threshold, in this case, 30°, and are cleared when it falls below this value.
  • 📊 Understanding key concepts like alert rules, alert states, contact points, and notification policies is crucial for configuring alerts in Grafana.
  • 📝 Alert rules define the conditions under which an alert is triggered, including data source, condition, and duration of the condition.
  • 🔔 There are three main alert states: OK, pending, and alerting, each representing different stages of alert condition satisfaction.
  • 💬 Contact points are the mechanisms through which alert notifications are sent, such as email, web hooks, Slack, or Discord.
  • 🛠️ Notification policies determine which contact points are used for alert notifications and can be linked to alert rules using labels.
  • 📧 The tutorial includes a step-by-step guide on configuring Grafana to send emails using Gmail, including setting up app passwords for authentication.
  • 🔗 The video script provides links to additional resources, such as a playlist on Grafana, a blog post on the topic, and a video on connecting PostgreSQL to Grafana.

Q & A

  • What is Grafana and what can it be used for?

    -Grafana is a visualization, analytics, and alerting platform that allows users to build interactive dashboards easily. It can be used for real-time data monitoring and creating alerts based on various conditions.

  • How can Grafana be connected to a PostgresSQL database for time series visualization?

    -The script provides a method to connect Grafana to a PostgresSQL database by using a data source. There are also previous videos and a blog post available that explain the connection process in detail.

  • What is the purpose of creating alerts in Grafana?

    -The purpose of creating alerts in Grafana is to monitor data continuously and trigger notifications when certain conditions are met, such as when a sensor's temperature exceeds a specified threshold.

  • What are the main concepts needed to understand Grafana alerts?

    -The main concepts needed to understand Grafana alerts are alert rules, alert states, contact points, and notification policies.

  • Can you explain what an alert rule is in the context of Grafana?

    -An alert rule in Grafana defines the conditions for when an alert should be triggered. It specifies the data source, the condition to be checked, the frequency of checks, and the duration for which the condition must be met to trigger the alert.

  • What are the three main alert states in Grafana?

    -The three main alert states in Grafana are OK, Pending, and Alerting. OK indicates no alerting condition is met, Pending means the condition is met but not for the required duration, and Alerting is when the condition is met for more than the specified duration.

  • What is a contact point in Grafana and what is it used for?

    -A contact point in Grafana is a notification medium used to send alert information to stakeholders. It can include various integrations like email, web hooks, Slack, Discord, etc.

  • How can alerts be sent from Gmail through Grafana?

    -Grafana can be configured to use Gmail as a contact point to send alerts. This involves setting up SMTP settings in Grafana's configuration file and creating app passwords in Gmail for authentication.

  • How can alerts be linked to a dashboard panel in Grafana?

    -Alerts can be linked to a dashboard panel in Grafana by editing the alert rule and using the 'Link dashboard and panel' option. This allows the alert state to be overlayed on the dashboard panel for visual representation.

  • What is the significance of the state history in Grafana alerts?

    -The state history in Grafana alerts provides a record of when alerts were triggered and when they returned to a normal state. It helps in understanding the transition of alert states over time.

Outlines

00:00

📊 Introduction to Grafana Alerts

The speaker introduces the topic of creating alerts in Grafana, a platform for data visualization, analytics, and alerting. They mention having a playlist on Grafana and a blog post on the same topic, both linked in the description. The video aims to guide viewers on setting up real-time data monitoring and alerts using a PostgreSQL data source. The example revolves around monitoring temperature data from a sensor, raising an alert when it exceeds a threshold, and removing it when it falls below. The speaker also plans to demonstrate sending alerts via Gmail and explains the basic concepts needed to understand Grafana alerts, such as alert rules, alert states, contact points, and notification policies.

05:01

🛠️ Setting Up Grafana and Populating Data

The speaker demonstrates logging into Grafana and accessing the data sources, including a previously connected PostgreSQL data source. They guide viewers on how to create a dashboard to display data from the data source. Since the data source is initially empty, the speaker populates it with dummy data using a script provided in a previous video. The script generates random temperature data for a specified time range. The speaker then creates a new dashboard, adds a visualization, and writes a SQL query to fetch the temperature data from the PostgreSQL database. The data is visualized, and the dashboard is saved.

10:02

🔧 Creating an Alert Rule in Grafana

The speaker walks through the process of creating an alert rule in Grafana. They explain the need for defining queries, expressions for alert evaluation, and setting conditions for alert states. The process involves setting up a threshold expression to trigger an alert if the temperature exceeds 30 degrees. The speaker also discusses the use of reduce expressions to simplify series data and the use of classic conditions for simpler alert rules. They preview the alert state based on the defined conditions and explain how to set up evaluation behavior, including the frequency of checks and the pending period before an alert is fired.

15:03

💬 Configuring Notification Policies and Contact Points

The speaker explains how to set up notification policies and contact points in Grafana. They guide viewers on creating a contact point for email notifications and configuring Grafana to send emails using Gmail's SMTP settings. This includes generating an app password for Gmail to allow Grafana to authenticate and send emails. The speaker also shows how to create a notification policy that links alert rules with contact points, ensuring that alerts are sent to the specified email addresses when triggered.

20:03

🔗 Linking Alerts with Dashboard and Testing

The speaker demonstrates linking alert rules with a dashboard panel to overlay alert states on the dashboard. They adjust the alert rule to trigger an alert at a lower temperature threshold for demonstration purposes. The speaker then shows how to view the alert state on the dashboard and how changes in the alert state result in notifications being sent. They also explain how to view the state history of alerts to track when thresholds were violated. The speaker concludes by encouraging viewers to check out the linked blog post for more detailed information and to engage with the content by asking questions or providing feedback.

Mindmap

Keywords

💡Grafana

Grafana is an open-source platform for data visualization and monitoring. It allows users to create interactive dashboards to display and analyze time-series data. In the video, Grafana is the central tool used to demonstrate how to set up alerts for real-time data monitoring, emphasizing its role in visual analytics.

💡Alerts

Alerts in the context of Grafana are notifications triggered by specific conditions met in the data being monitored. They are crucial for real-time data monitoring and are the main focus of the video, where the process of creating and managing these alerts is explained.

💡PostgreSQL

PostgreSQL, often referred to as Postgres, is a powerful, open-source object-relational database system. In the video, it is used as a data source for Grafana to visualize and monitor time-series data, such as sensor temperature readings.

💡Dashboards

Dashboards in Grafana are customizable, interactive pages that organize and display data in various panels. The video script describes the creation of a dashboard to visualize temperature data from a PostgreSQL database.

💡Alert Rules

Alert rules in Grafana define the conditions under which an alert is triggered. The script explains how to set up an alert rule based on a temperature threshold, which is a core part of configuring alerts in Grafana.

💡Alert States

Alert states represent the current status of an alert, such as 'OK', 'Pending', and 'Alerting'. The video discusses these states in the context of monitoring temperature data, explaining how the state changes in response to the data meeting certain conditions.

💡Contact Points

Contact points in Grafana are the destinations for alert notifications, such as email addresses or Slack channels. The script describes setting up a contact point to send email notifications when an alert is triggered.

💡Notification Policies

Notification policies in Grafana determine which contact points are used to send alert notifications. The video explains how to create a policy that associates an alert rule with a specific contact point, ensuring that alerts are routed correctly.

💡Thresholds

Thresholds are values that define the limits for triggering alerts. In the video, a temperature threshold of 30° is used as an example to illustrate how alerts are raised when the temperature exceeds this value.

💡Data Source

A data source in Grafana is a database or other external service from which Grafana retrieves data to display in dashboards. The script mentions connecting PostgreSQL as a data source for Grafana to visualize sensor data.

💡Evaluation Behavior

Evaluation behavior in Grafana refers to how often and how alerts are checked against their conditions. The video script describes setting the frequency of alert evaluation, which is essential for timely alerting based on real-time data.

Highlights

Introduction to Grafana as a visualization, analytics, and alerting platform.

Explanation of how to create alerts in Grafana for real-time data monitoring.

Link to a playlist on Grafana provided for further learning.

Demonstration of using Grafana with a PostgreSQL data source for time series visualization.

Tutorial on setting up alerts based on temperature thresholds from sensor data.

Description of alert states: OK, pending, and alerting with examples.

Introduction to contact points and notification policies in Grafana alerting.

Guide on sending alerts via Gmail using Grafana's alerting system.

Conceptual overview of alert rules and their configuration in Grafana.

Step-by-step guide on creating a dashboard in Grafana to visualize data from a PostgreSQL database.

Instructions on creating an alert rule in Grafana with a threshold expression.

Explanation of evaluation behavior and how to set intervals for alert checks.

How to add annotations to alert rules for better alert summaries.

Process of assigning labels to alerts for routing to specific notification channels.

Configuration of Grafana to send emails using Gmail SMTP settings.

Creating and managing notification policies to link alerts with contact points.

Linking alerts to dashboard panels for real-time alert visualization.

Demonstration of state history in Grafana to track alert transitions over time.

Final summary on configuring multiple alerts in Grafana and managing notifications.

Transcripts

play00:00

hi friends in this video we're going to

play00:01

talk about how to create alerts in

play00:03

grafana if you don't know what grafana

play00:05

is grafana is an awesome visualization

play00:08

analytics and alerting platform where

play00:10

you can build interactive dashboards

play00:12

very easily I have made a playlist on

play00:14

grafana and I will leave the link of the

play00:16

playlist in the description so in this

play00:17

video we're going to talk about how to

play00:19

use grafana for realtime data monitoring

play00:21

and creating alerts you can see I

play00:24

created a blog post on this topic and I

play00:25

will leave the link of this blog post in

play00:27

the description so I'm going to explain

play00:29

alerting grafana using a postest SQL

play00:32

data source in our previous video we

play00:34

have talked about how to use grafana to

play00:36

connect to postest SQL for time series

play00:38

visualization I will leave the link of

play00:39

this video in the description you can

play00:41

see that to understand how to connect

play00:43

post SQL with grafana so the thing we

play00:46

are going to achieve in this video is we

play00:48

will visualize POS SQL in grafana and

play00:50

create alerts based on conditions in our

play00:53

example we are plotting the temperature

play00:54

from a sensor data present in the poess

play00:56

SQL database and we are going to raise

play00:58

an alert if the temperature raises from

play01:00

a specified threshold value suppose if

play01:03

the temperature is greater than 30°

play01:04

raise an alert and if the temperature

play01:06

goes below 30° again then the alert will

play01:09

be removed again if the temperature goes

play01:12

above 30° then the alert will be raised

play01:14

so we are going to achieve this setup in

play01:16

this video and when an alert is raised

play01:18

or an alert is removed you will get a

play01:20

notification and we are going to

play01:22

demonstrate how to send alerts from

play01:24

Gmail and grafana will use Gmail to send

play01:27

alerts to the specified stakeholders so

play01:30

this is what we are going to achieve in

play01:31

this video so let's get started so

play01:33

before using grafana to configure alerts

play01:35

let's try to get to know some Concepts

play01:37

because without knowing that Concepts

play01:39

you can't use grafana to configure

play01:41

alerts so we are trying to achieve

play01:43

alerting in grafana and to understand

play01:45

grafana alerts you need to know about

play01:47

these Concepts alert rules alert States

play01:51

contact points and notification policies

play01:54

so let's start to go through these

play01:55

Concepts one by one so what is an alert

play01:57

rule so alert rule is basically what it

play01:59

literally means it's the rule which

play02:01

defines the alert for example you can

play02:04

write an alert to check the data

play02:07

continuously each minute and raise an

play02:09

alert if temperature is greater than 30°

play02:11

and if this condition is met

play02:12

continuously for 5 minutes then only you

play02:14

can raise an alert so this is an example

play02:17

of an alerting condition so in an

play02:19

alerting rule you define which data

play02:21

source should fet the data from and what

play02:23

is the alerting rule and what is the

play02:25

periodicity of checking the alerts and

play02:27

how much time the alert should be

play02:29

persisting to raise an alert so these

play02:31

are all defined in the alerting room and

play02:34

the next thing is the alerting states so

play02:36

there are mainly three alert states

play02:39

which is okay pending and alerting let's

play02:42

take our temperature example if the

play02:43

temperature is less than 30° then the

play02:45

state is okay because no alerting

play02:48

condition is met if the temperature is

play02:50

greater than 30° for 2 minutes the state

play02:53

would be pending because for us to raise

play02:56

an alert the temperature should be

play02:58

greater than the threshold for 5 minutes

play02:59

right so the alerting condition is met

play03:02

but still the desired duration of the

play03:05

alert is not completed so that state

play03:08

would be in pending and if the

play03:10

temperature is greater than the

play03:11

threshold for more than 5 minutes then

play03:13

the state would be alerting so this way

play03:16

the alerting rule can have three alert

play03:18

states which is okay pending and

play03:20

alerting and now the temperature again

play03:22

falls back from threshold to normal

play03:24

value then again the state will be okay

play03:27

state so this way these are the three

play03:29

alert States and obviously if the data

play03:31

source is not responding or if there is

play03:33

no data in the data source then the

play03:35

state would be no data and while

play03:37

evaluating the alert rule if there is

play03:39

some error the Alert state would be

play03:41

error State mostly you would be dealing

play03:43

with these three states okay pending and

play03:45

alerting and if there is some data

play03:47

issues then you may get into these

play03:48

states which are no data and error so

play03:51

these are alerting states and the next

play03:53

thing is the contact point so contact

play03:55

point is basically a notification medium

play03:57

using which you can send your alert

play03:59

information to your stakeholders so in

play04:02

graan you can have multiple type of

play04:03

contact points like email web hooks

play04:06

slack Discord Etc so basically the

play04:09

change in alerting States can be

play04:11

notified using these contact points and

play04:14

in grafana a contact Point can be one or

play04:16

more Integrations that means you can

play04:18

define a single contact point and it can

play04:21

have mail and web hook integration both

play04:24

in one contact point so basically

play04:25

contact point is a group of one or more

play04:28

Integrations like email web hook Etc and

play04:31

the next thing is a notification policy

play04:34

so you defined an alerting Rule and you

play04:36

defined a contact Point using the

play04:38

notification policy you will specify

play04:40

what contact points would be used by the

play04:42

alert rule this is achieved by attaching

play04:45

labels to the alert rule so these were

play04:47

the concepts which are required to

play04:49

understand the alerts in grafana alert

play04:50

rules alert States contact points and

play04:53

notification policies all right enough

play04:55

of theory let's try to do the real demo

play04:57

in grafana so my grafana is already

play04:59

already up and running in my local host

play05:01

let's try to open grafana so my grafana

play05:03

is running at Local Host 3000 and I'm

play05:06

presented with the login screen let's

play05:07

try to log to

play05:08

grafana all right now I'm present in the

play05:10

grafana home screen so let's try to see

play05:13

my data sources so in the connections

play05:16

I'm seeing my data sources and I've

play05:18

already connected a posters SQL data

play05:19

source to my grafana so if you don't

play05:22

know how to connect a post SQL data

play05:23

source to grafana I already made a video

play05:25

on that and I will leave the link of

play05:26

that video in the description please go

play05:28

through that all right the next next

play05:29

step is to create a dashboard to show

play05:31

the data from the data source right but

play05:33

since there is no data in the data

play05:35

source I will just populate some dummy

play05:37

data for this demo purpose in my

play05:40

previous video blog post where I

play05:42

connected posters SQL to gaana as a data

play05:44

source I have given a sample script for

play05:47

populating some dummy data into the

play05:49

database I also given you the schema so

play05:51

you can run the schema to create the

play05:53

dummy table and you can run this script

play05:55

to create a dummy data in that table so

play05:58

let's try to copy the script

play06:00

and I'm using DB to connect to my

play06:02

database DB is an awesome tool using

play06:05

which you can connect to multiple types

play06:06

of databases and do a lot of database

play06:09

Administration tasks if you don't know

play06:10

about DV I already made a video on that

play06:12

and I will leave the link of that video

play06:14

in the description currently Ive

play06:15

connected my DB to my post SQL database

play06:18

and this is the script which I'm going

play06:19

to run and this script is going to

play06:21

create some random data in the database

play06:23

and it will create the random data for

play06:24

the past 1 hour to the next 4 hours so

play06:27

let's try to run this script all at the

play06:29

script is run and the data is populated

play06:31

in the database all right since I've

play06:33

populated some dummy data in my process

play06:34

SQL database let's try to visualize here

play06:37

so I'm going to create a dashboard here

play06:39

by going to the dashboards and let's try

play06:41

to create a new dashboard new dashboard

play06:44

and add visualization and I'm going to

play06:46

select to the database as the posst SQL

play06:48

database which I configured already

play06:51

let's try to move this up so that we can

play06:52

get some space to see the code and here

play06:55

instead of the Builder mode I'm going to

play06:57

go to the code mode and I'm going to

play06:59

write some some SQL here to populate the

play07:01

data so this is going to be my SQL

play07:03

select data time as time and temperature

play07:06

as Sensor One temperature where sensor

play07:09

ID equal to S1 and I'm applying the time

play07:11

filter so Ive already explained these

play07:13

terms in my previous video so if you

play07:15

don't know how to is post scale query in

play07:17

grafana please refer that video but for

play07:19

now we are plotting Sensor One

play07:21

temperature in this grafana dashboard so

play07:23

let's try to run this query and yeah you

play07:26

got your data here since we have

play07:28

inserted the D data for only the last 1

play07:30

hour this would be empty here so let's

play07:32

try to convert this from last 6 hours to

play07:35

last 1 hour and you got your data here

play07:38

all right we are able to successfully

play07:40

create a dashboard showing the

play07:42

temperature from our post SQL database

play07:44

let's try to save this let's try to name

play07:46

the dashboard as sample dashboard save

play07:50

and I got my dashboard here now the next

play07:52

thing is to create an alert right

play07:54

creating alerts in the newer version of

play07:56

grafana has changed a lot so let's try

play07:58

to see how it's done so in the left

play08:01

pan go for alerting and here you got

play08:04

alert rules I've already created some

play08:07

alert rule let's try to delete that

play08:11

already so now I don't have any alert

play08:13

rules let's try to create a new alert

play08:16

rule let's try to give a name to this

play08:18

alert rule I'll just name it Sensor One

play08:22

alert all right now we need to define

play08:25

the query again let's go to the code

play08:27

mode and let's try to Define the alert

play08:30

and here in the options you will Define

play08:33

how much period of data is to be fetched

play08:35

and here in the options I'm getting the

play08:38

last 10 minutes data which is okay for

play08:41

me because for alert evaluation last 10

play08:44

minutes data is more than enough for me

play08:46

but if you want to change your time

play08:47

range of fetching the data you can just

play08:50

change it here but I'm okay with now

play08:52

minus 10 minutes and apply time range

play08:55

that's it now again let's try to paste

play08:57

our query to f fetch the data let's try

play09:00

to run the

play09:01

query and here is the data which we are

play09:04

fetching the last 10 minutes data so in

play09:06

this way you can check whether your

play09:08

query is right or wrong so we have

play09:10

successfully defined the query to fet

play09:12

the data for our alerting condition and

play09:14

we have checked it here all right we

play09:16

have mentioned the name of the alert we

play09:18

have defined the query to fetch the data

play09:19

for the alert now let's try to create an

play09:22

expression to do alert evaluation so my

play09:25

alert evaluation rule would be create an

play09:27

alert if the threshold is greater than

play09:30

30° so just scroll down and they already

play09:33

given you some easy Expressions the

play09:35

first expression is a reduced expression

play09:37

and the second expression is a threshold

play09:39

expression so reduce expression just as

play09:42

the name implies you can reduce the

play09:44

whole series data into one number so the

play09:47

alas of my input query is a it can be

play09:50

seen right here and the input to this

play09:52

radius query is the a so a is being

play09:56

input for this radius query and that

play09:59

taking the last one but I would like to

play10:01

take the maximum value that means in the

play10:04

last 10 minutes I'm going to take the

play10:06

maximum value and the value would be

play10:09

here 27° you can see the preview value

play10:11

Also let's try to preview again the

play10:14

maximum value in the last 10 minutes was

play10:16

29° and for alerts to work the output

play10:19

should be zero or one so that can be

play10:21

achieved using the threshold expression

play10:24

so the input would be this query which

play10:26

is the B query so input would be B and

play10:28

if it above 30° the threshold is

play10:31

satisfied so e above would be converted

play10:34

to 30° so we have defined that if B is

play10:38

greater than 30° then fire the alert

play10:41

let's try to preview again now it's

play10:44

normal previously the query was zero and

play10:47

obviously the data was above zero so if

play10:49

you preview it was firing the alert was

play10:51

in Alert state and now if I made the

play10:53

query is above 30° and preview now the

play10:57

state is normal so first we we defined

play10:59

our data fetch query and then we have

play11:01

defined two expressions which would get

play11:03

a result from the whole data fetched as

play11:06

a single value using the reduce

play11:08

expression maximum of the data and then

play11:11

I'm applying a threshold filter to see

play11:13

whether the data has crossed the

play11:14

threshold just with two expressions I

play11:17

was able to Define my alerting condition

play11:19

in fact people who are using some

play11:20

previous versions of grafana you can

play11:22

create a classic condition Also let's

play11:24

try to delete these two conditions in

play11:26

fact and create a new expression add EX

play11:29

classic condition and here the condition

play11:32

would be a single condition when maximum

play11:35

of a is above 30° the alert should be

play11:39

fired so set this as alerting condition

play11:42

in fact and Now preview now it's firing

play11:44

that means the data would have been

play11:45

greater than 30° and you can see it here

play11:47

the data was 30.9 so that's why it's

play11:50

firing so you can even create a simple

play11:52

classic condition or you can create

play11:54

reduce and threshold conditions in fact

play11:56

let's try to see some more expression

play11:58

possible days I'll just add a new

play12:00

expression and create a math expression

play12:02

and this is useful if you want to create

play12:04

transformation suppose you have two

play12:06

queries and you want to add them so if

play12:07

you have a query a and a query B you can

play12:10

even add them using math expression

play12:12

something like that so that would be for

play12:14

some complex scenarios where you would

play12:17

want to do Transformations on your

play12:19

queries that means you want to do double

play12:21

of your values or you want to subtract

play12:23

two queries or add two queries so for

play12:26

those complex calculations you can use

play12:28

the math expression but for our example

play12:30

it's a simple threshold matching

play12:32

alerting condition so I'm just using a

play12:34

classic condition and I'm saying that if

play12:36

the maximum of the data fetched is above

play12:38

30° just fire an alert let's to prev

play12:41

this

play12:42

again it's still firing because the data

play12:44

is above 30° 30.3 if the data comes

play12:47

below this threshold then it would be

play12:49

normal all right we have defined our

play12:51

alert Rule and the next thing is the

play12:53

evaluation Behavior so this will Define

play12:56

what is the periodicity of evaluating

play12:58

the alerts that means we may Define that

play13:00

check for the alerts for every 1 minute

play13:02

or check for the alerts every 5 minutes

play13:05

so this is the evaluation Behavior so to

play13:07

set an evaluation Behavior you need to

play13:08

have a folder but if you want a new

play13:10

folder you can just click on new folder

play13:12

and enter the name demo folder and click

play13:16

create and now you're using your new

play13:17

folder and to define the periodicity of

play13:19

alert evaluation or alert checking you

play13:22

need to have an evaluation group where

play13:24

you define the alerting checking

play13:26

periodicity so you need to select an

play13:28

evaluation group grou if you don't have

play13:29

any evaluation group just create a new

play13:31

evaluation Group by clicking this button

play13:34

and here enter a name so here I'm going

play13:36

to write something like temperature

play13:37

evaluation group and I want to check

play13:40

every 1 minute so I'm going to make the

play13:42

interval as 1 M so every 1 minute the

play13:45

alerting condition would be checked so

play13:47

create this alerting evaluation group so

play13:50

now all the rules in the selected group

play13:52

would be evaluated every 1 minute and

play13:54

the next thing is a pending period so

play13:56

pending period is basically the am

play13:58

amount of the time for which the alert

play14:00

should be continuously violating that

play14:02

means you can define an alert that if

play14:04

the temperature is continuously

play14:06

violating for 5 minutes at a stretch

play14:08

then only fire an alert so if you want

play14:10

to create a alerting condition something

play14:11

like that then you can use the pending

play14:13

period otherwise you can just make it

play14:15

zero that means whenever an alert is met

play14:18

immediately the alert will be fired if

play14:20

you write pending period something like

play14:21

10 minutes that means if the data is

play14:23

continuously violating for 10 minutes

play14:26

then only alert will be filed so for our

play14:28

example to make it simple let's make the

play14:30

pending period as zero that means as

play14:32

soon as the alert is met the alert will

play14:34

be fired and you can leave this default

play14:36

if there is no data the state would be

play14:38

no data and if the execution error or if

play14:40

there is some timeout you can make the

play14:42

state as error so it's okay to keep this

play14:44

as a default options and then the next

play14:46

step in defining the alerting rule is

play14:47

adding the annotations it's just

play14:49

basically telling the summary of the

play14:51

alerts you can Define it if you want

play14:53

let's TR describe our alert here all

play14:55

right we have described our alert here

play14:57

and then the next important thing is how

play14:59

can you convey your alerts to your

play15:00

notification channels or how can you

play15:02

send an email for your alert that's

play15:04

possible by giving labels to your alerts

play15:07

so let's try to give some labels to our

play15:08

alerts so label is basically a key value

play15:11

pair let's give a label team equal to

play15:14

infra so this is basically the

play15:16

convention generally used you give the

play15:18

tags to your alerts and based upon the

play15:20

tags you can route your alerts to your

play15:22

notification channels suppose if there

play15:24

is an organization and you kept the

play15:26

sensor in the server room and the

play15:28

concern team is the infrastructure

play15:29

maintenance team then I would keep the

play15:31

label team equal to infra so that is the

play15:33

general convention or else you can keep

play15:35

any label you want you can just write

play15:37

some key value pays here and that's it

play15:39

now you defined the rule just try to

play15:41

save the rule and exit and we have saved

play15:43

our rules so we have defined the rule

play15:45

here and you can see already the rule is

play15:47

normal here and the next evaluation

play15:50

period is within the 1 minute that means

play15:52

every 1 minute the rule is going to be

play15:54

evaluated now if you want to pause this

play15:57

rule how can you do that it's really

play15:59

simple actually let's try to see how it

play16:01

can be paused go to the edit button and

play16:04

you can see the editing screen of the

play16:05

rule and in the alert evaluation

play16:09

Behavior you can pause evaluation now

play16:12

save the rule now the rule won't be

play16:14

evaluated that means the rule checking

play16:16

is paused now so if you go to the alert

play16:18

rules if you expand this Sensor One

play16:21

alert this rule is paused now unless you

play16:24

unpause the rule the rule will not be

play16:26

checked so the alert is paused now so we

play16:29

have successfully defined an alert Rule

play16:31

now the next thing is the contact point

play16:33

so I already created a contact Point

play16:34

let's try to delete that let's try to

play16:36

create it again okay we are telling that

play16:39

the contact point is already being used

play16:40

in some policy let's TR go to my

play16:43

notification policy and I want to even

play16:45

delete this policy let's try to delete

play16:46

this notification policy and let's try

play16:48

to go and delete this contact Point all

play16:51

right now let's try to create a fresh

play16:54

contact point so our contact point is

play16:56

going to be an email so let's try to add

play16:58

a contact Point Let's TR to name it as

play17:01

infra team

play17:02

email and the integration would be an

play17:04

email integration and let me try to send

play17:07

the email to my infra team so suppose

play17:11

the email is infra abcd.com so this is

play17:14

my email of the infra team and optional

play17:17

email settings you can send a single

play17:19

email to all the email addresses suppose

play17:21

if I have two email addresses like infra

play17:23

abcd.com and infra 2 abcd.com a single

play17:28

mage message would be sent to these two

play17:30

emails at once and you can give an

play17:32

optional message and that's it it's that

play17:35

simple to create a contact point and

play17:36

then if you want to add one more

play17:38

integration in the same contact point

play17:40

you can do that let's go here and add a

play17:43

contact Point integration so here you

play17:45

can add one more email or you can add

play17:47

something like Discord or whatever so

play17:50

for this example let's make it simple

play17:52

and create just a single email address

play17:54

as one contact point now let's try to

play17:56

save the contact point now let's go to

play17:58

edit this contact point and now you can

play17:59

see all the contact Point details here

play18:01

so we are using an email contact point

play18:03

right so grafana should be able to send

play18:05

an email to this contact point so for

play18:08

that you need to configure grafana to

play18:09

use email in our example we are using

play18:13

Google's email in grafana to send emails

play18:16

so how can you do that so let's try to

play18:18

see how we can configure email in

play18:20

grafana so grafana is installed in my

play18:22

computer so we have a folder called C

play18:25

program files grafana labs grafana conf

play18:28

so in that folder you have defaults ini

play18:30

let's open this default. let's start

play18:33

right click and open with you can use

play18:35

any notepad but I'm using vs code

play18:37

because I'll will get the easy syntax

play18:39

highlighting and here I'm going to

play18:40

search for contrl f

play18:43

SMTP and there's a section called SMTP

play18:46

and this data would be used by grafana

play18:48

to send emails so if you're using Gmail

play18:51

to send emails from grafana the setting

play18:54

should be something like this first make

play18:56

enabled equal to true and and the host

play18:58

would be smtp.gmail.com or any SMTP host

play19:01

you using suppose you have your

play19:03

organization Outlook email you can use

play19:05

those settings but for this example I'm

play19:07

using the Gmail SMTP settings so this

play19:09

would be the same for all Gmail accounts

play19:11

smtp.gmail.com

play19:13

fire7 and here the username would be the

play19:15

Gmail address from which you are sending

play19:17

the Gmail and the password would be the

play19:20

app password let's TR to see how we can

play19:22

create the app password we will see that

play19:24

in a while and you can make skip verify

play19:26

equal to false and from address be the

play19:28

email address which you're using and the

play19:30

from name for example here I'm using

play19:32

grafana but you can use your company's

play19:34

name like Acme it department or

play19:36

something like that so let's try to see

play19:38

how we can get this password so log to

play19:41

your Google and go to

play19:42

accounts.google.com or myac account.

play19:45

goole.com or just click on this and

play19:47

click on your account here and then go

play19:49

to the security

play19:51

Tab and here in the search bar just

play19:53

search for app passwords and here you

play19:56

got this app passwords go here and now I

play19:59

got some app passwords here if you want

play20:01

to create an app password let's try to

play20:03

do it now grafana 2 I'll create a second

play20:06

app password now grafana to

play20:08

create and now I got an app password

play20:10

let's try to copy this copy and done now

play20:15

I got an app password which I can use in

play20:17

my grafana settings so I'll go to this

play20:20

vs code and paste my app password here

play20:24

obviously there should not be spaces

play20:25

remove the spaces and that's it now I

play20:27

can use my Gmail account to send emails

play20:31

now I configured grafana to send emails

play20:34

now let's try to close the defaults

play20:36

let's close this vs code Also let's

play20:39

close our Gmail and now since I've got

play20:41

my SMTP settings right I can test my

play20:44

SMTP so I have created integration right

play20:47

let's say to test this test and send

play20:50

test notification you can see test alert

play20:52

is sent and in my sent email I can see

play20:55

my test notification is sent actually

play20:57

notification test so that's how you can

play20:59

configure gra to send emails and you can

play21:01

configure contact point to send email to

play21:03

a particular email address so till now

play21:05

we have configured an alert rule we have

play21:07

configured a contact point and now you

play21:09

need to connect this alert rule with the

play21:11

contact point right for that you have

play21:12

notification policies so by default

play21:15

notification policy is the default

play21:17

policy which will use the email but I

play21:18

want to create a new policy so click on

play21:20

the new nested policy and remember the

play21:24

label which we have used in our alert Ru

play21:25

let's try to use that here I can write t

play21:28

equal to

play21:30

infra so that was a label I used in my

play21:32

alert so if I use this this policy would

play21:36

be matched with that alert Rule and that

play21:38

alert rule will use this policy to send

play21:41

notifications so the contact point which

play21:43

will be used by this policy is obviously

play21:44

the infr team email and that's it save

play21:48

policy now see this here if there is a

play21:51

label called team equal to infra in your

play21:53

alert rule infra team email contact

play21:56

point would be used so so this way using

play21:58

notification policy I was able to

play22:00

connect my alert rule with a contact

play22:03

point so that's it very easily we have

play22:05

created an alert Rule and we have

play22:07

connected a contact point with the alert

play22:09

rule to notify the changes in Alert

play22:11

state but hey I did not link my alert

play22:14

with the dashboard so that I can overlay

play22:16

the alerts of my alert rules on the

play22:18

dashboard right for example let's go to

play22:21

a dashboard dashboards and my sample

play22:23

dashboard I'm not able to see any Alert

play22:26

state here right so how can I link my

play22:28

alert rule with this dashboard panel how

play22:30

can I do that let's go to our alert

play22:33

rules alerting alert rules and in the

play22:36

demo folder this was my alert rule right

play22:39

let's go to edit this alert Rule and

play22:41

here there is a provision to link your

play22:44

alert tool with the dashboard in the

play22:46

section add annotations which is the

play22:48

fourth section you can see link

play22:50

dashboard and panel let's click on this

play22:53

and select the dashboard our dashboard

play22:54

was Sample dashboard and there is one

play22:57

panel and that panel is shown here click

play22:59

on this panel

play23:00

confirm now the dashboard panel is

play23:03

linked with this alert rule save this

play23:05

Rule and exit and now let's go to the

play23:07

dashboards let's go to our sample

play23:09

dashboard now you can see the Alert

play23:11

state here being

play23:13

shown in fact let's try to expand this

play23:16

and let's try to make the alert

play23:17

threshold very less so that we can see

play23:19

the alert here actually so let's try to

play23:22

save this dashboard

play23:23

again and now let's TR to change our

play23:25

alert rule let's go to alerts

play23:28

and alert rules let's try to make the

play23:30

threshold very less so that the alert

play23:32

will be triggered let's try to click on

play23:34

edit in fact let's try to unpause our

play23:36

alert so evaluation will go on pause

play23:38

evaluation will be removed and then we

play23:41

are evaluating every 1 minute right but

play23:43

for this demo let's evaluate every 10

play23:45

seconds click on this edit and here

play23:47

instead of 1 minute 10 seconds save and

play23:51

then in the alert rule in the threshold

play23:54

let's make it above something like 15°

play23:56

so that it will F defin Ely preview

play23:59

this it's firing let's try to save the

play24:02

rule and now let's go to the dashboards

play24:05

dashboard sample dashboard and now

play24:08

within 10 seconds you should see an

play24:10

alert here because the threshold is just

play24:12

15° let's try to reload now you got an

play24:15

alert saying that the alert has crossed

play24:17

the threshold and if you H over this you

play24:21

can see Sensor One alert and the value

play24:23

is

play24:24

30.93 so this way you can overlay your

play24:26

alerts on your existing panels and now

play24:29

let's tryy to make the threshold up

play24:31

again so that the alert would be coming

play24:33

to normal state so again let's go to the

play24:36

alerts alert rules and let's go to our

play24:39

alert rule edit this sorry it's

play24:42

evaluation group expand this and go to

play24:44

this alert edit and here let's say to

play24:47

make the condition above

play24:49

30° preview it's firing still because

play24:52

the value is greater than 30 let's make

play24:53

it

play24:54

35 and let's set a preview this now now

play24:57

it's normal save the rule and exit and

play25:00

now let's go to the

play25:02

dashboards sample dashboard and now

play25:05

let's start to wait for 10 seconds

play25:07

refresh this again and now you are in

play25:09

the okay state so this way as the alert

play25:11

rule evaluation goes on if there is some

play25:13

kind of violation in the threshold or if

play25:16

it's again less than the threshold the

play25:17

Alert state would be changing and for

play25:19

each alert change you should get a

play25:21

notification let's go to our Gmail and

play25:24

if you see the sent mail you can see

play25:26

there's a firing alert which is

play25:27

notifying that the alert has filed so

play25:30

this way you can even send notifications

play25:32

if there are alert violations so the

play25:34

alert is still not greater than 35° so

play25:37

the alert is still okay in state so if

play25:39

the temperature crosses 35° then again

play25:41

there will be something like an alerting

play25:43

State all right let's go to our alert

play25:45

rules and let's try to change the alert

play25:47

evaluation for every 1 minute instead of

play25:49

10 seconds so let's go to the alerts

play25:52

edit it and make the evaluation Behavior

play25:55

as 1 minute instead of 10 seconds so

play25:57

click on this edit button and instead of

play25:59

10 seconds make it something like 10

play26:01

minutes so every 10 minutes the

play26:03

temperature will be evaluated and now if

play26:05

you want to see the state history at

play26:07

what times the alert was filed let's go

play26:09

to the alert rules and if you expand

play26:11

this alert you can see something like a

play26:13

state history click on show State

play26:15

history and this is the state history so

play26:18

now if the alert goes from normal to

play26:20

alerting you will see a new entry here

play26:23

so this way you can see at what time the

play26:24

thresholds were violated and at what

play26:27

time the Val Has Come Again below the

play26:29

threshold so you can see the transition

play26:31

of the alert States using the state

play26:32

history so that's it guys let's go to a

play26:35

dashboard sample dashboard and this is

play26:39

how you can see your alerts in grafana

play26:42

now this way you can configure multiple

play26:43

alerts in grafana and you can get

play26:45

multiple notifications you can group

play26:47

your alerts and do a lot of convenient

play26:49

alerting so this was a simple example of

play26:53

how to create and manage alerts in

play26:54

grafana you can see I've created a blog

play26:56

post on creating and managing alerts in

play26:59

grafana I've given you the notes and

play27:01

I've also given you the configuration

play27:03

screen so that you can easily configure

play27:05

alerts in grafana for your own use cases

play27:08

I've also given you the link to the

play27:09

official demo video you can even go

play27:11

through this if you want to know more or

play27:13

if you want to get to know in depth

play27:15

about alerting in grafana but in our

play27:17

video we have just covered how to very

play27:19

easily set up alerts in grafana so

play27:21

please be sure to check out the link of

play27:22

this blog post in the description of

play27:24

this video please ask questions or post

play27:26

your valuable feedback in the comment

play27:28

section hope you like this video guys

play27:30

thank you for watching peace

Rate This

5.0 / 5 (0 votes)

相关标签
GrafanaAlertingDashboardPostgreSQLReal-timeMonitoringAnalyticsData VisualizationNotification PolicyAlert Rules
您是否需要英文摘要?