“CPU가 며칠째 90%였는데 몰랐다”, “디스크가 꽉 차서 서비스가 멈춘 뒤에야 알았다” — 모니터링 없이 서버를 운영하면 흔히 겪는 일입니다. 클라우드 매니지드 모니터링 서비스도 있지만, 직접 임대한 VPS·전용서버 환경에서는 Prometheus + Grafana 조합으로 자체 모니터링 스택을 구축하는 것이 비용·데이터 소유권 양쪽에서 유리합니다.
구조 한눈에 보기
[대상 서버] node_exporter (메트릭 노출, :9100)
↓ (주기적으로 pull)
[모니터링 서버] Prometheus (수집·저장, :9090)
↓
[모니터링 서버] Grafana (시각화, :3000)
↓
[알림] Alertmanager → Telegram/Slack/Email
Prometheus는 각 서버의 node_exporter가 노출하는 메트릭을 주기적으로 가져오는(pull) 방식입니다. 로그를 서버가 밀어 보내는(push) 구조가 아니라, 모니터링 서버가 능동적으로 대상을 긁어오기 때문에 대상 서버가 여러 대여도 설정이 중앙에서 관리됩니다.
1) node_exporter 설치 (모니터링 대상 서버)
useradd --no-create-home --shell /usr/sbin/nologin node_exporter
curl -LO https://github.com/prometheus/node_exporter/releases/latest/download/node_exporter-1.8.0.linux-amd64.tar.gz
tar xzf node_exporter-1.8.0.linux-amd64.tar.gz
cp node_exporter-1.8.0.linux-amd64/node_exporter /usr/local/bin/
chown node_exporter:node_exporter /usr/local/bin/node_exporter
systemd 유닛 등록:
# /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now node_exporter
curl localhost:9100/metrics | head # 메트릭 노출 확인
:9100 포트는 모니터링 서버 IP에서만 접근 가능하도록 방화벽으로 제한하는 것이 좋습니다. (방화벽 규칙 관리는 iptables→nftables 마이그레이션 가이드 참고)
2) Prometheus 설치 (모니터링 서버)
useradd --no-create-home --shell /usr/sbin/nologin prometheus
mkdir /etc/prometheus /var/lib/prometheus
curl -LO https://github.com/prometheus/prometheus/releases/latest/download/prometheus-2.53.0.linux-amd64.tar.gz
tar xzf prometheus-2.53.0.linux-amd64.tar.gz
cp prometheus-2.53.0.linux-amd64/{prometheus,promtool} /usr/local/bin/
수집 대상 설정:
# /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'node'
static_configs:
- targets:
- '10.0.0.11:9100' # 웹서버
- '10.0.0.12:9100' # DB서버
- '10.0.0.13:9100' # 게임서버
systemctl enable --now prometheus
http://<모니터링서버>:9090에서 웹 UI 접속, up 쿼리로 각 대상이 정상 수집되는지 확인합니다.
3) Grafana 설치 및 데이터소스 연결
# Debian/Ubuntu 기준
apt-get install -y apt-transport-https software-properties-common
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor > /usr/share/keyrings/grafana.gpg
echo "deb [signed-by=/usr/share/keyrings/grafana.gpg] https://apt.grafana.com stable main" | tee /etc/apt/sources.list.d/grafana.list
apt-get update && apt-get install -y grafana
systemctl enable --now grafana-server
http://<모니터링서버>:3000 접속(초기 계정 admin/admin) 후 Data Sources → Add → Prometheus로 http://localhost:9090 연결. Grafana 공식 대시보드 갤러리에서 Node Exporter Full(대시보드 ID 1860)을 임포트하면 CPU·메모리·디스크·네트워크 그래프가 즉시 구성됩니다.
4) 알림 — Alertmanager로 임계치 초과 시 텔레그램 알림
메트릭을 보는 것과 “문제가 생겼을 때 알아채는 것”은 다릅니다. Alertmanager로 알림 채널을 연결합니다.
# /etc/prometheus/alert.rules.yml
groups:
- name: server-alerts
rules:
- alert: HighCPU
expr: 100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 90
for: 10m
labels:
severity: warning
annotations:
summary: "{{ $labels.instance }} CPU 90% 초과 (10분 지속)"
- alert: DiskAlmostFull
expr: (node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}) * 100 < 10
for: 5m
labels:
severity: critical
annotations:
summary: "{{ $labels.instance }} 디스크 여유공간 10% 미만"
Alertmanager 설정에서 Telegram bot webhook을 연결하면, 서버 문제 발생 시 대시보드를 열어보지 않아도 즉시 알림을 받을 수 있습니다.
어떤 메트릭부터 봐야 하나
처음 구축한다면 아래 4가지만 먼저 갖춰도 실무에서 필요한 대부분을 커버합니다.
| 메트릭 | 왜 중요한가 |
|---|---|
| CPU 사용률(코어별) | 병목 여부, 특정 코어 쏠림 확인 |
| 메모리·스왑 사용량 | OOM 발생 전 조기 경보 |
| 디스크 여유공간·I/O 대기시간 | 서비스 중단의 흔한 원인 |
| 네트워크 처리량·에러/드롭 카운트 | 회선 문제·DDoS 징후 조기 탐지 |
커널 수준까지 더 깊게 관찰하고 싶다면 eBPF로 관찰성 강화하기도 함께 참고하세요. node_exporter가 못 보는 시스템콜·지연 분포 수준까지 들여다볼 수 있습니다.
자주 묻는 질문
Q. 클라우드 매니지드 모니터링(Datadog 등)과 비교하면? 매니지드 서비스는 설정이 편리하지만 서버 대수·메트릭 수에 비례해 비용이 커집니다. 자체 구축은 초기 설정에 시간이 들지만 이후 비용이 인프라(모니터링 서버 하나) 외에 추가되지 않습니다.
Q. 모니터링 서버도 따로 임대해야 하나요? 서버가 몇 대 안 된다면 소규모 VPS 한 대로 충분합니다. Prometheus·Grafana 모두 가벼운 워크로드입니다.
Q. 데이터 보관 기간은?
기본 설정은 15일이며, --storage.tsdb.retention.time 옵션으로 조정 가능합니다. 장기 보관이 필요하면 Thanos·Mimir 같은 장기 저장 솔루션을 추가로 검토합니다.
마무리
모니터링은 “문제가 생긴 뒤 원인을 찾는 도구”가 아니라 문제가 커지기 전에 알아채는 도구입니다. Prometheus + Grafana + Alertmanager 조합은 오픈소스로 무료이고, VPS 한 대 정도의 리소스면 충분히 구축할 수 있습니다.
TCP-80.NET VPS·전용서버 모두 이런 모니터링 스택을 자유롭게 설치할 수 있는 완전한 루트 권한 환경을 제공합니다. 구축이 막히면 텔레그램 @tcp80net으로 문의해 주세요.