새소식

Observability/Prometheus

[Prometheus]Prometheus Slack Alert 연동하기

  • -

Custom Rules 작성이 선행되어야 하고 이후 annotaion을 slack message에서 가져다 쓴다.

2022.07.11 - [Monitoring/Prometheus] - [Prometheus](AWS)Add Custom rules to Prometheus stack with cloudwatch-exporter

Slack 수신 웹 설정

  • 기능 페이지에서 수신 웹후크 활성화 토글을 켭니다.

  • Slack에서 Alert을 수신할 채널을 추가한다.

  • 워크스페이스에 새 웹후크 추가를 클릭합니다(. (Add New Webhook to Workspace)

  • API TEST

curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' <https://hooks.slack.com/services/T01P8GA78P8/##중략>
  • Webhook URL
<https://hooks.slack.com/services/T01P8GA78P8/##중략

생성한 채널에서 메세지를 확인할 수 있다.

Webhook URL을 통해서 Prometheus와 Slack을 연동한다.

Prometheus-stack Helm chart의 alertmanager에 Slack 정보 추가하기

Install prometheus stack 참고
2022.05.29 - [Monitoring/Prometheus] - [Prometheus]Install prometheus for kubernetes monitoring with helm chart

slack config 확인
https://prometheus.io/docs/alerting/latest/configuration/#slack_config

alertmanager:
  config:
    global:
      resolve_timeout: 5m
    route:
      group_by: ['job']
      group_wait: 30s
      group_interval: 2m # 초기 알림이 이미 전송된 알림 그룹에 추가된 새 알림에 대한 알림을 보내기 전에 대기하는 시간(보통 최대 5m 이상)입니다. / s, m, h
      repeat_interval: 6h #6h # 알림이 이미 성공적으로 전송된 경우 알림을 다시 보내기 전에 대기하는 시간(보통 최대 3시간 이상).
      receiver: 'gcp-monitoring'
      # All alerts that do not match the following child routes
      # will remain at the root node and be dispatched to 'default-receiver'.
      routes:
      - receiver: 'gcp-monitoring'
        group_wait: 10s
    receivers:
    - name: 'gcp-monitoring'
      slack_configs:
      - channel: 'gke-prometheus' ## The channel or user to send notifications to / 의미가 없어보임 내가 확인하기 위해 작성
        api_url: "<https://hooks.slack.com/services/T01P8GA78P8##중략>
        send_resolved: true
        icon_url: <https://avatars3.githubusercontent.com/u/3380462>
        title: "{{ range .Alerts }}{{ .Annotations.title }}\\n{{ end }}"
        text: "{{ range .Alerts }}{{ .Annotations.message }}\\n{{ end }}"
  • api_url
    • 위에서 확인한 webhook url을 입력한다.

Slack에서 Alert 확인하기

임계치가 넘었을때 위 slack_config에 작성한 title, text에 해당하는 메세지를 받을 수 있는지 확인한다.

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.