반응형
1. Slack “NEW APP” 생성
- apps 슬랙 페이지 접속 : https://api.slack.com/apps
- “Create New App” 클릭

- App Name 입력
- Workspace 선택
- “Create App” 클릭

- Install your app 설치

- Features → “Oauth & Permissions” 클릭
- “OAuth Tokens for Your Wokrspace” 토큰 확인
- ex) xoxb-xxxxxxxx

- Features → “Oauth & Permissions” 클릭
- Scopes 설정
- chat:write
- files:write

2. Slack Bot 추가
- 생성한 앱 이름을 입력하면 앱을 초대할 수 있다.
- “@grafana-Alert” 입력

3. Slack Bot 테스트
- 테스트 사이트 : https://api.slack.com/methods/chat.postMessage/test
- Or, provide your own token: ex) xoxb-xxx
- channel : datadog-misc-infra
- text : test
- “Test method” 클릭

4. Alert Templates 설정
Templates은 Slack에 메세지 내용을 설정
- title
- text
- Alerting -> Contact Points -> "New templates" 클릭
- Template name : 템플릿 이름
- Content : 내용 입력
- "Save template" 클릭
{{ define "alert_severity_prefix_emoji" -}}
{{- if ne .Status "firing" -}}
:white_check_mark:
{{- else if eq .CommonLabels.severity "critical" -}}
:red_circle:
{{- else if eq .CommonLabels.severity "warning" -}}
:warning:
{{- end -}}
{{- end -}}
{{ define "slack.title" -}}
{{ template "alert_severity_prefix_emoji" . }}
[{{- .Status | toUpper -}}{{- if eq .Status "firing" }} x {{ .Alerts.Firing | len -}}{{- end }} | {{ .CommonLabels.env | toUpper -}} ] {{ .CommonLabels.alertname -}}
{{- end -}}
{{- define "slack.text" -}}
{{- range .Alerts -}}
{{ if gt (len .Annotations) 0 }}
*Summary*: {{ .Annotations.summary}}
*Description*: {{ .Annotations.description }}
*AlertValues*: {{ .Annotations.AlertValues }}
Grafana URL : https://grafana.test.com
{{ end }}
{{ end }}
{{ end }}
5. Alert Contact point 설정
- Alerting → “Contact Points” → “New contact point" 클릭

- Name : Contant point Name 입력
- Contact Point type : Slack 입력
- Recipient : service-error (slack 채널방 입력)
- Webhook URL : Slack 채널 Webhook URL 입력
- Title : 템플릿 정보 넣기 {{ template "slack.title" .}}
- Text Body : 템플릿 정보 넣기 {{ template "slack.text" .}}
- test 클릭
- Alert 테스트 가능
- test 클릭
- “Save contact point” 저장


6. Notification Policies 설정
Label 지정된 내용으로 Alert를 어디에 보낼지 설정하는 내용입니다.
- Alerting -> "Notification policies" -> "New policy" 클릭
- Label
- env = project-prod & slack = service-error 이라고 라벨링 달린 Alert를 "Contact Point"에게 전달한다.
- Contact point : 위에서 생성한 Contact point(Slack) 정보를 선택한다.
- Save policy 클릭
7. Alert Rule 설정
Loki에서 수집된 로그중에서 조건에 맞으면 알람을 보내준다.
- Alerting -> Alert rules -> New alert rule 클릭
- A : 등록한 Loki Datasource 클릭
- Code : istio-proxy 컨테이너 제외, statge-* pod 제외, WARN와 warn, "Requested entity was not found" 메세지는 제외 default 네임스페이스에서 , 메세지에 error와 ERROR 가 포함되어있으면 알람을 발생해준다.
sum by(pod, container) (count_over_time({namespace="default", instance=~".*", container!="istio-proxy", pod!~"stage-*"} |~ `(error|ERROR)` !~ `Requested entity was not found` !~ `(WARN|warn)` [1s]))
- Evalute every : 30초 마다 Alert Rule을 검색하고 30s동안 유지되면 알람발생
- Rule name : rule 이름
- Folder : Rule 구분하기 위한 폴더 선택
- group : Rule 구분하기 위한 그룹 선택
- Summary and annotations : Alert이 발생하면 어느 정보를 전달할지 정의한다.
{{ with $values }}
{{ range $k, $v := . }}
Pod: {{$v.Labels.pod}}
Container: {{$v.Labels.container}}
Alerting value: {{ $v }}
{{ end }}
{{ end }}
- Alert이 발생하면 어느 policy에 적용될지 Label을 정의해준다.
반응형
'모니터링 > prometheus' 카테고리의 다른 글
[ Prometheus ] Nginx Log exporter (0) | 2023.03.16 |
---|---|
[ prometheus ] Nginx exporter (0) | 2023.03.16 |
[ Grafana ] 설정 (0) | 2023.02.27 |
[ prometheus ] node exporter (0) | 2023.02.23 |
[ prometheus ] component 구성 (0) | 2023.02.23 |