prometheusalert区分告警到不同钉钉群

方法一

修改告警规则

- alert: cpu使用率大于88%expr: instance:node_cpu_utilization:ratio * 100 > 88for: 5mlabels:severity: criticallevel: 3kind: CpuUsageannotations:summary: "cpu使用率大于85%"description: "主机 {{ $labels.hostname }} 的cpu使用率为 {{ $value | humanize }}"

根据Kind区分,规则一kind1,规则二是kind2。

alertmanager配置示例

global:resolve_timeout: 5msmtp_from: from@email.comsmtp_smarthost: smtp.net:portsmtp_auth_username: from@email.comsmtp_auth_password: PASSsmtp_require_tls: false
route:receiver: 'email'group_by: ['alertname']group_wait: 10sgroup_interval: 10srepeat_interval: 10mroutes:- receiver: 'our'group_wait: 10smatch_re:severity: warning- receiver: 'other'group_wait: 10smatch_re:severity: busitemplates:- '*.html'
receivers:
- name: 'email'email_configs:- to: 'xuxd@email.com'send_resolved: falsehtml: '{{ template "default-monitor.html" . }}'headers: { Subject: "[WARN] 报警邮件" } #邮件主题
- name: 'our'webhook_configs:- url: http://127.0.0.1:8060/dingtalk/our/send
- name: 'other'webhook_configs:- url: http://127.0.0.1:8060/dingtalk/other/send
  • route:除了email这个全局配置的接收者外,下面的routes指定了两个特定的接收者,一个接收者叫“our”,匹配warning级别的;另一个叫“other”,匹配busi级别的,这两个级别在最前面的规则里定义,不是什么特定关键字,就是自己随便定义的一个标记
  • receivers:这里指定了上面定义的接收者的配置,email指定邮件发给谁;“our”指定dingtalk的发送url,注意这个uri的末尾,send前用的"our";“other”下面指定了两个url,区别就是url末尾的send前面,一个是“our”,另一个是"other"

prometheus-webhook-dingtalk配置

## Customizable templates path
templates:- /home/user/monitor/alert/prometheus-webhook-dingtalk-1.4.0.linux-amd64/template/template.tmpl## Targets, previously was known as "profiles"
targets:our:url: https://oapi.dingtalk.com/robot/send?access_token=xxxxsecret: xxx_secretother:url: https://oapi.dingtalk.com/robot/send?access_token=xxx_othersecret: xxx_other_secret

targets下有两个,分别是"our"和"other",这里对应上面alertmanager配置的url里的"our"和"other。

这样配置,如果规则一告警,就是alertmanager的name为other的receiver来发送告警通知,发送到我们的钉钉群和业务侧钉钉群。如果是规则二告警,通过our发送,便只发送到我们的钉钉群。

vmalert配置文件value.yaml

