Ubuntu 20.04
Sponsored Link

Prometheus : インストール2020/09/07

 
監視システム Prometheus をインストールして設定します。
Prometheus サーバーから監視対象ノードにアクセスしてデータを取得する Pull 型のアーキテクチャーを採用しています。 また、外部データベースは不要で Prometheus サーバー上に時系列データが保存されます。
Prometheus のアーキテクチャー概要は公式サイトを参照ください。
⇒ https://prometheus.io/docs/introduction/overview/
[1] Prometheus サーバー、および CPU やメモリーなどの一般的なシステムリソースのデータを取得する [node-exporter] をインストールします。
root@dlp:~#
apt -y install prometheus prometheus-node-exporter
[2] 基本的な設定は [prometheus.yml] で実施します。
# 基本的な設定は下記ファイルで実施

# 変更なしのデフォルト状態でも [Prometheus] 関連の統計情報は取得される

root@dlp:~#
vi /etc/prometheus/prometheus.yml
# Sample config for Prometheus.

global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'example'

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets: ['localhost:9093']

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s
    scrape_timeout: 5s

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['localhost:9090']

  - job_name: node
    # If prometheus-node-exporter is installed, grab stats about the local
    # machine by default.
    static_configs:
      - targets: ['localhost:9100']

root@dlp:~#
systemctl enable prometheus prometheus-node-exporter
[3] 任意のクライアントホストで Web ブラウザーを起動し、[http://(サーバーのホスト名 または IPアドレス):9090/] へアクセスします。 すると、Prometheus Web UI の画面が表示されます。
[4]
[insert metric at cursor] をクリックすると、保存された時系列データが参照可能な様々なクエリーが用意されています。 クエリーは上部の入力フィールドから直接記述することも可能で、Prometheus 独自の [Expression Language] 機能です。
Expression Language の使用例は公式サイトを参照ください。
⇒ https://prometheus.io/docs/querying/examples/
[5] [node-exporter] で取得した [node_procs_running] のデータを表示した様子です。
[6] [Status] - [Targets] をクリックすると、各ノードのステータスが確認できます。
関連コンテンツ