prometheus告警发送到钉钉群机器人的全部署流程

这篇具有很好参考价值的文章主要介绍了prometheus告警发送到钉钉群机器人的全部署流程。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前置条件:prometheus安装完成,创建钉钉群机器人,我这里使用的是指定ip的方式

定义告警规则

修改Prometheus配置文件prometheus.yml,添加以下配置:

rule_files:
  - /usr/local/prometheus/rules/*.rules

alerting:
  alertmanagers:
    - static_configs:
        - targets:
           - localhost:9093

在目录/usr/local/prometheus/rules/下创建告警文件hoststats-alert.rules内容如下:

groups:
- name: hostStatsAlert
  rules:
  - alert: hostCpuUsageAlert
    expr: sum by (instance) (avg without (cpu) (irate(node_cpu_seconds_total{mode!="idle"}[5m]))) > 0.5
    for: 1m
    labels:
      # 严重性
      severity: warning
    annotations:
      title: cpu飚高告警
      summary: "Instance {{ $labels.instance }} CPU usgae high"
      description: "{{ $labels.instance }} CPU usage above 50% (current value: {{ $value }})"
  - alert: hostMemUsageAlert
    expr: (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes)/node_memory_MemTotal_bytes > 0.85
    for: 1m
    labels:
      severity: warning
    annotations:
      title: 内存使用率飚高告警
      summary: "Instance {{ $labels.instance }} MEM usgae high"
      description: "{{ $labels.instance }} MEM usage above 85% (current value: {{ $value }})"

重启Prometheus后访问Prometheus http://127.0.0.1:9090/rules可以查看当前以加载的规则文件。

安装配置prometheus-webhook-dingtalk

wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v2.1.0/prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz
tar -zxvf prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz -C /usr/local
mv /usr/local/prometheus-webhook-dingtalk-2.1.0.linux-amd64 /usr/local/prometheus-webhook-dingtalk
cp /usr/local/prometheus-webhook-dingtalk/config.example.yml  /usr/local/prometheus-webhook-dingtalk/config.yml
vim config.yml      # 将配置文件修改成下面这样
## Request timeout
# timeout: 5s
 
## Uncomment following line in order to write template from scratch (be careful!)
#no_builtin_template: true
 
## Customizable templates path
templates:
  - contrib/templates/mytemplate.tmpl # 这里指向你生成的模板
 
## You can also override default template using `default_message`
## The following example to use the 'legacy' template from v0.3.0
#default_message:
#  title: '{{ template "legacy.title" . }}'
#  text: '{{ template "legacy.content" . }}'
 
## Targets, previously was known as "profiles"
targets:
  webhook1:
    # 钉钉机器人的webhook, 是从钉钉机器人中获取的值
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    # secret for signature 加签后得到的值, 机器人的加签
    # secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#  webhook2:
#    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
#  webhook_legacy:
#    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
#    # Customize template content
#    message:
#      # Use legacy template
#      title: '{{ template "legacy.title" . }}'
#      text: '{{ template "legacy.content" . }}'
#  webhook_mention_all:
#    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
#    mention:
#      all: true
#  webhook_mention_users:
#    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
#    mention:
#      mobiles: ['156xxxx8827', '189xxxx8325']
# 添加如下模板,模板中需要有prometheus添加的 Annotations中需要title、description;Labels中需要有severity
vim /usr/local/prometheus-webhook-dingtalk/contrib/templates/mytemplate.tmpl

cd /usr/local/prometheus-webhook-dingtalk/

./prometheus-webhook-dingtalk --config.file=config.yml >dingtalk.log 2>&1 &
{{ define "__subject" }}
[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}]
{{ end }}
 
 
{{ define "__alert_list" }}{{ range . }}
---
{{ if .Labels.owner }}@{{ .Labels.owner }}{{ end }}

**告警名称**: {{ index .Annotations "title" }} 
 
**告警级别**: {{ .Labels.severity }} 
 
**告警主机**: {{ .Labels.instance }} 
 
**告警信息**: {{ index .Annotations "description" }}
 
**告警时间**: {{ dateInZone "2006.01.02 15:04:05" (.StartsAt) "Asia/Shanghai" }}
{{ end }}{{ end }}
 
{{ define "__resolved_list" }}{{ range . }}
---
{{ if .Labels.owner }}@{{ .Labels.owner }}{{ end }}
 
**告警名称**: {{ index .Annotations "title" }}
 
**告警级别**: {{ .Labels.severity }}
 
**告警主机**: {{ .Labels.instance }}
 
**告警信息**: {{ index .Annotations "description" }}
 
**告警时间**: {{ dateInZone "2006.01.02 15:04:05" (.StartsAt) "Asia/Shanghai" }}
 
**恢复时间**: {{ dateInZone "2006.01.02 15:04:05" (.EndsAt) "Asia/Shanghai" }}
{{ end }}{{ end }}
 
 
{{ define "default.title" }}
{{ template "__subject" . }}
{{ end }}
 
{{ define "default.content" }}
{{ if gt (len .Alerts.Firing) 0 }}
**====侦测到{{ .Alerts.Firing | len  }}个故障====**
{{ template "__alert_list" .Alerts.Firing }}
---
{{ end }}
 
{{ if gt (len .Alerts.Resolved) 0 }}
**====恢复{{ .Alerts.Resolved | len  }}个故障====**
{{ template "__resolved_list" .Alerts.Resolved }}
{{ end }}
{{ end }}
 
 
{{ define "ding.link.title" }}{{ template "default.title" . }}{{ end }}
{{ define "ding.link.content" }}{{ template "default.content" . }}{{ end }}
{{ template "default.title" . }}
{{ template "default.content" . }}

安装配置prometheus-alertmanager

wget https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-amd64.tar.gz
tar -zxvf alertmanager-0.25.0.linux-amd64.tar.gz 
mv alertmanager-0.25.0.linux-amd64 /usr/local/alertmanager
# 修改告警管理的配置文件如下
vim /usr/local/alertmanager/alertmanager.yml
cd /usr/local/alertmanager/
./alertmanager --config.file=alertmanager.yml >alertmanager.log 2>&1 &
global:
  #每一分钟检查一次是否恢复
  resolve_timeout: 5m
route:
  #采用哪个标签来作为分组依据
  group_by: ['alertname']
  #组告警等待时间。也就是告警产生后等待10s,如果有同组告警一起发出
  group_wait: 10s
  #两组告警的间隔时间
  group_interval: 1m
  #重复告警的间隔时间,减少相同告警的发送频率
  repeat_interval: 1m
  #设置默认接收人
  receiver: 'web.hook'
  routes:
  - receiver: 'dingding.webhook1'
    match_re:
      alertname: ".*"
receivers:
- name: 'web.hook'
  webhook_configs:
  - url: 'http://127.0.0.1:5001/'
- name: 'dingding.webhook1'
  webhook_configs:
  # 这里的webhook1,根据我们在钉钉告警插件配置文件中targets中指定的值做修改
  - url: 'http://127.0.0.1:8060/dingtalk/webhook1/send'
    send_resolved: true
inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'dev', 'instance']

此时,我们可以手动拉高系统的CPU使用率,验证Prometheus的告警流程,在主机上运行以下命令:

cat /dev/zero>/dev/null

Prometheus首次检测到满足触发条件后,hostCpuUsageAlert显示由一条告警处于活动状态。由于告警规则中设置了1m的等待时间,当前告警状态为PENDING,可在下图位置可见
prometheus告警发送到钉钉群机器人的全部署流程
等待告警状态为firing后钉钉群机器人会发出告警信息

springboot应用埋点在下篇文章
文章来源地址https://www.toymoban.com/news/detail-507297.html

到了这里,关于prometheus告警发送到钉钉群机器人的全部署流程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • prometheus监控k8s服务并告警到钉钉

    一、监控k8s集群 要监控k8s集群需要使用到以下服务用于收集监控的资源信息,node_exporter用于监控k8s集群节点的资源信息,kube-state-metrics用于监控k8s集群的deployment、statefulset、daemonset、pod等的状态,cadvisor用于监控k8s集群的pod资源信息 在k8s集群中创建monitoring的命名空间用于部

    2024年02月13日
    浏览(33)
  • Outlook无需API开发连接钉钉群机器人,实现新增会议日程自动发送群消息通知

    Outlook用户使用场景: 在企业中,会议和活动的顺利举行对于业务运转和团队协作至关重要。然而,计划的变动总是无法避免,这可能会导致其他人的计划受到影响,打乱原有的安排。为了解决这个问题,许多企业开始使用各种工具和技术来确保信息的及时传递和更新。其中

    2024年02月09日
    浏览(31)
  • 钉钉小程序生态5—钉钉群机器人消息通知和钉钉工作通知

    钉钉小程序生态1—区分企业内部应用、第三方企业应用、第三方个人应用 钉钉小程序生态2—区分小程序和H5微应用 钉钉小程序生态3—钉钉扫码登录PC端网站 钉钉小程序生态4—钉钉小程序三方企业应用事件与回调 钉钉小程序生态5—钉钉群机器人消息通知和钉钉工作通知 钉

    2024年02月09日
    浏览(73)
  • 快手无需代码连接钉钉群机器人的方法

    快手用户使用场景: 对于视频运营人员来说,每当在快手平台上发布视频进行推广后,常需要关注视频的播放量,点赞量,转发量以及评论等,然后将数据发送到部门群,便于运营人员分析,做好后续策略调整。随着公司的快速发展,公司每天需要发布多个视频,同时还需要

    2024年02月11日
    浏览(50)
  • java实现钉钉群机器人@机器人获取信息后,机器人回复(机器人接收消息)

    1.需求 鉴于需要使用钉钉群机器人回复,人们提出的问题,需要识别提出的问题中的,后端进行处理实现对应的业务逻辑 2.实现方式 用户@群机器人,附带提出的问题,后端接收消息后识别消息内容,读取到进行对应的业务逻辑操作后,机器人获取返回的信息后

    2024年02月14日
    浏览(39)
  • linux环境下监控docker进程运行情况,使用钉钉群机器人报警异常服务

    背景:在linux环境下,很多服务我们都使用docker来跑,很是方便,容器服务独立,配置独立,数据独立等等,但是有个问题,就是如果某个服务异常了,暂停了,停止了,一直重启中,我们要怎么及时的知道是哪个服务,并进行处理,保证业务正常运行。 本文主要介绍使用

    2024年02月13日
    浏览(34)
  • zabbix配置钉钉机器人告警

    1.在钉钉上创建一个钉钉群组 2.在群组中添加一个机器人           3.配置zabbix server调用钉钉接口的代码( 使用python ) 查看是否有python环境 python --version  找到zabbix 的AlertScriptsPath目录路径  cat /etc/zabbix/zabbix_server.conf|grep AlertScriptsPath 将调用钉钉接口的python文件放在AlertScripts

    2024年02月11日
    浏览(35)
  • prometheusalert区分告警到不同钉钉群

    根据Kind区分,规则一kind1,规则二是kind2。 route:除了email这个全局配置的接收者外,下面的routes指定了两个特定的接收者,一个接收者叫“our”,匹配warning级别的;另一个叫“other”,匹配busi级别的,这两个级别在最前面的规则里定义,不是什么特定,就是自己随便定

    2024年02月12日
    浏览(36)
  • 企业微信,阿里钉钉告警群机器人

    链接:如何通过企业微信群接收报警通知_云监控-阿里云帮助中心

    2024年02月15日
    浏览(25)
  • shell脚本实现告警消息推送钉钉机器人

    一、准备钉钉机器人         钉钉创建群聊                  群设置、智能群助手、添加机器人         机器人类型选择 自定义 (通过webhook接入自定义服务)         添加到刚才创建的群组、安全设置选择自定义 ( 将设置为告警二字,有用),配

    2024年02月14日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包