# Default values for victoria-metrics-alert.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.serviceAccount:# Specifies whether a service account should be createdcreate: true# Annotations to add to the service accountannotations: {}# The name of the service account to use.# If not set and create is true, a name is generated using the fullname templatename:# mount API token to pod directlyautomountToken: trueimagePullSecrets: []rbac:create: truepspEnabled: truenamespaced: falseextraLabels: {}annotations: {}server:name: serverenabled: trueimage:repository: victoriametrics/vmalerttag: "" # rewrites Chart.AppVersionpullPolicy: IfNotPresentnameOverride: ""fullnameOverride: ""## See `kubectl explain poddisruptionbudget.spec` for more## ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/podDisruptionBudget:enabled: false# minAvailable: 1# maxUnavailable: 1labels: {}# -- Additional environment variables (ex.: secret tokens, flags) https://github.com/VictoriaMetrics/VictoriaMetrics#environment-variablesenv:[]# - name: VM_remoteWrite_basicAuth_password#   valueFrom:#     secretKeyRef:#       name: auth_secret#       key: passwordreplicaCount: 1# deployment strategy, set to standard k8s defaultstrategy:type: RollingUpdaterollingUpdate:maxSurge: 25%maxUnavailable: 25%# specifies the minimum number of seconds for which a newly created Pod should be ready without any of its containers crashing/terminating# 0 is the standard k8s defaultminReadySeconds: 0# vmalert reads metrics from source, next section represents its configuration. It can be any service which supports# MetricsQL or PromQL.datasource:url: "http://192.168.47.9:8481/select/0/prometheus/"basicAuth:username: ""password: ""remote:write:url: ""read:url: ""notifier:alertmanager:url: "http://x.x.x.x:9093"extraArgs:envflag.enable: "true"envflag.prefix: VM_loggerFormat: json# Additional hostPath mountsextraHostPathMounts:[]# - name: certs-dir#   mountPath: /etc/kubernetes/certs#   subPath: ""#   hostPath: /etc/kubernetes/certs#   readOnly: true# Extra Volumes for the podextraVolumes:[]#- name: example#  configMap:#    name: example# Extra Volume Mounts for the containerextraVolumeMounts:[]# - name: example#   mountPath: /exampleextraContainers:[]#- name: config-reloader#  image: reloader-imageservice:annotations: {}labels: {}clusterIP: ""## Ref: https://kubernetes.io/docs/user-guide/services/#external-ips##externalIPs: []loadBalancerIP: ""loadBalancerSourceRanges: []servicePort: 8880type: ClusterIP# Ref: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip# externalTrafficPolicy: "local"# healthCheckNodePort: 0ingress:enabled: falseannotations: {}#   kubernetes.io/ingress.class: nginx#   kubernetes.io/tls-acme: 'true'extraLabels: {}hosts: []#   - name: vmselect.local#     path: /select#     port: httptls: []#   - secretName: vmselect-ingress-tls#     hosts:#       - vmselect.local# For Kubernetes >= 1.18 you should specify the ingress-controller via the field ingressClassName# See https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#specifying-the-class-of-an-ingress# ingressClassName: nginx# -- pathType is only for k8s >= 1.1=pathType: PrefixpodSecurityContext: {}# fsGroup: 2000securityContext:{}# capabilities:#   drop:#   - ALL# readOnlyRootFilesystem: true# runAsNonRoot: true# runAsUser: 1000resources:{}# We usually recommend not to specify default resources and to leave this as a conscious# choice for the user. This also increases chances charts run on environments with little# resources, such as Minikube. If you do want to specify resources, uncomment the following# lines, adjust them as necessary, and remove the curly braces after 'resources:'.# limits:#   cpu: 100m#   memory: 128Mi# requests:#   cpu: 100m#   memory: 128Mi# Annotations to be added to the deploymentannotations: {}# labels to be added to the deploymentlabels: {}# Annotations to be added to podpodAnnotations: {}podLabels: {}nodeSelector: {}priorityClassName: ""tolerations: []affinity: {}# vmalert alert rules configuration configuration:# use existing configmap if specified# otherwise .config values will be usedconfigMap: ""config:alerts:groups:- name: 磁盘挂载错误rules:- alert: 磁盘挂载错误annotations:description: '{{$labels.job}}链{{$labels.instance}}节点磁盘挂载错误'expr: mount_error{job=~"dev|sit"} == 1for: 1mlabels:severity: criticalkind: kind1- name: 进程不存在rules:- alert: 进程不存在annotations:description: '{{$labels.job}}链{{$labels.instance}}进程不存在'expr: process_total_error{job=~"dev|sit"} == 1for: 1mlabels:severity: criticalkind: kind2serviceMonitor:enabled: falseextraLabels: {}annotations: {}
#    interval: 15s
#    scrapeTimeout: 5s# -- Commented. HTTP scheme to use for scraping.
#    scheme: https# -- Commented. TLS configuration to use when scraping the endpoint
#    tlsConfig:
#      insecureSkipVerify: truealertmanager:enabled: truereplicaCount: 1podMetadata:labels: {}annotations: {}image: prom/alertmanagertag: v0.20.0retention: 120hnodeSelector: {}priorityClassName: ""resources: {}tolerations: []imagePullSecrets: []podSecurityContext: {}extraArgs: {}# key: value# external URL, that alertmanager will expose to receiversbaseURL: ""# use existing configmap if specified# otherwise .config values will be usedconfigMap: ""config:global:resolve_timeout: 5mroute:# default receiverreceiver: aldaba# tag to group bygroup_by: [alertname]# How long to initially wait to send a notification for a group of alertsgroup_wait: 30s# How long to wait before sending a notification about new alerts that are added to a groupgroup_interval: 60s# How long to wait before sending a notification again if it has already been sent successfully for an alertrepeat_interval: 1hroutes:- receiver: 'mychain'group_wait: 10smatch_re:kind: mychainreceivers:- name: aldabawebhook_configs:- url: http://192.168.208.133:8080/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=https://oapi.dingtalk.com/robot/send?access_token=72a3a55795094a6878c2c2443a81a3545add1f688ddee18701c0dd753dbb3b2a&split=falsesend_resolved: true- name: mychainwebhook_configs:- url: http://192.168.208.133:8080/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=https://oapi.dingtalk.com/robot/send?access_token=307270fdcd1bb0c4b0533e29005cca7cb353c27d7f988fdff0ec00e6affc6e83&split=falsesend_resolved: trueinhibit_rules:- source_match:#severity: 'warning'target_match:#severity: 'warning'#equal: ['alertname', 'job']templates: {}#  alertmanager.tmpl: |-service:annotations: {}type: ClusterIPport: 9093# if you want to force a specific nodePort. Must be use with service.type=NodePort# nodePort:ingress:enabled: falseannotations:#  nginx.ingress.kubernetes.io/auth-realm: Authentication Required#  nginx.ingress.kubernetes.io/auth-secret: victoria-metrics/basic-auth#  nginx.ingress.kubernetes.io/auth-type: basic#   kubernetes.io/ingress.class: nginx#   kubernetes.io/tls-acme: 'true'extraLabels: {}hosts: {}#   - name: wangjuan.test.com#    path: /#     port: webtls: []#   - secretName: alertmanager-ingress-tls#     hosts:#       - alertmanager.local# For Kubernetes >= 1.18 you should specify the ingress-controller via the field ingressClassName# See https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#specifying-the-class-of-an-ingress# ingressClassName: nginx# -- pathType is only for k8s >= 1.1=pathType: PrefixpersistentVolume:# -- Create/use Persistent Volume Claim for alertmanager component. Empty dir if falseenabled: false# -- Array of access modes. Must match those of existing PV or dynamic provisioner. Ref: [http://kubernetes.io/docs/user-guide/persistent-volumes/](http://kubernetes.io/docs/user-guide/persistent-volumes/)accessModes:- ReadWriteOnce# -- Persistant volume annotationsannotations: {}# -- StorageClass to use for persistent volume. Requires alertmanager.persistentVolume.enabled: true. If defined, PVC created automaticallystorageClass: ""# -- Existing Claim name. If defined, PVC must be created manually before volume will be boundexistingClaim: ""# -- Mount path. Alertmanager data Persistent Volume mount root path.mountPath: /data# -- Mount subpathsubPath: ""# -- Size of the volume. Better to set the same as resource limit memory property.size: 50Mi

