概要
Prometheusでalert設定をしようとしてなぜか、起動時にformatエラーになるので調べてみると、v1.xとv2.xでは記法が変わっていたのでメモ。
versionごとの記法
- v1.xの記法
instance.rules
ALERT InstanceDown
IF 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.",
}
- v2.xの記法
instance.rules.yaml
groups:
- name: instance.rules
rules:
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: page
annotations:
description: '{{$labels.instance}} of job {{$labels.job}} has been down for
more than 5 minutes.'
summary: Instance {{$labels.instance}} down
なんとyamlに変わっていました。
変換方法
こちらのサイトに記載がありますが、下記でformatをチェックするpromtoolがインストールできます。
$ go get github.com/prometheus/prometheus/cmd/promtool
このtoolを使って、v1形式のファイルをv2形式に変換できます。
$ promtool update rules instance.rules
実行後、 instance.rules.yml
というファイルが出来上がります.