prometheusの記録規則(recording rules)とアラーム規則(alerting rule)
Prometheusでは、レコード・ルールとアラート・ルールの2種類のルールがサポートされています.Prometheusにルールを含めるには、必要なルール文を含むファイルを作成し、Prometheus構成の
構文チェック・ルールPrometheusプロセスを開始せずに、ルール・ファイルが構文上正しいかどうかをすばやくチェックするには、Prometheusのpromtoolコマンド・ライン・ツールをインストールして実行します.
使用例
ルール構文:
例
アラームルールの構文は次のとおりです.
アラームルールの例
rule_files
フィールドからルールファイルをロードします.SIGHUP
をPrometheusプロセスに送信することで、実行時にルールファイルを再ロードできます.これらの変更は、すべてのルール・ファイルのフォーマットが良好な場合にのみ適用されます.構文チェック・ルールPrometheusプロセスを開始せずに、ルール・ファイルが構文上正しいかどうかをすばやくチェックするには、Prometheusのpromtoolコマンド・ライン・ツールをインストールして実行します.
go get github.com/prometheus/prometheus/cmd/promtool
使用例
[root@fabric-cli prometheus-2.2.1.linux-amd64]# ls -l
108104
drwxrwxr-x 2 1000 1000 38 3 14 22:14 console_libraries
drwxrwxr-x 2 1000 1000 173 3 14 22:14 consoles
drwxr-xr-x 5 root root 85 5 12 00:05 data
-rw-rw-r-- 1 1000 1000 11357 3 14 22:14 LICENSE
-rw-rw-r-- 1 1000 1000 2769 3 14 22:14 NOTICE
-rwxr-xr-x 1 1000 1000 66176282 3 14 22:17 prometheus
-rw-r--r-- 1 root root 167 5 4 10:47 prometheus.rules.yml
-rw-rw-r-- 1 1000 1000 879 5 4 10:49 prometheus.yml
-rwxr-xr-x 1 1000 1000 44492910 3 14 22:18 promtool
[root@fabric-cli prometheus-2.2.1.linux-amd64]# ./promtool check rules prometheus.rules.yml
Checking prometheus.rules.yml
SUCCESS: 1 rules found
ルール構文:
groups:
[ - ]
#
name: <string>
#
[ interval: | default = global.evaluation_interval ]
rules:
[ - ... ]
#
record: <string>
#
# evaluated at the current time, and the result recorded as a new set of
# time series with the metric name as given by 'record'.
expr: <string>
# Labels to add or overwrite before storing the result.
labels:
[ : ]
例
groups:
- name: example
rules:
- record: job:http_inprogress_requests:sum
expr: sum(http_inprogress_requests) by (job)
アラームルールの構文は次のとおりです.
# The name of the alert. Must be a valid metric name.
alert: <string>
# The PromQL expression to evaluate. Every evaluation cycle this is
# evaluated at the current time, and all resultant time series become
# pending/firing alerts.
expr: <string>
# Alerts are considered firing once they have been returned for this long.
# Alerts which have not yet fired for long enough are considered pending.
[ for: | default = 0s ]
# Labels to add or overwrite for each alert.
labels:
[ : ]
# Annotations to add to each alert.
annotations:
[ : ]
アラームルールの例
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: 10m
は、10分以上でサービスにアクセスできないことを示すアラームリファレンスrecording_rules alerting_rules