Grafana从4.0开始新增预警功能,下面简单介绍一下。Grafana告警设置分为两部分:

  1. Notification配置
  2. Alert配置

1、Notification配置:其实就是配置告警途径,Grafana支持多种方式的告警:Email、webhook等。由于webhook比较通用,我们重点说下如何配置webhook。

grafana alert报警功能介绍_数据结构


之后点击New Channel进入配置页面: 


grafana alert报警功能介绍_grafana_02


保存后即可。 2、alert配置: 1)进入dashboards,选择一个pannel,然后edit,进入alert选项卡,添加alert配置。

grafana alert报警功能介绍_grafana_03

在alert config页面设置报警阈值,和报警条件等。 2)设置notification: grafana alert报警功能介绍_grafana_04

然后再notification页面设置上一步配置的notification,以及报警信息。

3、编写webhook接口: 1)grafana发送的数据结构如下:

{
"ruleName": "webhooktest",
"state": "alerting",
"message": "This is my webhook send test ,my target is to get the alert data.",
"ruleId": 4,
"title": "[Alerting] webhooktest",
"ruleUrl": "http://localhost:3000/dashboard/db/webhookdatatest?fullscreen&edit&tab=alert&panelId=1&orgId=1",
"evalMatches": [
{
"metric": "mytest.age { myName: pangkun2 }",
"value": 27,
"tags": null
},
{
"metric": "mytest.age { myName: pangkun3 }",
"value": 26,
"tags": null
}
]
}

2)在接口中,可以通过request.getparamater("key")来获取上面结构中的数据