LoginSignup
1
2

More than 5 years have passed since last update.

PrometheusのAlerting rulesをv1.xからv2.x用に書き換える

Posted at

概要

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 というファイルが出来上がります.

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2