Grafana告警推送至钉钉教程
📌 环境确认
Grafana
v12.4.0(内置dingtalkContact Point插件),国内和国外的Grafana都是这个版本钉钉群
自定义机器人权限Grafana 服务器可访问
oapi.dingtalk.com:443
第一步:创建钉钉自定义机器人
钉钉群 →
⚙️ 群设置→智能群助手→添加机器人→自定义
命名:按照用途命名
安全设置(必需三选一)
✅ 加签(推荐):复制
Secret(SECxxxxxxxx)🔑 自定义关键词:添加
Grafana告警或监控🌐 IP 白名单:填写 Grafana 服务器出口 IP

点击
完成,完整复制 Webhook URL(https://oapi.dingtalk.com/robot/send?access_token=xxx)
第二步:Grafana 配置钉钉联系方式(Contact Point)
左侧菜单
Alerting→Contact points点击
+ Create contact point填写字段(v12.4.0 界面):
点击底部
Test钉钉收到
✅ Test notification from Grafana→ 成功报错
403→ 检查关键词/加签/白名单报错
400→ 检查 URL 是否完整或含空格
点击
Save contact point
第三步:配置通知策略(Notification Policy)
Alerting→Notification policies根策略右侧点击
⋯→Add policy配置路由规则:
Matchers:env = xxx(与告警规则 Labels 对应)Contact point:选择上一步刚刚创建的Contact pointOverride general timings:勾选Group wait:30sGroup interval:5mRepeat interval:1hMute timing:按需绑定(如维护窗口)
点击
Save policy/Update policy
第四步:创建告警规则(Alert Rule)
Alerting→Alert rules→+ Create alert ruleStep 1: Query & Transform
选择数据源(如
Prometheus)编写查询,点击
Run queries验证返回结果
100 * ( sum(rate(container_cpu_usage_seconds_total{image!=""}[5m])) by (pod, namespace, container) / sum(kube_pod_container_resource_limits{resource="cpu"}) by (pod, namespace, container) ) sum(kafka_consumergroup_lag{consumergroup!~"anonymous.*|amazon.*|.*([0-9]{1,3}\\.){3}[0-9]{1,3}.*"}) by (consumergroup, topic, namespace, instance) > 50000Step 2: Set conditions
选择评估字段(如
A)设置阈值:
IS ABOVE 60或IS ABOVE 50000点击
Preview alert rule condition可以查看查询结果
Step 3: Add folder and labels
Folder 选择之前建好的
Labels:添加env = kafka 或者 env = cpu(必须与策略 Matchers 一致)
Step 4: Evaluation
Evaluation group and interval:新建一个Pending period:5m(持续满足条件 5 分钟才触发,防网络抖动)Keep firing for:5m
Step 5: Configure notifications
确认
Contact point是之前创建的
点击
Save
第五步:测试
验证路径
手动制造触发条件(如临时调低阈值)
Alerting→Alert instances查看状态:Normal→Pending→Firing钉钉群收到卡片
指标恢复后,状态变为
Resolved,钉钉推送恢复通知