Monitoring/Prometheus

Alertmanager 메일 알림 기능 추가

박쿠리 2025. 4. 28. 21:55

1. Alertmanager로 메일 알림 설정

1.1 Prometheus alert rule 작성

Prometheus 가 설치된 서버에 추가하면 된다.

파일  설치 위치
iis_service_alert.yaml Prometheus 서버 내, rules 디렉토리 (예: /etc/prometheus/rules/ 또는 C:\Prometheus\rules\)

(※ rules 디렉토리 없다면 그냥 만들어도 됨.)

 

새 Alert rule 파일 (iis_service_alert.yaml) 예시:

groups:
- name: IIS Service Alerts
  rules:
  - alert: IISServiceDown
    expr: wmi_service_status{service="W3SVC"} == 0
    for: 2m
    labels:
      severity: critical
    annotations:
      summary: "IIS 서비스 다운"
      description: "IIS (W3SVC) 서비스가 2분 이상 죽어있습니다."

 

  • for: 2m → 2분 이상 다운된 경우 알람 발생
  • 필요시 1m, 5m로 조정 가능

prometheus.yaml에 alert rule 등록

파일  위치
prometheus.yaml Prometheus 메인 설정 파일, 보통 /etc/prometheus/prometheus.yml 또는 C:\Prometheus\prometheus.yml

 

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'windows_exporter'
    static_configs:
      - targets: ['서버IP:9182']

  - job_name: 'wmi_exporter'
    static_configs:
      - targets: ['서버IP:9183']

rule_files:
  - "rules/iis_service_alert.yaml"

rule_files는 scrape_configs 끝난 뒤 추가하면 된다.
(즉, scrape_configs: 블록과 나란히 존재해야 한다.)

 

1.2 Alertmanager 메일 설정 예시

Alertmanager : Prometheus 가 보낸 알람을 받아서 외부로 알리는 소프트웨어

https://cool-ri.tistory.com/78

 

Alertmanager 다운로드 & 설치

1. Alertmanager 다운로드 & 설치공식 사이트:https://prometheus.io/download/#alertmanager리눅스 (예시)cd /optwget https://github.com/prometheus/alertmanager/releases/download/v0.26.0/alertmanager-0.26.0.linux-amd64.tar.gztar -xvf alertmanager

cool-ri.tistory.com

 

파일  설치 위치
alertmanager.yaml Alertmanager 설정 파일, 보통 /etc/alertmanager/alertmanager.yaml 또는 C:\Alertmanager\alertmanager.yaml

 

alertmanager.yaml 예시:

global:
  smtp_smarthost: 'smtp.example.com:587'
  smtp_from: 'alert@example.com'
  smtp_auth_username: 'your_email@example.com'
  smtp_auth_password: 'your_password'

route:
  receiver: email-alert

receivers:
- name: email-alert
  email_configs:
  - to: 'your_target_email@example.com'

SMTP 설정은 회사/개인 메일 서버에 맞춰 수정해야 함.

 

요약

[Prometheus]
  - 서버 상태 모니터링
  - 알람 발생

    ↓ 알람 전송

[Alertmanager]
  - 알람 수신
  - 메일 발송, Slack 발송 등

    ↓

[관리자 이메일, Slack 채널]

 

반응형