amtool --alertmanager.url=http://localhost:9093 alert severity=warning
groups:
- name: example
rules:
- record: job:http_inprogress_requests:sum
expr: sum(http_inprogress_requests) bysc (job)
histogram_quantile(0.9, rate(employee_age_bucket_bucket[10m]))
最近10分钟之内90%的样本的最大值。例如过去10分钟的样本数据:
[1, 1, ... 1, 1, 1, 50, 50] // 共100条数据,p99=50 p90=1
histogram_quantile对histogram类型是在服务器端计算,而对sumamry是在客户端计算,即通过promql计算分位数试,summary有更好的性能。
predict_linear(node_filesystem_free{job="node"}[1h], 4 * 3600)
以当前1个小时的指标数据,预测4小时后系统磁盘空间的剩余情况。
delta(cpu_temp_celsius{host="zeus"}[2h])
cpu温度在2个小时之间的差异。
topk(10, http_requests_total)
increase(kube_pod_container_status_restarts_total[2m])
increase(kube_pod_container_status_restarts_total[2m]) / 120 // rate(kube_pod_container_status_restarts_total[2m])
表示取15分钟内的样本数据,按每分钟分为1断,例如max_over_time(kube_pod_container_status_restarts_total{namespace=”ansible-automation-platform”}[15m:1m])
rate(http_requests_total[5m])
例如过去5分钟样本值是:[1, 2, 3, 10, 31],则rate(http_requests_total[5m])为(31 - 1)/(5*60) = 0.1,即平均每秒钟增长0.1,300秒钟增加了30次(31-1),rate一般用于counter类指标。和聚合相关函数使用时,先调用rate,否则rate不知道计数器是否被重置。
amtool --alertmanager.url=http://localhost:9093 silence
amtool check-config alert.yaml
curl -d '[{"labels": {"Alertname": "Test"}}]' http://localhost:9093/api/v1/alerts
- source_match:
alertname: ClusterDown
severity: critical
target_match:
severity: critical
equal:
- cluster
如果收到ClusterDown的alert且severity是critical。那么当有新的alert且severity是critical,如果新的alert中的cluster的值和ClusterDown中的相同,则启动抑制停止发送新的alert。
send_resolved: true
match // alert按标签完全匹配
match_re // alert按标签正则匹配
routes:
- matchers:
- severity =~ "warning|critical"
- alertname !~ "Watchdog|UpdateAvailable|ViolatedPolicyReport|AlertmanagerReceiversNotConfigured"
receiver: default-receiver
receivers:
- name: default-receiver
slack_configs:
- channel: alerts
http_config:
proxy_url: http://proxy.com:1234
group_by: ['alertname', 'cluster', 'service'] // 具有这些标签的alerts被分为一个组,聚合多条alerts成一条alert发送
group_by: [...] // 禁用分组
如果按一下配置,alert触发后,一个分组被创建,会等待5分钟才会发送给receiver,然后每隔2分钟检查group中的alert状态,如果有新的alert,则发送给receiver,如果没有新的alert,后续就会每隔6分钟发送一次alert,因为每个2分钟检查一次alert状态,检查2次alert状态才4分钟,没有大于repeat_interval,所以经过3次检查后,6分钟发送一次重复的alert。
group_wait: 5m
group_interval: 2m
repeat_interval: 4m
continue: false // 匹配到就发送
continue: true // 继续匹配子路由,alert会被发送到多个receiver
https://awesome-prometheus-alerts.grep.to/rules.html
https://relabeler.promlabs.com/
amtool: error: failed to validate 1 file(s) ```
absent(up{job="kube-controller-manager"} == 1)
:) 未完待续……
LEo at 00:12