简介
Grafana是一款用Go语言开发的开源数据可视化工具,可以做数据监控和数据统计,带有告警功能。目前使用grafana的公司有很多,如paypal、ebay、intel等。
功能说明
告警通知
开启告警
grafana只有graph支持告警通知。grafana的告警通知渠道有很多种,像Email、Teams、钉钉等都有支持。
在grafana.ini中开启告警:
#################################### Alerting ############################
[alerting]
# Disable alerting engine & UI features
enabled = true #开启
# Makes it possible to turn off alert rule execution but alerting UI is visible
execute_alerts = true #开启
# Default setting for new alert rules. Defaults to categorize error and timeouts as alerting. (alerting, keep_state)
;error_or_timeout = alerting
# Default setting for how Grafana handles nodata or null values in alerting. (alerting, no_data, keep_state, ok)
;nodata_or_nullvalues = no_data
# Alert notifications can include images, but rendering many images at the same time can overload the server
# This limit will protect the server from render overloading and make sure notifications are sent out quickly
;concurrent_render_limit = 5
邮件通知
STMP服务器配置
要能发送邮件通知,首先需要在配置文件grafana.ini中配置邮件服务器等信息:
#################################### SMTP / Emailing ##########################
[smtp]
enabled = true #是否允许开启
host = #发送服务器地址,可以再邮箱的配置教程中找到:
user = 你的邮箱
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
password = 这个密码是你开启smtp服务生成的密码
;cert_file =
;key_file =
skip_verify = true
from_address = 你的邮箱
from_name = Grafana
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com
[emails]
;welcome_email_on_sign_up = false
例子:
#################################### SMTP / Emailing #####################
[smtp]
enabled = true
host = smtp.163.com:25
user = 495804928@163.com
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = **********
cert_file =
key_file =
skip_verify = true
from_address = 495804928@163.com
from_name = Grafana
ehlo_identity = 163.com
修改完配置,记得重启Grafana服务
具体配置
具体邮件和钉钉配置可以参考:
https://yq.aliyun.com/articles/255169
重点注意
1.怎么解决Template variables are not supported in alert queries?
由于Prometheus告警不支持变量,我们怎么在有大量变量的面板中对监控指标进行告警呢,具体步骤如下:
1.我们需要在该面板Queries中添加一个没有变量的Query,如图中C就没法用于监控,D才能用于监控,因为C有变量。
2.然后设置成Disable query这样图表中就不会有该指标数据,图中标记的部分。

3.然后在面板的Alert中选择该Query用于监控即可,如图中query(D,15s,now),多说一句,图中Evaluate every是检查告警的周期,检查到异常会变黄,如果在For配置的时间内还没有恢复就会变红,然后触发告警了。

注意:一定要给监控指标配置Legend,如果直接钉钉直接发送process_cpu_usage{application="server2",instance="localhost:9754",job="server2"}这样的可能会提示字符问题,建议Legend定义为例如:应用:{{application}},实例: {{instance}},在告警信息就能知道那个应用的那个实例有问题。
网友评论