方法二

根据job过滤

alertmanager配置

apiVersion: v1
data:alertmanager.yaml: |-global:resolve_timeout: 5minhibit_rules:- equal:- alertname- jobsource_match:severity: warningtarget_match:severity: warningreceivers:- name: nftwebhook_configs:- send_resolved: falseurl: http://x.x.x.x:8080/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxx&split=false- name: poapwebhook_configs:- send_resolved: falseurl: http://x.x.x.x:8080/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxx&split=false- name: ipforcewebhook_configs:- send_resolved: falseurl: http://x.x.x.x:8080/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxx&split=falseroute:group_by:- alertnamegroup_interval: 60sgroup_wait: 30sreceiver: nftrepeat_interval: 1hroutes:- group_wait: 10smatch_re:job: test_poapreceiver: poap- group_wait: 10smatch_re:job: test_ipforcereceiver: ipforce
kind: ConfigMap
metadata:annotations:meta.helm.sh/release-name: vmalertmeta.helm.sh/release-namespace: victoria-metricscreationTimestamp: '2022-04-06T07:31:38Z'labels:app: alertmanagerapp.kubernetes.io/instance: vmalertapp.kubernetes.io/managed-by: Helmapp.kubernetes.io/name: victoria-metrics-alerthelm.sh/chart: victoria-metrics-alert-0.4.33managedFields:- apiVersion: v1fieldsType: FieldsV1fieldsV1:'f:data': {}'f:metadata':'f:annotations':.: {}'f:meta.helm.sh/release-name': {}'f:meta.helm.sh/release-namespace': {}'f:labels':.: {}'f:app': {}'f:app.kubernetes.io/instance': {}'f:app.kubernetes.io/managed-by': {}'f:app.kubernetes.io/name': {}'f:helm.sh/chart': {}manager: helmoperation: Updatetime: '2022-04-06T07:31:38Z'- apiVersion: v1fieldsType: FieldsV1fieldsV1:'f:data':'f:alertmanager.yaml': {}manager: ACK-Console Apache-HttpClientoperation: Updatetime: '2023-01-05T07:52:13Z'name: vmalert-alertmanager-alertmanager-confignamespace: victoria-metricsresourceVersion: '80954053'uid: 653e4633-86e5-41ce-9a17-301f75224e9c

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/39497.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

