Monitoring/Prometheus-Grafana

[Prometheus - Grafana] - 7 Node-exporter 실습

돌문어우엉 2025. 4. 19. 14:03

Node-Exporter란

Node Exporter는 Prometheus에서 서버(노드)의 시스템 수준 메트릭을 수집하기 위해 사용하는 대표적인 Exporter입니다.
Linux 서버의 CPU, 메모리, 디스크, 네트워크 등 운영 체제 자원에 대한 상태 정보를 수집하고, Prometheus가 이를 pull 방식으로 수집할 수 있도록 HTTP로 노출합니다.

 

 

Node-exporter 설치

 

리소스 데이터를 수집할 대상호스트에서 아래과정을 진행합니다.

설치전 아래 명령어로 혹시나 9100포트를 사용중인지 체크합니다.

ss -tulnp | grep 9100

서버의 로컬환경에서 직접설치합니다.

yum install wget
# 압축 파일 다운로드
# 압축 파일 해제
# 압축 파일 삭제
# node_exporter 설치된 디렉토리로 이동
wget <https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz>
tar -xvf node_exporter-1.8.2.linux-amd64.tar.gz
cd node_exporter-1.8.2.linux-amd64

# node_exporter 실행 -> 실행후 서버 재접속
$ ./node_exporter --no-collector.nvme

 

 

리눅스 서비스 등록

nodeexporter를 systemctl로 관리하기 위해 서비스 등록을 진행합니다.

# user 추가
# 실행 파일 /usr/local/bin/으로 경로 복사 이동
# /usr/local/bin/node_exporter node_exporter 유저, 그룹 권한 주기
useradd -M -r -s /bin/false node_exporter
cd /usr/local/node-exporter/node_exporter-1.8.2.linux-amd64
cp ./node_exporter /usr/local/bin
chown node_exporter:node_exporter /usr/local/bin/node_exporter

# 서비스 파일 등록
$ tee /etc/systemd/system/node_exporter.service << EOF
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter --no-collector.nvme

[Install]
WantedBy=multi-user.target
EOF

# 데몬 리로드
$ systemctl daemon-reload

 

 

Node-exporter 구동 및 메트릭 확인

systemctl 로 재시작 하여 서비스 상태를 확인합니다.

# 서비스 가동
$ systemctl restart node_exporter

# 서비스 상태 확인
$ systemctl status node_exporter
● node_exporter.service - Node Exporter
   Loaded: loaded (/etc/systemd/system/node_exporter.service; disabled; vendor pr>
   Active: active (running) since Tue ; 5s ago
 Main PID: 48153 (node_exporter)
...

 

 

메트릭이 재대로 나오고있는지 확인합니다.

$ curl localhost:9100/metrics

# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0
go_gc_duration_seconds_sum 0
go_gc_duration_seconds_count 0
...

 

 

 💡 만약 위 명령어에서는 metrics가 잘 나오지만 Prometheus와 연동이 되지 않을시, 해당 서버의 방화벽설정을 확인하여 9100포트를 열어 주어야 합니다. (Prometheus가 다른서버에 설치된 경우)

#방화벽 포트 상태 확인
firewall-cmd --list-ports

#9100추가
firewall-cmd --add-port=9100/tcp --permanent

#방화벽정책 리로드
firewall-cmd --reload

 

 

exporter - prometheus - Grafana 연동

설치된 exporter를 Prometheus와 연결하고 Grafana로 시각화 합니다.

※Prometheus와 Grafana설치 및 연동은 이전 글을 참조해 주세요.

 

프로메테우스의 config.yml 설정파일에 다음 내용을 추가합니다.

- job_name: 'test' #서버명 (주의: 이름 변경시 기존데이터와 연동X) 
    scrape_interval: 5s #새로고침 주기
    static_configs:
    - targets: ['nodeexporter가 설치된 서버 ip:9100']

 

 

 

프로메테우스 재 기동 후 프로메테우스에 접속하여 target을 확인합니다.

위와같이 정상으로 표시되어야 합니다.

 

 

그라파나에 접속하여 1860번 대시보드를 import합니다. (다른 커스텀 대시보드 사용 가능)

데이터소스는 prometheus입니다.

 

 

대시보드 확인