Prometheus: 配置 Prometheus 警报规则
本文档属于警报指南的一部分。您可以在此处查看完整指南:Prometheus 警报的工作原理及其配置方法。
👋 欢迎查阅 Stackhero 文档!
Stackhero 提供了一个完全托管的 Prometheus cloud 平台,专为高可靠性与简便性设计:
- 内置
Alert Manager,可将告警直接发送到Slack、Mattermost、PagerDuty及其他主流平台。- 配备专用邮件服务器,支持发送无限量邮件告警,无需额外配置。
- 集成
Blackbox,可对HTTP、ICMP、TCP等协议进行探测,实现全面监控。- 通过在线配置文件编辑器,快速完成实例配置,无需手动管理 YAML 文件。
- 一键升级,Stackhero 自动为您处理升级流程,最大限度减少停机和人工干预。
- 依托专属私有基础设施,内置高性能与强大安全性。
大约 5 分钟即可完成部署。Stackhero 负责所有初始化设置,让您专注于监控本身,无需为维护分心。欢迎体验 Stackhero 的 Prometheus cloud hosting,让您的监控与告警流程更加高效便捷。
您可以通过编辑 rules-alert.yml 文件来调整 Prometheus 警报规则。为此,请访问您的 Stackhero 仪表板,选择您的 Prometheus 服务,然后点击“Prometheus 警报规则配置”。
我们已经在您的 Stackhero for Prometheus 实例中添加了一些默认警报规则,因此通常不需要修改 rules-alert.yml 文件,除非需要自定义。
以下是一个示例,当磁盘使用率超过 90% 时触发警报:
- alert: "HostOutOfDiskSpace"
expr: (node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes < 10 and ON (instance, device, mountpoint) node_filesystem_readonly == 0
for: 2m
labels:
severity: "warning"
annotations:
summary: "Host out of disk space (instance {{ $labels.instance }})"
description: "Disk is almost full (< 10% left)"
value: "{{ $value }}"
这是另一个示例,预测未来 24 小时内磁盘空间可能饱和:
- alert: "HostDiskWillFillIn24Hours"
expr: (node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes < 10 and ON (instance, device, mountpoint) predict_linear(node_filesystem_avail_bytes{fstype!~"tmpfs"}[1h], 24 * 3600) < 0 and ON (instance, device, mountpoint) node_filesystem_readonly == 0
for: 2m
labels:
severity: "warning"
annotations:
summary: "Host disk will fill in 24 hours (instance {{ $labels.instance }})"
description: "Filesystem is predicted to run out of space within the next 24 hours at the current write rate"
value: "{{ $value }}"
您可以在 Awesome Prometheus Alerts 网站上找到更多警报规则示例。