7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Prometheus.ymlの記述内容を解説する

Last updated at Posted at 2019-10-28

はじめに

Prometheus関連の記事は触りやとりあえず動かす!という程度の情報はネットで拾えますが、ファイル単位での解説記事は目にする機会がそう多くありませんでした。
タイトルの通り、Prometheusで最初に設定するprometheus.ymlファイルの記述内容について、『どんなことが書いてあるか』を記事にしました。

誤りがございましたらご指摘頂けたら幸いです。

尚、本記事の記述内容はLinux向けprometheus ver.2.13.1となります。

prometheus.ymlファイルの中身

まずはprometheus.ymlの中身です。
設定項目ごとに左側の行数単位で解説していきます。

prometheus.yml

1 # my global config
2 global:
3  scrape_interval:     15s 
  # Set the scrape interval to every 15 seconds. Default is every 1 minute.
4  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
5  # scrape_timeout is set to the global default (10s).
6
7 # Alertmanager configuration
8 alerting:
9   alertmanagers:
10   - static_configs:
11     - targets:
12       # - alertmanager:9093
13 
14  # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
15  rule_files:
16   # - "first_rules.yml"
17   # - "second_rules.yml"
18 
19  # A scrape configuration containing exactly one endpoint to scrape:
20  # Here it's Prometheus itself.
21  scrape_configs:
22   # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
23   - job_name: 'prometheus'
24 
25     # metrics_path defaults to '/metrics'
26     # scheme defaults to 'http'.
27 
28     static_configs:
29     - targets: ['localhost:9090'] 


全体設定 (1~5行目)

全体設定.yml
1 # my global config
<<訳>> 全体設定 メトリクス取得の周期等を設定する
   
2 global:
3  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
<<訳>>データ取得間隔           # スクレイプ(データ取得)間隔を設定します。デフォルトは1分毎です 

4  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
<<訳>>評価間隔(直訳)           # Prometheusはアラーティングルールとアラートの状態を取得し、ヘルスチェックを実施します。これは、その間隔を設定する項目。

5  # scrape_timeout is set to the global default (10s).
<<筆者挿入(公式から引用)>> [ scrape_timeout: <duration> | default = 10s ] #スクレイプのタイムアウト時間を設定します。デフォルト10秒。

アラートマネージャの設定 (7~12行目)

alertmanager_config.yml
7 # Alertmanager configuration
   # Alertmanagerの設定項目。
<<解説>> Prometheusサーバがアラート送信(push)するAlertmanagerインスタンスを指定します。
         また、Alertmanagerとの通信方法を設定するためのパラメータ設定も行えます。
         Alertmanagerはstatic_configsで静的に設定することも、サポートされている
         service検出メカニズムを使用して動的に検出することもできます。
         

8 alerting:
9   alertmanagers:
10   - static_configs:
11     - targets:
12       # - alertmanager:9093
<<解説>> デフォルトのAlertmanagerにpushする場合は上記のalertmanagerをコメントアウトすればOK

アラーティングルールの設定(14~17行目)

alerting_rule関連.yml
14  # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
<<訳>>globalで設定したevaluation_intervalに従って定期的に評価する。
<<解説>>Prometheusが取得したメトリクスに対する評価のルール設定ファイルを指定します。
        先に設定したevaluation_intervalの取得間隔で参照するファイルとなります。
        また、本ファイルがymlなので、記述順にルールの重みづけがされます。
15  rule_files:
16   # - "first_rules.yml"
17   # - "second_rules.yml"

監視対象の設定(19~29行目)

監視設定.yml
19  # A scrape configuration containing exactly one endpoint to scrape:
20  # Here it's Prometheus itself.

21  scrape_configs:
22   # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
23   - job_name: 'prometheus'
24 
25     # metrics_path defaults to '/metrics'
26     # scheme defaults to 'http'.
27 
28     static_configs:
29     - targets: ['localhost:9090'] 

<<解説>>targets: Prometheus が情報を取得する対象のホスト名もしくはIPアドレスと、ポート番号を設定する
        主な設定対象はexporter。

引用

入門 Prometheus (オライリージャパン)

Prometheus公式ドキュメント Configuration

・[Prometheus: understanding the delays on alerting]
(https://pracucci.com/prometheus-understanding-the-delays-on-alerting.html)

7
8
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
7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?