Prometheus Learning Series (xiv) the configuration rules

First, the configuration rules

Prometheus supports two types of rules that can be configured on a regular basis, and regular assessment: Record rules and alert rule . Prometheus to be included in the rules, create a file that contains the necessary rules for the statement, and let Prometheus Prometheus configuration by rule_filesloading a file field. Rules file using YAML.

By SIGHUPsending to the Prometheus process, you can reload the rules file at run time. It will apply the change only when all the rules file in the correct format.

Second, syntax checking rules

To quickly check whether a file is syntactically correct rules without starting Prometheus server, install and run the Prometheus of the promtoolcommand-line utility:

go get github.com/prometheus/prometheus/cmd/promtool
promtool check rules /path/to/example.rules.yml
复制代码

When the file is valid in the syntax checker parsed textual representation of the rule printed to standard output, and then 0return to the state exit.

If there are any syntax errors or invalid input parameters, an error message is output to standard error, and to 1return to the state exit.

Third, the recording rule

Record rules allow you to pre-calculate frequently require computationally expensive or expression, and save the result as a new set of time series. Therefore, the results of pre-computed query execution usually much faster than the original expression every time you need. This is especially useful for instrument panels, instrument panels need to repeat the same query expression on every refresh.

Record and alert rule exists in the rule group. Set of operating rules in order at fixed intervals.

Rules file syntax is:

groups:
  [ - <rule_group> ]
复制代码

A simple example would be the rules file:

groups:
  - name: example
    rules:
    - record: job:http_inprogress_requests:sum
      expr: sum(http_inprogress_requests) by (job)
复制代码
3.1 <rule_group>
# 组的名称。 在文件中必须是唯一的。
name: <string>

# 评估组中的规则的频率。
[ interval: <duration> | default = global.evaluation_interval ]

rules:
  [ - <rule> ... ]
复制代码
3.2 <rule>

Record rule syntax is:

# 要输出的时间序列的名称。 必须是有效的度量标准名称。
record: <string>

# 要评估的PromQL表达式。 每个评估周期都会在当前时间进行评估,并将结果记录为一组新的时间序列,其中度量标准名称由“记录”给出。
expr: <string>

# 在存储结果之前添加或覆盖的标签。
labels:
  [ <labelname>: <labelvalue> ]
复制代码

Alert rule syntax is:

# 警报的名称。 必须是有效的度量标准名称。
alert: <string>

# 要评估的PromQL表达式。 每个评估周期都会在当前时间进行评估,并且所有结果时间序列都会成为待处理/触发警报。
expr: <string>

# 警报一旦被退回这段时间就会被视为开启。
# 尚未解雇的警报被认为是未决的。
[ for: <duration> | default = 0s ]

# 为每个警报添加或覆盖的标签。
labels:
  [ <labelname>: <tmpl_string> ]

# 要添加到每个警报的注释。
annotations:
  [ <labelname>: <tmpl_string> ]
复制代码
Fourth, the link

Prometheus official website address: prometheus.io/

My Github: github.com/Alrights/pr...

Reproduced in: https: //juejin.im/post/5d04ab95e51d455a694f9517

Guess you like

Origin blog.csdn.net/weixin_33816300/article/details/93182136