Node Exporter を使用した Linux ホストメトリクスの監視

Prometheus のNode Exporterは、ハードウェアおよびカーネル関連の様々なメトリックを公開します。

このガイドでは、以下のことを行います。

  • `localhost` で Node Exporter を起動する
  • 実行中の Node Exporter からメトリックをスクレイプするように設定された Prometheus インスタンスを `localhost` で起動する
注: Prometheus Node Exporter は *nix システム用ですが、Windows 用のWindows exporterもあり、同様の目的を果たします。

Node Exporter のインストールと実行

Prometheus Node Exporter は、tarball 経由でインストールできる単一の静的バイナリです。Prometheus のダウンロードページからダウンロードしたら、それを解凍して実行します。

# NOTE: Replace the URL with one from the above mentioned "downloads" page.
# <VERSION>, <OS>, and <ARCH> are placeholders.
wget https://github.com/prometheus/node_exporter/releases/download/v<VERSION>/node_exporter-<VERSION>.<OS>-<ARCH>.tar.gz
tar xvfz node_exporter-*.*-amd64.tar.gz
cd node_exporter-*.*-amd64
./node_exporter

Node Exporter が現在実行中でポート 9100 でメトリックを公開していることを示す、以下のような出力が表示されるはずです。

INFO[0000] Starting node_exporter (version=0.16.0, branch=HEAD, revision=d42bd70f4363dced6b77d8fc311ea57b63387e4f)  source="node_exporter.go:82"
INFO[0000] Build context (go=go1.9.6, user=root@a67a9bc13a69, date=20180515-15:53:28)  source="node_exporter.go:83"
INFO[0000] Enabled collectors:                           source="node_exporter.go:90"
INFO[0000]  - boottime                                   source="node_exporter.go:97"
...
INFO[0000] Listening on :9100                            source="node_exporter.go:111"

Node Exporter メトリック

Node Exporter がインストールされて実行中になったら、`cURL` を使って `/metrics` エンドポイントにアクセスすることで、メトリックがエクスポートされていることを確認できます。

curl https://:9100/metrics

以下のような出力が表示されるはずです。

# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 3.8996e-05
go_gc_duration_seconds{quantile="0.25"} 4.5926e-05
go_gc_duration_seconds{quantile="0.5"} 5.846e-05
# etc.

成功です!Node Exporter は、Prometheus がスクレイプできるメトリックを公開しています。これには、出力の下の方にある様々なシステムメトリック(`node_` でプレフィックスされているもの)が含まれます。これらのメトリック(ヘルプとタイプ情報を含む)を表示するには

curl https://:9100/metrics | grep "node_"

Prometheus インスタンスの設定

Node Exporter のメトリックにアクセスするには、ローカルで実行中の Prometheus インスタンスが適切に設定されている必要があります。以下のprometheus.yml の設定ファイルの例は、Prometheus インスタンスが `localhost:9100` 経由で Node Exporter から、どのくらいの頻度でスクレイプするかを指示します。

global:
  scrape_interval: 15s

scrape_configs:
- job_name: node
  static_configs:
  - targets: ['localhost:9100']

Prometheus をインストールするには、ご使用のプラットフォーム用の最新リリースをダウンロードし、解凍します。

wget https://github.com/prometheus/prometheus/releases/download/v*/prometheus-*.*-amd64.tar.gz
tar xvf prometheus-*.*-amd64.tar.gz
cd prometheus-*.*

Prometheus のインストールが完了したら、上記で作成した Prometheus 設定ファイルを指すように --config.file フラグを使用して起動できます。

./prometheus --config.file=./prometheus.yml

Prometheus 式ブラウザによる Node Exporter メトリックの探索

Prometheus が実行中の Node Exporter インスタンスからメトリックをスクレイプしているので、Prometheus UI(別名式ブラウザ)を使用してそれらのメトリックを探索できます。ブラウザで `localhost:9090/graph` に移動し、ページ上部のメインの式バーを使用して式を入力します。式バーは次のようになります。

Prometheus expressions browser

Node Exporter に固有のメトリックは `node_` でプレフィックスされており、`node_cpu_seconds_total` や `node_exporter_build_info` などのメトリックが含まれます。

いくつかのメトリック例を見るには、以下のリンクをクリックしてください。

メトリック 意味
rate(node_cpu_seconds_total{mode="system"}[1m]) 過去1分間のシステムモードで費やされたCPU時間の平均値(1秒あたり、秒単位)
node_filesystem_avail_bytes 非ルートユーザーが利用可能なファイルシステム領域(バイト単位)
rate(node_network_receive_bytes_total[1m]) 過去1分間に受信したネットワークトラフィックの平均値(1秒あたり、バイト単位)

このドキュメントはオープンソースです。問題の報告やプルリクエストの送信により、改善にご協力ください。