Prometheus만 설치해도 호스트의 CPU·메모리·디스크·네트워크 메트릭이 자동으로 수집되는 것은 아니다. 리눅스/유닉스 환경에서 이런 시스템 메트릭을 수집하려면 Node Exporter라는 작은 에이전트를 설치하고, Prometheus가 이를 스크레이프하도록 설정해야 한다. 이 글은 공식 가이드(Node Exporter 공식 가이드)를 기반으로 최소 설치 과정을 정리한다.
Node Exporter가 필요한 이유
- Prometheus 자체는 메트릭 저장소다. 스크레이프할 대상의
/metrics엔드포인트에서 메트릭을 긁어올 뿐, 호스트 OS 메트릭을 직접 수집하지 않는다. - Node Exporter는 리눅스/유닉스 호스트의 CPU·메모리·디스크·네트워크·파일시스템 정보를
/metrics형식으로 노출한다. - Prometheus가 Node Exporter를 스크레이프하면,
node_cpu_seconds_total,node_memory_MemTotal_bytes같은 메트릭을 PromQL로 조회할 수 있다.
설치 과정
1) 바이너리 다운로드 및 설치
최신 릴리스는 Prometheus 다운로드 페이지에서 확인한다. 아래는 1.7.0 기준 예시다.
cd /tmp
curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
tar xvfz node_exporter-1.7.0.linux-amd64.tar.gz
sudo mv node_exporter-1.7.0.linux-amd64/node_exporter /usr/local/bin/
ARM 보드나 다른 아키텍처는 linux-arm64 등 맞는 파일을 받아야 한다.
2) systemd 서비스 등록
Node Exporter를 백그라운드에서 계속 실행하려면 systemd 서비스로 등록한다.
sudo tee /etc/systemd/system/node_exporter.service >/dev/null <<'EOF'
[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
User=node-exp
Group=node-exp
Type=simple
ExecStart=/usr/local/bin/node_exporter --web.listen-address=:9100
[Install]
WantedBy=multi-user.target
EOF
3) 실행 계정 생성 및 서비스 시작
sudo useradd -rs /bin/false node-exp
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
sudo systemctl status node_exporter --no-pager
정상이면 “active (running)” 상태가 표시된다.
4) 방화벽 및 로컬 확인
- 기본 포트: 9100/tcp
- 로컬에서 메트릭 확인:
curl http://localhost:9100/metricsnode_cpu_seconds_total,node_memory_MemTotal_bytes등의 메트릭이 보이면 정상이다.
Prometheus 연동
1) prometheus.yml 스크레이프 설정 추가
scrape_configs:
- job_name: "node"
static_configs:
- targets: ["localhost:9100"]
만약 원격 호스트라면 ["192.168.1.100:9100"] 형식으로 IP를 지정한다.
2) Prometheus 재시작
sudo systemctl restart prometheus
3) 스크레이프 상태 확인
Prometheus 웹 UI → Status → Targets에서 node job이 UP 상태인지 확인한다. 또는 쿼리로 확인:
up{job="node"}
결과가 1이면 정상이다.
실무 쿼리 예시
Node Exporter가 정상 작동하면 아래 PromQL을 바로 쓸 수 있다.
CPU 사용률(%)
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
메모리 사용률(%)
(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100
디스크 사용률(%)
(max by (instance,device) (node_filesystem_size_bytes{fstype!~"tmpfs|overlay"})
- max by (instance,device) (node_filesystem_free_bytes{fstype!~"tmpfs|overlay"}))
/ max by (instance,device) (node_filesystem_size_bytes{fstype!~"tmpfs|overlay"}) * 100
네트워크 수신/송신 Bps
sum by (instance) (rate(node_network_receive_bytes_total{device!~"lo"}[5m]))
sum by (instance) (rate(node_network_transmit_bytes_total{device!~"lo"}[5m]))
흐름 한눈에 보기
Node Exporter :9100]:::exporter --> B[Prometheus
스크레이프 job node]:::prometheus B --> C[PromQL 쿼리
node_cpu_seconds_total]:::query C --> D[Grafana 대시보드
CPU/메모리/디스크]:::dashboard classDef exporter fill:#1e293b,stroke:#10b981,color:#e2e8f0; classDef prometheus fill:#0f172a,stroke:#22d3ee,color:#e0f2fe; classDef query fill:#1e293b,stroke:#f59e0b,color:#fef3c7; classDef dashboard fill:#1e293b,stroke:#ec4899,color:#fce7f3;
결론/팁
- Prometheus는 메트릭 저장소일 뿐, 호스트 메트릭을 직접 수집하지 않는다. Node Exporter를 설치해야
node_*메트릭을 쓸 수 있다. - systemd 서비스로 등록하면 재부팅 후에도 자동 실행된다.
- 포트를 바꾸고 싶으면
--web.listen-address=:9101처럼 옵션을 주고, Prometheus 타깃도 동일 포트로 맞춘다. - 윈도우는 windows_exporter(구 wmi_exporter)를 설치하고 기본 포트 9182를 스크레이프한다.
- 공식 가이드: Monitoring Linux host metrics with the Node Exporter
이제 Grafana에서 Node Exporter 메트릭을 패널로 만들어 CPU·메모리·디스크·네트워크 대시보드를 구성할 수 있다. 다음 단계로 cAdvisor(컨테이너 메트릭)와 Spring Boot Actuator(애플리케이션 메트릭) 연동을 이어가면 풀스택 모니터링이 완성된다.
자신만의 철학을 만들어가는 중입니다.
댓글남기기