node exporter를 컨테이너로 사용했다. systemd 의 서비스를 모니터링 할 수 없다는 단점이 있다. 그래서 컨테이너 대신 서비스 형식으로 사용하는 방법을 알아 보았다. 아래 2곳에서 관련 정보를 얻었다.

Node_exporter –collector.systemd.unit-include regex trouble
I’m trying to limit the systemd units that the node_exporter is gathering metrics for, and I’m having trouble with the regex. I’m using the grafana-server.service as a test on the host, but the exp…
가장 먼저 node-exporter를 다운 받는다.

Download | Prometheus
An open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.
시스템에 맞춰서 다운 받고 압축을 풀어준다. 글을 작성할 때는 1.8.2 였는데, 지금은 1.9.0이 최신 버전이다.
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
tar xzvf node_exporter-1.8.2.linux-amd64.tar.gz
파일을 /usr/local/bin으로 옮겨준다.
Prometheus의 깃헙 내용으로는 –collector.systemd.unit-include=cloudflared-proxy-dns.service 옵션만 추가하면 될 것 같다. 그러면 안된다.
GitHub – prometheus/node_exporter: Exporter for machine metrics
Exporter for machine metrics. Contribute to prometheus/node_exporter development by creating an account on GitHub.
다음과 같이 –collector.systemd 을 더 넣어주고 실행한다.
./node_exporter --collector.systemd --collector.systemd.unit-include=cloudflared-proxy-dns.service
서비스 등록은 다음처럼 한다.
sudo nano /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/home/ysrcc/node_exporter-1.8.2.linux-amd64/node_exporter --collector.systemd --collector.systemd.unit-include=cloudflared-proxy-dns.service
[Install]
WantedBy=multi-user.target
다음 명령어로 서비스 등록 및 실행한다.
sudo systemctl daemon-reload
sudo systemctl enable node_exporter.service
sudo systemctl start node_exporter.service