Docker: Prometheus 및 Grafana로 Docker 모니터링

2026. 3. 22. 09:15·🐳Docker

Docker 및 Docker-compose를 설치했다는 가정하에 작성

  • Docker-compose.yml 작성
version: '3'

services:
  node_exporter:
    image: prom/node-exporter:latest
    container_name: node_exporter
    ports:
      - "9100:9100"
    restart: always

  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    volumes:
      - /home/rocky/dev_monitor/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
      - /home/rocky/dev_monitor/prometheus/alert.rules.yml:/etc/prometheus/alert.rules.yml
    ports:
      - "9090:9090"
    restart: always

  alertmanager:
    image: prom/alertmanager:latest
    container_name: alertmanager
    volumes:
      - /home/rocky/dev_monitor/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml
      - /home/rocky/dev_monitor/alertmanager/templates:/etc/alertmanager/templates
    ports:
      - "9093:9093"
    restart: always

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3000:3000"
    volumes:
      - grafana-data:/var/lib/grafana
    restart: always

volumes:
  grafana-data:
  • node_exporter : 시스템 지표 수집
  • Prometheus : metric 수집기
  • alertmanager : 각종 알림 관리자
  • Grafana : 모니터링 시각화 서비스

Docker container 형식으로 돌리는 것이기 때문에, 사라지면 안되는 file들은 mount를 시켜야 한다.

mount를 설정한 부분

prometheus: 
volumes:
      - /home/rocky/dev_monitor/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
      - /home/rocky/dev_monitor/prometheus/alert.rules.yml:/etc/prometheus/alert.rules.yml

alertmanager: 
volumes:
      - /home/rocky/dev_monitor/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml
      - /home/rocky/dev_monitor/alertmanager/templates:/etc/alertmanager/templates

grafana:
volumes:
      - grafana-data:/var/lib/grafana

각각 경로에 맞게 폴더와 파일을 만든 뒤, Docker container로 올릴 때, mount 해서 올리자.


📌 참고 | Mount 내용

alertmanager

  • alertmanager.yml
global:
  resolve_timeout: 5m

route:
  group_by: ['alertname', 'instanceDown']
  group_wait: 20s
  group_interval: 5m
  repeat_interval: 60m
  receiver: 'telegram'

receivers:
- name: 'telegram' # 텔레그램 외에도 많은 플랫폼이 있음. 
  telegram_configs:
  - bot_token: '봇 토큰'
    chat_id: 챗_id
    send_resolved: true
    message: '{{ template "monitoring-template" . }}' # 내가 만든 템플릿.
templates:
- '/etc/alertmanager/templates/*.tmpl' # 템플릿 경로
  • telegram.tmpl (서버 다운 될 시, 알림 템플릿) — 예시
{{ define "monitoring-template" }}
** {{ if eq .Status "firing" }}🔥{{ else if eq .Status "resolved" }}✅{{ end }} {{ .Status }} **

{{ range .Alerts }}
  Instance: {{ .Labels.instance }}
  Job: {{ .Labels.job }}

  {{ if eq .Status "firing" }}
    {{ .Annotations.summary }} - down
  {{ else if eq .Status "resolved" }}
    {{ .Annotations.summary }} - up
  {{ else }}
    {{ .Annotations.summary }}
  {{ end }}
{{ end }}
{{ end }}

Prometheus

  • alert.rules.yml

알림 규칙을 정의한 파일내용이다.

사용자에 맞게 유동적으로 변경가능하다.

groups:
- name: server_down
  rules:
  - alert: InstanceDown
    expr: up == 0
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Instance {{ $labels.instance }} "
      description: "{{ $labels.instance }} of job {{ $labels.job }} "
  • Prometheus.yml
# 해당 파일은 서버정보가 담겨 있기 때문에 생략.
# 아래와 같은 형식으로 서버마다 작성하면 됨.

- job_name: "Job-name"
    static_configs:
      - targets: ["IP_addr:9100"]
저작자표시 비영리 변경금지 (새창열림)

'🐳Docker' 카테고리의 다른 글

Docker: Docker-Compose 설치 방법 및 확인  (0) 2026.03.22
Docker: Nexus로 Private Docker Registry 구축기  (0) 2026.03.20
Docker: Docker CLI 사용법  (0) 2026.03.18
Docker 이미지 관리: 이미지 Pull, Push 및 백업  (0) 2026.03.18
Docker: 최신 Docker 엔진으로 성능 개선하기  (0) 2026.03.18
'🐳Docker' 카테고리의 다른 글
  • Docker: Docker-Compose 설치 방법 및 확인
  • Docker: Nexus로 Private Docker Registry 구축기
  • Docker: Docker CLI 사용법
  • Docker 이미지 관리: 이미지 Pull, Push 및 백업
Diven
Diven
  • Diven
    Diven
    Diven
  • 전체
    오늘
    어제
    • 분류 전체보기 (110) N
      • ☁️Cloud (21) N
        • AWS (2)
        • Alibaba (14) N
        • OCI (1)
        • AWS: Certified Solution Arc.. (0)
        • AWS: Certificate Advanced N.. (2) N
      • 📊DB (13)
        • MongoDB (8)
        • MariaDB (2)
        • PostgreSQL (2)
        • MySQL (1)
      • 🧑🏽‍💻Dev:Lang (9)
        • C++ (0)
        • GO (1)
        • Python (8)
      • ⚙️DevOps (4)
        • CICD (0)
        • Jenkins (4)
      • 🐳Docker (15)
      • 🪢laC (0)
      • ⚓K8s (7)
      • 🐧Linux (25)
      • 🖥️Monitoring (10)
        • Grafana (1)
        • Prometheus (6)
        • Loki (1)
        • ELK (2)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    docker
    SSL
    PolarDB
    AWS
    linux
    Python
    alb
    centOS7
    Cloud
    NGINX
    alertmanager
    prometheus
    mariadb
    k8s
    알리바바 클라우드
    Alibaba
    jenkins
    mongoDB
    db
    MySQL
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
Diven
Docker: Prometheus 및 Grafana로 Docker 모니터링
상단으로

티스토리툴바