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.pswp.cn/news/39497.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/39497.shtml
英文地址,請注明出處:http://en.pswp.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語言👀 🚚代碼倉庫:笨小孩的代碼庫👀 ?社區:不是笨小孩👀 🌹歡迎大家三連關注&…