Prometheus监控
  • 介绍
  • 全书组织
  • Part I - Prometheus基础
    • 第1章 天降奇兵
      • Prometheus简介
      • 初识Prometheus
        • 安装Prometheus Server
        • 使用Node Exporter采集主机数据
        • 使用PromQL查询监控数据
        • 监控数据可视化
      • 任务和实例
      • Prometheus核心组件
      • 小结
    • 第2章 探索PromQL
      • 理解时间序列
      • Metrics类型
      • 初识PromQL
      • PromQL操作符
      • PromQL聚合操作
      • PromQL内置函数
      • 在HTTP API中使用PromQL
      • 最佳实践:4个黄金指标和USE方法
      • 小结
    • 第3章 Prometheus告警处理
      • Prometheus告警简介
      • 自定义Prometheus告警规则
      • 部署AlertManager
      • Alertmanager配置概述
      • 基于标签的告警处理路由
      • 使用Receiver接收告警信息
        • 集成邮件系统
        • 集成Slack
        • 集成企业微信
        • 集成钉钉:基于Webhook的扩展
      • 告警模板详解
      • 屏蔽告警通知
      • 使用Recoding Rules优化性能
      • 小结
  • Part II - Prometheus进阶
    • 第4章 Exporter详解
      • Exporter是什么
      • 常用Exporter
        • 容器监控:cAdvisor
        • 监控MySQL运行状态:MySQLD Exporter
        • 网络探测:Blackbox Exporter
      • 使用Java自定义Exporter
        • 使用Client Java构建Exporter程序
        • 在应用中内置Prometheus支持
      • 小结
    • 第5章 数据与可视化
      • 使用Console Template
      • Grafana的基本概念
      • Grafana与数据可视化
        • 变化趋势:Graph面板
        • 分布统计:Heatmap面板
        • 当前状态:SingleStat面板
      • 模板化Dashboard
      • 小结
    • 第6章 集群与高可用
      • 本地存储
      • 远程存储
      • 联邦集群
      • Prometheus高可用
      • Alertmanager高可用
      • 小结
    • 第7章 Prometheus服务发现
      • Prometheus与服务发现
      • 基于文件的服务发现
      • 基于Consul的服务发现
      • 服务发现与Relabel
      • 小结
  • Part III - Prometheus实战
    • 第8章 监控Kubernetes
      • 初识Kubernetes
      • 部署Prometheus
      • Kubernetes下的服务发现
      • 监控Kubernetes集群
      • 基于Prometheus的弹性伸缩
      • 小结
    • 第9章 Prometheus Operator
      • 什么是Prometheus Operator
      • 使用Operator管理Prometheus
      • 使用Operator管理监控配置
      • 在Prometheus Operator中使用自定义配置
      • 小结
    • 参考资料
Powered by GitBook
On this page

Was this helpful?

  1. Part I - Prometheus基础
  2. 第3章 Prometheus告警处理
  3. 使用Receiver接收告警信息

集成企业微信

Previous集成SlackNext集成钉钉:基于Webhook的扩展

Last updated 5 years ago

Was this helpful?

Alertmanager已经内置了对企业微信的支持,我们可以通过企业微信来管理报警,更进一步可以通过企业微信和微信的互通来直接将告警消息转发到个人微信上。

中给出了企业微信的相关配置说明

# Whether or not to notify about resolved alerts.
[ send_resolved: <boolean> | default = false ]

# The API key to use when talking to the WeChat API.
[ api_secret: <secret> | default = global.wechat_api_secret ]

# The WeChat API URL.
[ api_url: <string> | default = global.wechat_api_url ]

# The corp id for authentication.
[ corp_id: <string> | default = global.wechat_api_corp_id ]

# API request data as defined by the WeChat API.
[ message: <tmpl_string> | default = '{{ template "wechat.default.message" . }}' ]
[ agent_id: <string> | default = '{{ template "wechat.default.agent_id" . }}' ]
[ to_user: <string> | default = '{{ template "wechat.default.to_user" . }}' ]
[ to_party: <string> | default = '{{ template "wechat.default.to_party" . }}' ]
[ to_tag: <string> | default = '{{ template "wechat.default.to_tag" . }}' ]
global:
  resolve_timeout: 10m
  wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
  wechat_api_secret: '应用的secret,在应用的配置页面可以看到'
  wechat_api_corp_id: '企业id,在企业的配置页面可以看到'
templates:
- '/etc/alertmanager/config/*.tmpl'
route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 12h
  routes:
  - receiver: 'wechat'
    continue: true
inhibit_rules:
- source_match:
receivers:
- name: 'wechat'
  wechat_configs:
  - send_resolved: false
    corp_id: '企业id,在企业的配置页面可以看到'
    to_user: '@all'
    to_party: ' PartyID1 | PartyID2 '
    message: '{{ template "wechat.default.message" . }}'
    agent_id: '应用的AgentId,在应用的配置页面可以看到'
    api_secret: '应用的secret,在应用的配置页面可以看到'

配置模板示例如下:

{{ define "wechat.default.message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
{{- range $index, $alert := .Alerts -}}
{{- if eq $index 0 -}}
告警类型: {{ $alert.Labels.alertname }}
告警级别: {{ $alert.Labels.severity }}

=====================
{{- end }}
===告警详情===
告警详情: {{ $alert.Annotations.message }}
故障时间: {{ $alert.StartsAt.Format "2006-01-02 15:04:05" }}
===参考信息===
{{ if gt (len $alert.Labels.instance) 0 -}}故障实例ip: {{ $alert.Labels.instance }};{{- end -}}
{{- if gt (len $alert.Labels.namespace) 0 -}}故障实例所在namespace: {{ $alert.Labels.namespace }};{{- end -}}
{{- if gt (len $alert.Labels.node) 0 -}}故障物理机ip: {{ $alert.Labels.node }};{{- end -}}
{{- if gt (len $alert.Labels.pod_name) 0 -}}故障pod名称: {{ $alert.Labels.pod_name }}{{- end }}
=====================
{{- end }}
{{- end }}

{{- if gt (len .Alerts.Resolved) 0 -}}
{{- range $index, $alert := .Alerts -}}
{{- if eq $index 0 -}}
告警类型: {{ $alert.Labels.alertname }}
告警级别: {{ $alert.Labels.severity }}

=====================
{{- end }}
===告警详情===
告警详情: {{ $alert.Annotations.message }}
故障时间: {{ $alert.StartsAt.Format "2006-01-02 15:04:05" }}
恢复时间: {{ $alert.EndsAt.Format "2006-01-02 15:04:05" }}
===参考信息===
{{ if gt (len $alert.Labels.instance) 0 -}}故障实例ip: {{ $alert.Labels.instance }};{{- end -}}
{{- if gt (len $alert.Labels.namespace) 0 -}}故障实例所在namespace: {{ $alert.Labels.namespace }};{{- end -}}
{{- if gt (len $alert.Labels.node) 0 -}}故障物理机ip: {{ $alert.Labels.node }};{{- end -}}
{{- if gt (len $alert.Labels.pod_name) 0 -}}故障pod名称: {{ $alert.Labels.pod_name }};{{- end }}
=====================
{{- end }}
{{- end }}
{{- end }}

这时如果某一容器频繁重启,可以接收到如下的告警内容:

企业微信相关概念说明请参考,可以在企业微信的后台中建立多个应用,每个应用对应不同的报警分组,由企业微信来做接收成员的划分。具体配置参考如下:

prometheus官网
企业微信API说明
告警