99%的Python用户都不知道的f-string隐秘技巧

f-string想必很多Python用户都基础性的使用过,作为Python3.6版本开始引入的特性,通过它我们可以更加方便地向字符串中嵌入自定义内容,但f-string真正蕴含的功能远比大多数用户知道的要丰富,今天我们就来一起get它们~ 「最基础用法…

ajax解析

Ajax(Asynchronous JavaScript and XML)是一种用于在不重新加载整个页面的情况下与服务器交换数据的技术。它通过异步的方式发送请求和接收响应,能够实现在后台与服务器进行数据交互,然后更新页面的部分内容,从而提升用…

【CI/CD】基于 Jenkins+Docker+Git 的简单 CI 流程实践(上)

基于 JenkinsDockerGit 的简单 CI 流程实践(上) 在如今的互联网时代,随着软件开发复杂度的不断提高,软件开发和发布管理也越来越重要。目前已经形成一套标准的流程,最重要的组成部分就是 持续集成 及 持续交付、部署。…

GPU编程基础-CUDA实现图像处理

GPU编程基础-CUDA实现图像处理 1. 相关基础概念1.1 Host和Device程序1.2 Kernel程序1.3 SIMT和SIMD1.4 GPU计算的 Occupancy指标1.5 GPU计算的基本流程2. GPU计算框架与过程说明3. 一个基于CUDA的图像处理例子4. 一些报错解决1. 相关基础概念 1.1 Host和Device程序 在CPU上运行…

Effective C++学习笔记(7)

目录 条款41:了解隐式接口和编译多态条款42:了解typename的双重意义条款43:学习处理模板化基类内的名称条款44:将与参数无关的代码抽离templates条款45:运用成员函数模板接受所有兼容类型条款46:需要类型转…

opencv,opengl,osg,vulkan,webgL,opencL,cuda,osg,vtk,ogre的区别

OpenCV OpenCV是一个基于BSD许可(开源)发行的跨平台计算机视觉和机器学习软件库,可以运行在Linux、Windows、Android和Mac OS操作系统上。 它轻量级而且高效——由一系列 C 函数和少量 C 类构成,同时提供了Python、Ruby、MATLAB等…

avue多选列表根据后端返回的某个值去判断是否选中;avue-curd多选回显

