[Grafana] grafana alert

Younghwan Cha·2023년 4월 12일
0

server monitoring

목록 보기
10/11

[grafana alert] https://grafana.com/docs/grafana/latest/panels-visualizations/


Alerting

[how to create grafana alaram rule] https://grafana.com/docs/grafana/latest/alerting/alerting-rules/create-grafana-managed-rule/

Optionally, enable Continue matching subsequent sibling nodes to continue matching nested policies 
even after the alert matched the parent policy. When this option is enabled, you can get more than 
one notification. Use it to send notification to a catch-all contact point as well as to one of more 
specific contact points handled by nested policies.

https://community.grafana.com/t/nested-notification-policy-contact-point/74137


config threshold

https://grafana.com/docs/grafana/latest/panels-visualizations/configure-thresholds/


Alert rules

Folder > Evaluation Group > Rule group evaluation interval

contact point 정의 ( slack, sms etc)
label 에 contact point 연결
패널에서 특정 임계정을 설정 후 label 정의

1. Set an alert rule name


2. Set a query and alert condition

alert condition 을 결정하는 요소는 여러가지가 있다

  • Math
  • Classic_conditions
    classic conditions RefID B 에 정의한 condition 의 값을 {{ $values.B0 }},
    {{ $values.B1 }} 와 같이 불러 올 수 있다.

[classic conditions]
https://grafana.com/docs/grafana/latest/alerting/fundamentals/annotation-label/variables-label-annotation/#classic-conditions

  • Threshold

3. Alert evaluation behavior

  • No data and error handling
    해당 옵션에서 데이터가 없을 경우의 상태값을 지정할 수 있다.
    • No Data Option
      • No Data
      • Alerting
      • Ok
    • Error or timeout option
      • Alerting
      • Ok
      • re

[No data & error handling] https://grafana.com/docs/grafana/latest/alerting/alerting-rules/create-grafana-managed-rule/#no-data-and-error-handling


4. Add details for your alert rule
알림과 관련된 정보들을 기입 할 수 있는 섹션이다.
- Panel ID & Dashboard UID
Set dashboard and panel 버튼을 통해서 alarm 을 등록할 대상 패널을 등록하면 자동으로 관련 정보를 반환한다.
- summary
{{ $values.B0 }}
[variable] https://grafana.com/docs/grafana/latest/alerting/fundamentals/annotation-label/variables-label-annotation/#the-values-variable


  1. Notifications

contact points

[contact point] https://grafana.com/docs/grafana/latest/alerting/fundamentals/contact-points/


template

contact point 에 보낼 내용들을 미리 template 에 정의해두고 재사용 할 수 있다.

Add Template => template name 와 content 를 입력 => save template

이때, content 를 입력하면 {{ define "<template name>" }}{{ end }} 이 자동으로 붙어서 template 이 생성된다.

# content
{{ len .Alerts.Firing }} firing. {{ len .Alerts.Resolved }} resolved.
# template
{{ define "mytemplate" }}
  {{ len .Alerts.Firing }} firing. {{ len .Alerts.Resolved }} resolved.
{{ end }}

이후에, 다음과 같이 template 을 사용 할 수 있다.

{{ template "mytemplate" . }}

아래와 같이 {{ range .Alerts }} 를 통해서 for 문을 사용 할 수 있다.

{{ define "slack" }}
  {{ range .Alerts }}
    {{ template "alertEmoji" .}}: {{ .Annotations.summary }}
  {{ end }}
{{ end }}

정의한 template 이외에도 아래와 같은 default 값들이 있다.

  • default.title
  • default.message
  • teams.default.message

[Notification templating] https://grafana.com/docs/grafana/latest/alerting/fundamentals/alert-rules/message-templating/

[msg template] https://community.grafana.com/t/how-to-use-alert-message-templates-in-grafana/67537

[reference] https://grafana.com/docs/grafana/latest/alerting/manage-notifications/template-notifications/reference/


Notification policies

(label)

profile
개발 기록

0개의 댓글