Prometheus and Grafana: Linux and Docker Monitoring Notes

Jul 27 2026 · 1 min · Sieon

예전 Velog에 Prometheus와 Grafana 설치 과정을 따로 적어두었는데, 다시 보니 단순 설치 명령보다 monitoring 흐름을 같이 정리하는 편이 더 좋다.

이 글은 Linux 설치 방식과 Docker 설치 방식을 하나의 메모로 다시 정리한 것이다.

Prometheus와 Grafana의 역할

Prometheus는 metric을 수집하고 저장하는 time series database다. Target endpoint를 주기적으로 scrape해서 metric을 가져온다.

Grafana는 수집된 metric을 dashboard로 보여주는 시각화 도구다. Prometheus를 data source로 연결하면 CPU, memory, disk, application metric 등을 dashboard로 볼 수 있다.

간단히 나누면 이렇다.

  • Prometheus: metric 수집과 저장
  • node exporter: Linux host metric 노출
  • Grafana: dashboard와 visualization

Prometheus scrape config

Prometheus는 prometheus.yml 파일로 scrape 대상을 설정한다.

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: prometheus
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']

여기서 targets는 Prometheus가 metric을 가져올 endpoint다. Docker 환경에서는 localhost가 host가 아니라 container 자기 자신을 의미할 수 있으므로 network 구성을 주의해야 한다.

Docker network로 Prometheus 실행

Docker에서 Prometheus를 띄울 때는 같은 network 안에서 target container를 찾을 수 있게 구성하는 것이 좋다.

docker network create db_network

docker run -d \
  --name prometheus \
  --network db_network \
  -p 9090:9090 \
  -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
  prom/prometheus

브라우저에서 다음 주소로 접속하면 Prometheus UI를 볼 수 있다.

http://public-ip:9090

Grafana Docker 실행

Grafana는 Docker로 간단하게 실행할 수 있다.

docker run -d \
  --name grafana \
  -p 3000:3000 \
  grafana/grafana

초기 접속은 보통 다음 주소다.

http://public-ip:3000

기본 계정은 환경에 따라 다를 수 있지만, 예전 Grafana 기본값은 admin / admin이었다. 운영 환경에서는 반드시 비밀번호를 변경해야 한다.

node exporter

node exporter는 Linux host의 CPU, memory, disk, network metric을 Prometheus 형식으로 노출한다.

보통 9100 port를 사용한다.

http://public-ip:9100/metrics

Prometheus가 node exporter를 scrape하려면 config에 target을 추가해야 한다.

scrape_configs:
  - job_name: node
    static_configs:
      - targets: ['node-exporter:9100']

Docker Compose를 사용하면 Prometheus, Grafana, node exporter를 같은 network에 올려 container name으로 통신하게 만들 수 있다.

Linux package 방식 설치

Linux에 직접 Grafana를 설치할 수도 있다. 예전 노트에서는 yum repository를 추가한 뒤 package를 설치하는 흐름으로 정리했다.

sudo yum -y install grafana
sudo systemctl enable --now grafana-server
sudo systemctl start grafana-server

Prometheus도 binary를 내려받고, prometheus user를 만들고, /etc/prometheus, /var/lib/prometheus 권한을 설정하는 식으로 구성할 수 있다.

Docker 방식은 실습이 빠르고, package 방식은 host service로 운영할 때 구조를 이해하기 좋다.

Dashboard 구성 흐름

Grafana에서 dashboard를 보려면 다음 순서로 진행한다.

  1. Grafana에 로그인한다.
  2. Data source로 Prometheus를 추가한다.
  3. Prometheus URL을 입력한다.
  4. Dashboard를 import하거나 panel을 직접 만든다.
  5. Query에 PromQL을 입력한다.

예를 들어 CPU나 memory metric은 node exporter가 노출한 metric을 PromQL로 조회해서 그래프로 만들 수 있다.

운영할 때 주의할 점

Monitoring stack도 운영 서비스다. 그래서 다음을 조심해야 한다.

  • Grafana admin password를 기본값으로 두지 않는다.
  • Prometheus와 Grafana를 public internet에 그대로 노출하지 않는다.
  • scrape interval을 너무 짧게 잡아 target에 부담을 주지 않는다.
  • Prometheus data retention을 설정한다.
  • volume을 붙여 Grafana dashboard와 Prometheus data를 보존한다.

정리

Prometheus와 Grafana는 역할을 나눠서 이해하면 쉽다.

  • Prometheus는 metric을 scrape하고 저장한다.
  • Grafana는 metric을 dashboard로 보여준다.
  • node exporter는 host metric을 노출한다.
  • Docker 환경에서는 network와 localhost 의미를 주의해야 한다.
  • 운영 환경에서는 인증, 보존 기간, volume, network 노출을 같이 챙겨야 한다.