效果如上: getSiteList().then(res > {//列表数据this.siteData res.data.datathis.$nextTick(()>{this.siteData.forEach(item>{//业务条件if(item.configid&&item.configid!0&&item.configid>0){//符合条件时调用选中的方法this.$…

JAVASE---数组的定义与使用

数组的基本概念 什么是数组 数组是具有相同类型元素的集合,在内存中连续存储。 1. 数组中存放的元素其类型相同 2. 数组的空间是连在一起的 3. 每个空间有自己的编号,起始位置的编号为0,即数组的下标 数组的创建及初始化 数组的创建 T[…

mybatis高级特性

文章目录 数据库事务管理批处理插件扩展持久化和ORM缓存机制 数据库事务管理 通过注解方式: 在需要进行事务管理的方法上添加Transactional注解,该注解可以用于类或方法上。在配置文件中开启事务管理器,并指定事务管理器的类型和连接池等相关…

Java SpringBoot Vue智能停车系统

基础环境 JDK1.8、Maven、Mysql、IntelliJ IDEA 内置功能 系统管理:角色管理、接口管理、系统菜单、全局配置 账号管理:用户管理、合作单位 系统监控:监控大屏、日志监控 财务管理:订单列表 停车记录:停车记录 车辆管…

Labview选项卡之实现被选择选项卡工作

文章目录 前言一、使用选项卡二、实现被选择选项卡工作1、需求2、分析3、实现①、前面板②、程序框图 三、效果展示四、源码自取 前言 有些时候,我们做界面,需要好多个界面切换。如果是同一个 VI 里界面切换,一般都是选项卡了。切换不同选项…

使用phpstorm开发调试thinkphp

1.环境准备 1.开发工具下载:PhpStorm: PHP IDE and Code Editor from JetBrains 2.PHP下载:PHP: Downloads 3. PHP扩展:PECL :: Package search 4.用与调试的xdebug模块: Xdebug: Downloads xdebug模块,如果是php8以…

23.8.16日总结

原先写的评论是每级评论用缩进来区分,所以最多设置的是九级评论,修改了排版和格式: 还有管理员页面,查看文章时可以进行点赞,收藏的操作,现在进行了修改,将相关操作隐藏。 还有点击查看未发布…

js如何获取字符串大小是几M

js如何获取字符串大小是几M 在JavaScript中,可以使用以下方法来获取字符串的大小(以字节为单位): function getStringSizeInBytes(str) {// 使用UTF-8编码计算字符串的字节长度let totalBytes new Blob([str]).size;// 将字节长…

14-矩阵相乘及其运算法则

矩阵与向量的乘法 在这一篇文章中我们就将基于上一篇重新审视矩阵的这个视点来理解矩阵的乘法,那么在这一篇,我们主要来看一下矩阵和向量的乘法。这里这个线性方程组是上一小节给大家举的模拟的一个非常简单的小型经济系统的例子,我们可以把…

文件的导入与导出

文章目录 一、需求二、分析1. Excel 表格数据导出2. Excel 表格数据导入一、需求 在我们日常开发中,会有文件的导入导出的需求,如何在 vue 项目中写导入导出功能呢 二、分析 以 Excel 表格数据导出为例 1. Excel 表格数据导出 调用接口将返回的数据进行 Blob 转换,附: 接…

logstash日志换行处理小解

logstash主用于日志实时数据收集、解析,并将数据转发的工具,内置的功能也相当强大。但,同时意味着,他可能接收到各种情况的数据。 此处,我们主要讲解我实际使用中,碰到的一个小问题,换行(\n)。…

redis 和 mongodb 比较

Redis和MongoDB是两种不同类型的数据库,它们在数据存储和查询方式、数据模型以及适用场景等方面有一些明显的区别。下面是Redis和MongoDB之间的一些比较: 数据模型: Redis:Redis是一个键值存储系统,支持多种数据结构如…

FPGA应用学习笔记--时钟域的控制 亚稳态的解决

时钟域就是同一个时钟的区域,体现在laways语句边缘触发语句中,设计规模增大就会导致时钟不同步,有时差,就要设计多时钟域。 会经过与门的延时产生的新时钟域,这种其实不推荐使用,但在ascl里面很常见 在处理…

八大排序超详解(动图+源码)

💓博主个人主页:不是笨小孩👀 ⏩专栏分类:数据结构与算法👀 刷题专栏👀 C语言👀 🚚代码仓库:笨小孩的代码库👀 ⏩社区:不是笨小孩👀 🌹欢迎大家三连关注&…