kube-prometheus实现企业微信机器人告警

公司kubernetes生产环境部署了kube-prometheus-release-0.3用于监控kubernetes集群状态,但是默认预置了告警规则,但是不能发送告警信息。本文着重介绍自己在公司环境实现alertmanager通过企业微信发送告警信息。具体实现方式的逻辑如下图:

 实现方式:

1.查看部署的kube-prometheus

[root@k8s-master-03 kube-prometheus-release-0.3]# kubectl get pod -n monitoring
NAME                                       READY   STATUS    RESTARTS   AGE
alertmanager-main-0                        2/2     Running   0          6h20m
alertmanager-main-1                        2/2     Running   0          6h20m
alertmanager-main-2                        2/2     Running   0          6h2m
grafana-77978cbbdc-x9qpp                   1/1     Running   0          5d22h
kube-state-metrics-7f6d7b46b4-nnjrs        3/3     Running   0          5d22h
node-exporter-42hpk                        2/2     Running   0          5d22h
node-exporter-5d99p                        2/2     Running   0          5d22h
node-exporter-5fcd8                        2/2     Running   0          5d22h
node-exporter-66mxt                        2/2     Running   0          5d22h
node-exporter-6tcg6                        2/2     Running   0          5d22h
node-exporter-8dkc2                        2/2     Running   0          5d22h
node-exporter-8wrq5                        2/2     Running   0          5d22h
node-exporter-9z778                        2/2     Running   0          5d22h
node-exporter-b2lpm                        2/2     Running   0          5d22h
node-exporter-dvfmw                        2/2     Running   0          5d22h
node-exporter-f794p                        2/2     Running   0          5d22h
node-exporter-frfzm                        2/2     Running   0          5d22h
node-exporter-hffpg                        2/2     Running   0          5d22h
node-exporter-hkhkh                        2/2     Running   0          5d22h
node-exporter-jjszd                        2/2     Running   0          5d22h
node-exporter-lgslx                        2/2     Running   0          5d22h
node-exporter-nxdtj                        2/2     Running   0          5d22h
node-exporter-q458q                        2/2     Running   0          5d22h
node-exporter-r6mff                        2/2     Running   0          5d22h
node-exporter-s9jw2                        2/2     Running   0          5d22h
node-exporter-vfp24                        2/2     Running   0          5d22h
node-exporter-w2q6g                        2/2     Running   0          5d22h
node-exporter-xgmn5                        2/2     Running   0          5d22h
prometheus-adapter-68698bc948-xtnvm        1/1     Running   0          5d22h
prometheus-k8s-0                           3/3     Running   1          5d1h
prometheus-k8s-1                           3/3     Running   0          5d2h
prometheus-operator-6685db5c6-4zwcn        1/1     Running   0          5d22h

2.在企业微信群聊创建机器人

 3.创建webhook服务,用于转发alertmanager的告警消息到企业微信机器人

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: prometheus-webhook-qywx
  name: prometheus-webhook-qywx
  namespace: monitoring
spec:
  selector:
    matchLabels:
      run: prometheus-webhook-qywx
  template:
    metadata:
      labels:
        run: prometheus-webhook-qywx
    spec:
      containers:
      - args:
        - --adapter=/app/prometheusalert/wx.js=/adapter/wx=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c3578c16-1a8e-ssssdddd8888888  #注意变更这个地址,即企业微信机器人的webhook地址
        image: registry.cn-hangzhou.aliyuncs.com/guyongquan/webhook-adapter  
        name: prometheus-webhook-dingtalk
        ports:
        - containerPort: 80
          protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: prometheus-webhook-qywx
  name: prometheus-webhook-qywx
  namespace: monitoring
spec:
  ports:
  - port: 8060
    protocol: TCP
    targetPort: 80
  selector:
    run: prometheus-webhook-qywx
  type: ClusterIP

备注:

adapter=/app/prometheusalert/wx.js=/adapter/wx=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c3578c16-1a8e-ssssdddd8888888  #注意变更这个地址,即企业微信机器人的webhook地址  

4.报警方式,即alertmanager的配置文件变更

变更命名空间monitoring下的alertmanager-main的secret,这个是alertmanager的配置文件

默认安装的时候,缺省配置为

"global":
  "resolve_timeout": "5m"
"receivers":
- "name": "null"
"route":
  "group_by":
  - "job"
  "group_interval": "5m"
  "group_wait": "30s"
  "receiver": "null"
  "repeat_interval": "12h"
  "routes":
  - "match":
      "alertname": "Watchdog"
    "receiver": "null"

根据需求变更为

"global":
  "resolve_timeout": "5m"
"receivers":
- name: 'web.hook'
  webhook_configs:
  - url: 'http://prometheus-webhook-qywx.monitoring.svc.cluster.local:8060/adapter/wx'               # 刚刚创建的webhook地址
    send_resolved: false
"route":
  "group_by":
  - "job"
  - "namespaces"
  - "alertname"
  "group_interval": "5m"
  "group_wait": "30s"
  "receiver": "web.hook"
  "repeat_interval": "10m"
  "routes":
  - "match":
      "alertname": "Watchdog"
    "receiver": "web.hook"

http://prometheus-webhook-qywx.monitoring.svc.cluster.local:8060 是上面创建的webhook转发服务的service

配置企业微信机器人告警时需要先安装webhook;最后重启alertmanger-main-0,alertmanger-main-1,alertmanger-main-3

5.查看企业微信机器人的告警信息

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
一、prometheus简介 Prometheus是一个开源的系统监控和告警系统,现在已经加入到CNCF基金会,成为继k8s之后第二个在CNCF维护管理的项目,在kubernetes容器管理系统中,通常会搭配prometheus进行监控,prometheus支持多种exporter采集数据,还支持通过pushgateway进行数据上报,Prometheus再性能上可支撑上万台规模的集群。 二、prometheus架构图 三、prometheus组件介绍 1.Prometheus Server: 用于收集和存储时间序列数据。 2.Client Library: 客户端库,检测应用程序代码,当Prometheus抓取实例的HTTP端点时,客户端库会将所有跟踪的metrics指标的当前状态发送到prometheus server端。 3.Exporters: prometheus支持多种exporter,通过exporter可以采集metrics数据,然后发送到prometheus server端 4.Alertmanager: 从 Prometheus server 端接收到 alerts 后,会进行去重,分组,并路由到相应的接收方,发出报警,常见的接收方式有:电子邮件,微信,钉钉, slack等。 5.Grafana:监控仪表盘 6.pushgateway: 各个目标主机可上报数据到pushgatewy,然后prometheus server统一从pushgateway拉取数据。 四、课程亮点 五、效果图展示 六、讲师简介 先超(lucky):高级运维工程师、资深DevOps工程师,在互联网上市公司拥有多年一线运维经验,主导过亿级pv项目的架构设计和运维工作 主要研究方向: 1.云计算方向:容器 (kubernetes、docker),虚拟化(kvm、Vmware vSphere),微服务(istio),PaaS(openshift),IaaS(openstack)等2.系统/运维方向:linux系统下的常用组件(nginx,tomcat,elasticsearch,zookeeper,kafka等),DevOps(Jenkins+gitlab+sonarqube+nexus+k8s),CI/CD,监控(zabbix、prometheus、falcon)等 七、课程大纲

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

忍冬行者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值