Netdata + Server酱:服务器指标告警推送到微信
效果:Netdata 监控到 CPU/内存/磁盘等指标告警时推送到微信
前置条件
- 获取 Server酱 SendKey(30 秒获取教程)
- 已安装并运行 Netdata 服务
配置步骤
在 Netdata 所在服务器编辑 health_alarm_notify.conf,找到 custom_sender() 函数,填入以下 curl 命令:
curl -sS -X POST "https://sctapi.ftqq.com/你的SENDKEY.send" \
--data-urlencode "title=Netdata告警 ${name}" \
--data-urlencode "desp=${chart} 状态 ${status}"
如果使用 Server酱³,端点替换为 https://你的UID.push.ft07.com/send/你的SENDKEY.send(UID 取自 sctp 后的数字)。
- 确保系统已安装 curl。
- 在
health_alarm_notify.conf中启用 custom 通知(具体配置项以应用内实际显示为准)。 - 将上述 curl 命令写入
custom_sender()函数内,Netdata 会将${name}、${chart}、${status}等告警变量自动替换为实际值。 - 在角色路由配置里,把
custom加入需要接收告警的角色列表中。 - 保存配置并重启 Netdata 使其生效。
完整示例
以下为 custom_sender() 函数的完整写法,可直接替换到 health_alarm_notify.conf 中:
custom_sender() {
curl -sS -X POST "https://sctapi.ftqq.com/你的SENDKEY.send" \
--data-urlencode "title=Netdata告警 ${name}" \
--data-urlencode "desp=${chart} 状态 ${status}"
return 0
}
常见问题
Server酱的发送额度是多少? 免费用户每日可发送 5 条消息,订阅会员目前特价最低 3 元/月,一天最多可发 1000 条(价格详情)。
配置后没有收到告警消息怎么办?
请先检查 health_alarm_notify.conf 中 custom 通知是否启用、角色路由是否包含 custom,并参考常见问题与排查检查 SendKey 与网络。
发送频率有限制吗? 有,每分钟发送上限为 50 条,订阅会员每日 API 请求上限为 1000。