이번 글에서는 Prometheus를 사용하여 Linux 호스트의 성능 메트릭을 모니터링하는 방법을 알아보겠습니다. 이를 위해 Node Exporter를 설치하고 설정하는 과정을 다룹니다.
Node Exporter는 Linux 호스트의 메트릭을 수집하여 Prometheus가 이를 스크랩할 수 있도록 하는 도구입니다. CPU, 메모리, 디스크 사용량 등 다양한 시스템 메트릭을 수집할 수 있으며, 이를 통해 시스템의 상태를 실시간으로 모니터링할 수 있습니다.
먼저, Prometheus 공식 웹사이트로 이동하여 Node Exporter를 다운로드합니다. 설치하려는 시스템 아키텍처에 맞는 버전을 선택한 후, 바이너리를 다운로드하거나 URL을 복사하여 wget을 사용해 파일을 다운로드할 수 있습니다.
$ wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
HTTP request sent, awaiting response... 200 OK
Length: 9033415 (8.6M) [application/octet-stream]
Saving to: ‘node_exporter-1.3.1.linux-amd64.tar.gz’
node_exporter-1.3.1.linux-amd64.tar.gz
100%[=========================================================================
=========>] 8.61M 12.4MB/s in 0.7s
2022-09-02 15:04:10 (12.4 MB/s) - ‘node_exporter-1.3.1.linux-amd64.tar.gz’
saved [9033415/9033415]
다운로드한 파일은 tar 형식으로 압축되어 있습니다. 아래 명령어를 사용해 압축을 해제합니다.
$ tar –xvf node_exporter-1.3.1.linux-amd64.tar.gz
node_exporter-1.3.1.linux-amd64/
node_exporter-1.3.1.linux-amd64/LICENSE
node_exporter-1.3.1.linux-amd64/NOTICE
node_exporter-1.3.1.linux-amd64/node_exporter
압축을 해제한 후, 해당 디렉토리로 이동하면 node_exporter
실행 파일이 있습니다.
cd node_exporter-[버전]
Node Exporter를 실행하려면 다음 명령어를 사용합니다.
$ ./node_exporter
ts=2022-09-05T16:51:59.947Z caller=node_exporter.go:115 level=info collector=vmstat
ts=2022-09-05T16:51:59.947Z caller=node_exporter.go:199 level=info msg="Listening on" address=:9100
ts=2022-09-05T16:51:59.947Z caller=tls_config.go:195 level=info msg="TLS is disabled." http2=false
기본적으로 Node Exporter는 포트 9100에서 실행되며, 이는 필요에 따라 변경할 수 있습니다.
Node Exporter가 정상적으로 작동하는지 확인하려면, curl 명령어를 사용하여 로컬 호스트의 포트 9100으로 요청을 보내면 됩니다. /metrics
엔드포인트를 통해 수집된 메트릭을 확인할 수 있습니다.
$ curl http://localhost:9100/metrics
# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# 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
또는, 웹 브라우저를 열고 http://localhost:9100/metrics
에 접속하여 확인할 수 있습니다.
이제 Prometheus가 해당 메트릭을 스크랩할 수 있도록 설정이 완료되었습니다. 이를 통해 시스템의 다양한 성능 지표를 실시간으로 모니터링하고, 이상 발생 시 빠르게 대응할 수 있습니다.
Node Exporter를 사용하여 Prometheus와 함께 Linux 시스템의 상태를 모니터링하는 방법을 살펴보았습니다. 이 과정은 시스템의 성능을 모니터링하고 관리하는 데 매우 유용하며, 문제 발생 시 신속한 대응을 가능하게 합니다.