• 欢迎来到小爱博客,一个分享互联网IT技术的网站,喜欢就收藏吧!

prometheus rules配置

prometheus 小爱 3个月前 (07-31) 43次浏览 已收录 0个评论 扫描二维码

支持两种rules。

recording rules

alerting rules

编辑后不需要重启prometheus验证语法,通过promtool工具:

go get github.com/prometheus/prometheus/cmd/promtool
promtool check rules /path/to/example.rules.yml
Recording rules
对采集的metric最计算或聚合,生成新的metric

groups:
– name: example
rules:
– record: job:http_inprogress_requests:sum
expr: sum(http_inprogress_requests) by (job)
Alerting rules
可以通过表达式定义报警规则。报警规则的配置和recording rules一样。

groups:
– name: example
rules:
– alert: HighErrorRate
expr: job:request_latency_seconds:mean5m{job=”myjob”} > 0.5
for: 10m
labels:
severity: page
annotations:
summary: High request latency
for:第一次判断前的等待时间

labels: 会被添加到告警中

annotations:存一些告警信息到补充和描述

模版
labels和annotations可以采用模版变量。

用法:

# To insert a firing element’s label values:
{{ $labels.<labelname> }}
# To insert the numeric expression value of the firing element:
{{ $value }}
例子:

groups:
– name: example
rules:

# Alert for any instance that is unreachable for >5 minutes.
– alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: page
annotations:
summary: “Instance {{ $labels.instance }} down”
description: “{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.”

# Alert for any instance that has a median request latency >1s.
– alert: APIHighRequestLatency
expr: api_http_request_latencies_second{quantile=”0.5″} > 1
for: 10m
annotations:
summary: “High request latency on {{ $labels.instance }}”
description: “{{ $labels.instance }} has a median request latency above 1s (current value: {{ $value }}s)”
alert: InstanceDown
expr: up == 0
for: 5m
labels:
– severity: page
annotations:
summary: “Instance {{$labels.instance}} down”
description: “{{$labels.instance}} of job {{$labels.job}} has been down for more than 5 minutes.”
带循环的

{{ range query “up” }}
{{ .Labels.instance }} {{ .Value }}
{{ end }}


小爱博客 , 版权所有
转载请注明原文链接:prometheus rules配置
喜欢 (1)
【你的支持, 我的动力】
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址