Prometheus 联合 Alertnamager 告警配置编写

  1. prometheus.yml
global:
  scrape_interval:     15s
  external_labels:
    monitor: 'codelab-monitor'
scrape_configs:
  - job_name: test
    static_configs:
      - targets: ['10.13.82.244:8000']
        labels:
          instance: proxy
  - job_name: node
    static_configs:
      - targets: ['10.13.82.244:9100','10.13.82.196:9100']
alerting:
  alertmanagers:
  - static_configs:
    - targets: ["localhost:9093"]

rule_files:
   - rule.yml
  1. rule.yml
groups:
- name: test-rule
  rules:
  - alert: "内存报警"
    expr: 100 - ((node_memory_MemAvailable * 100) / node_memory_MemTotal) > 10
    for: 1s
    labels:
      severity: warning
    annotations:
      summary: "服务名:{{$labels.alertname}}"
      description: "业务500报警: {{ $value }}"
      value: "{{ $value }}"
- name: test-rule2
  rules:
  - alert: "内存报警"
    expr: 100 - ((node_memory_MemAvailable * 100) / node_memory_MemTotal) > 40
    for: 1s
    labels:
      severity: test
    annotations:
      summary: "服务名:{{$labels.alertname}}"
      description: "业务500报警: {{ $value }}"
      value: "{{ $value }}"
  1. alertmanager.yml
global:
  smtp_smarthost: 'xxx'
  smtp_from: 'xxx'
  smtp_auth_username: 'xxx'
  smtp_auth_password: 'xxx'
  smtp_require_tls: false

templates:
  - '/alertmanager/template/*.tmpl'

route:
  receiver: 'default-receiver'
  group_wait: 1s #组报警等待时间
  group_interval: 1s  #组报警间隔时间
  repeat_interval: 1s  #重复报警间隔时间
  group_by: [cluster, alertname]
  routes:
  - receiver: test
    group_wait: 1s
    match_re:
      severity: test
receivers:
- name: 'default-receiver'
  email_configs:
  - to: '[email protected]'
    html: '{{ template "wps.html" . }}'
    headers: { Subject: " {{ .CommonAnnotations.summary }}" }
- name: 'test'
  email_configs:
  - to: '[email protected]'
    html: '{{ template "wps.html" . }}'
    headers: { Subject: " {{ 第二路由匹配测试}}" }
  1. test.tmpl
{{ define "wps.html" }}

    {{ range $i, $alert := .Alerts }}
        
    {{ end }}
报警项 磁盘 报警阀值 开始时间
{{ index $alert.Labels "alertname" }} {{ index $alert.Labels "instance" }} {{ index $alert.Annotations "value" }} {{ $alert.StartsAt }}
{{ end }}

原文地址:https://www.cnblogs.com/cp-miao/p/9071939.html

你可能感兴趣的:(Prometheus 联合 Alertnamager 告警配置编写)