프로메테우스 알림매니저 실행 - Prometheuse alertmanager via slack
1. 정의
- 프로메테우스는 alert 시스템을 제공한다.
- slack, hipchat 등 을 통하여 alert을 받을 수 있다.
- 만약 node_exporter 가 설치된 서버에 node_exporter가 죽으면 instance가 죽었다는 alert을 받는다.
2. AlertManager 구성
- https://prometheus.io/docs/alerting/overview/
- 두 파트로 나뉜다, Alert rules, Alert manager
- Alert rules가 Alert manager에게 alert 메시지를 전송하면 Alert manager는 슬랙, 이메일, 힙챗 등을 통하여 사용자게에 보여준다
3. AlertManger설치 및 설정
1) AlertManager 설치
- https://prometheus.io/download/ OS에 맞는 AlertManager를 다운받는다.
- simple.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | global: slack_api_url: 'https://xxxx.com/xxxxx/slack' route: receiver: 'slack-notifications' group_by: ['alertname', 'cluster'] group_wait: 30s group_interval: 5m repeat_interval: 3h routes: - receiver: 'slack-notifications' group_wait: 10s match_re: service: mysql|cassandra receivers: - name: 'slack-notifications' slack_configs: - channel: 'test1' |
- 해당 설정 파일을 통하여 AlertManager를 설정할 수 있다.
- 위 설정은 slack 을 이용한 alert를 받기 위한 설정이다.
- global : 이 영역에 slack, hipchat 같은 api를 작성한다.
- route : 최상위 노드로서 group의 이름, 시간 등을 설정한다.
- receivers : slack 채널을 설정
- https://prometheus.io/docs/alerting/configuration/
- ./alertmanager.exe --conifg.file=simple.yml 실행
- localhost:9093에 접속하면 AlertManger 화면에 접속할 수 있다.
4. Alertrules 설정 및 Slack 연결
- AlertManager를 설치 했다면 AlertRule를 설정한다. Rule 설정은 프로메테우스 서버에서 설정한다.
1) Prometheus.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: 'codelab-monitor' # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: - alert.rules.yml # - second.rules alerting: alertmanagers: - static_configs: - targets: ["localhost:9093"] # A scrape configuration containing exactly one endpoint to scrape`: # Here it's Prometheus itself. scrape_configs: ...... ..... |
- rule_files : Alertrules 파일을 따로 만들어서 이곳에서 loading 되도록 한다.
- alerting : AlertManger와 연결하는 부분
- 과거 버전(x): ./prometheus.exe --config.file=prometheus.yml --alertmanager.url=http://localhost:9093
- 최신 버전(o) : prometheus.yml 파일에 직접 셋팅한다.
2) alert.rules.yml
- 과거버전
1 2 3 4 5 6 7 8 9 | ALERT InstanceDown IF up == 0 FOR 5m LABELS { severity = "page" } ANNOTATIONS { # Prometheus templates apply here in the annotation and label fields of the alert. summary = "Instance {{ $labels.instance }} down", description = "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." } |
- 최신 버전
- ALERT RULE 포맷이 아닌 YAML 포맷을 따른다.
1 2 3 4 5 6 7 8 9 10 11 12 | groups: - name: alert.rules rules: - alert: InstanceDown expr: up == 0 for: 30s labels: severity: page annotations: description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 30 seconds.' summary: Instance {{ $labels.instance }} down |
- 변환 방법
- rules 파일을 먼저 만들고 promtool 을 이용하여 update 하면 자동으로 변환된다.
- ./promtool.exe update rules alert.rules
5. 확인
- ./alertmanager.exe --config.file=simple.yml 을 띄운다
- ./prometheus.exe --config.file=prometheus.yml 실행
- 이후에 node_exporter가 설치된 서버에 접속하여 node_exporter 를 죽인다
- localhost:9090/alerts, localhost:9093 에 접속하여 확인
'APM > Prometheus' 카테고리의 다른 글
[Prometheus] 그라파나(Grafana)를 이용한 프로메테우스 시각화 (0) | 2017.07.05 |
---|---|
[Prometheus] 프로메테우스(APM) 아마존 EC2 자동 찾기 - Automatically monitoring EC2 Instances (0) | 2017.07.05 |
[Prometheus] 프로메테우스(APM) node_exporter 연결하기 (0) | 2017.07.04 |
[Prometheus] 프로메테우스(APM) 설정파일 오류 prometheus.yml error (0) | 2017.07.04 |
[Prometheus] 프로메테우스(APM) 설치 및 실행 (0) | 2017.07.04 |