
PrometheusのNode ExporterをRocky Linux 9にインストールします。
記事の目次
PrometheusのNode Exporterをダウンロードする!
Node Exporter用のディレクトリを作成して移動します。
$ mkdir -p prometheus/node_exporter $ cd prometheus/node_exporter
Prometheusのホームページでダウンロードするバージョンを確認し、GitHubからNode Exporterをダウンロードします。
$ wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz $ ls -l total 9944 -rw-r--r--. 1 usradmin usradmin 10181045 Nov 30 04:05 node_exporter-1.5.0.linux-amd64.tar.gz
Node Exporterを展開する!
Node Exporterを展開します。
$ tar -zxvf node_exporter-1.5.0.linux-amd64.tar.gz node_exporter-1.5.0.linux-amd64/ node_exporter-1.5.0.linux-amd64/LICENSE node_exporter-1.5.0.linux-amd64/NOTICE node_exporter-1.5.0.linux-amd64/node_exporter
Node Exporterを起動する!
Node Exporterを展開したディレクトリに移動し、Node Exporterを起動します。
$ cd node_exporter-1.5.0.linux-amd64 $ ./node_exporter ... ts=2022-12-14T20:28:45.438Z caller=tls_config.go:232 level=info msg="Listening on" address=[::]:9100 ts=2022-12-14T20:28:45.438Z caller=tls_config.go:235 level=info msg="TLS is disabled." http2=false address=[::]:9100
Node Exporterが動作していることを確認する!
curlコマンドで、Node Exporterが動作していることを確認します。
$ curl http://localhost:9100/metrics
...
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 0
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0
Node Exporterをsystemdで自動起動する!
systemdのUnitの定義ファイルを作成します。
$ cat /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Documentation=https://github.com/prometheus/node_exporter
[Service]
Type=simple
ExecStart=/home/usradmin/prometheus/node_exporter/node_exporter-1.5.0.linux-amd64/node_exporter
ExecStop=/bin/kill -TERM ${MAINPID}
ExecReload=/bin/kill -HUP ${MAINPID}
Restart=always
User=usradmin
[Install]
WantedBy=multi-user.target
Unitを登録し、起動します。
$ sudo systemctl daemon-reload
$ sudo systemctl enable node_exporter.service
Created symlink /etc/systemd/system/multi-user.target.wants/node_exporter.service → /etc/systemd/system/node_exporter.service.
$ sudo systemctl start node_exporter.service
$ sudo systemctl status node_exporter.service
● node_exporter.service - Node Exporter
Loaded: loaded (/etc/systemd/system/node_exporter.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2022-12-21 22:57:06 JST; 15s ago
...
Prometheusのサーバ側の設定を行う!
サーバ側の設定を行います。prometheus.ymlの最後に以下の3行を追加してPrometheusを再起動します。node_exporterは、「vmsans01」というサーバにインストールしています。
$ cat prometheus.yml
# my global config
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).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager: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"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: "node_exporter"
static_configs:
- targets: ["vmsans01:9100"]
Node Exporterが登録されたことを確認する
Prometheusのサーバ名が、「vmspmt01」の場合、以下のURLにアクセスして、Node Exporterが追加されたことを確認します。
http://vmspmt01:9090/targets#pool-prometheus
おわりに
PrometheusのNode Exporterのインストールはとても容易です。Node Exporterのインストール後は、Prometheusのサーバ側の設定を行って監視を行います。
参考情報
関連記事
Prometheus書籍(Amazon)
