prometheusAlertManager微信報警配置-創(chuàng)新互聯(lián)

準(zhǔn)備工作:

成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供嘉蔭網(wǎng)站建設(shè)、嘉蔭做網(wǎng)站、嘉蔭網(wǎng)站設(shè)計、嘉蔭網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、嘉蔭企業(yè)網(wǎng)站模板建站服務(wù),10多年嘉蔭做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

獲取企業(yè)×××的對外接口

企業(yè)×××的secret_api

企業(yè)信息ID corp_id

wechat_api_url: wechat對外接口https://qyapi.weixin.qq.com/cgi-bin/
wechat_×××: 企業(yè)×××("企業(yè)應(yīng)用"-->"自定應(yīng)用"[Prometheus]--> "Secret") Prometheus是本人自創(chuàng)建應(yīng)用名稱
wechat_api_corp_id: 企業(yè)信息("我的企業(yè)"--->"CorpID"[在底部])
to_party: 1值是組的ID 你可通過鏈接去定制報警信息接收人或者組(https://work.weixin.qq.com/ap...
agent_id: 企業(yè)×××("企業(yè)應(yīng)用"-->"自定應(yīng)用"[Prometheus]--> "AgentId") Prometheus是本人自創(chuàng)建應(yīng)用名稱

如果prometheus和alertmanager的配置文件是分開(不是helm安裝)

Prometheus中AlertManager配置:

alerting?與?global同級

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- localhost:9093

rules配置文件加入到Prometheus配置文件中

rule_files:
- "/usr/local/prometheus/rules.yml"

prometheus rules配置
創(chuàng)建rule.yml文件
根據(jù)需求添加報警規(guī)則
groups:
- name: prometheus_go_goroutines
rules:
- alert: go_goroutines_numbers
expr: go_goroutines > 45
for: 15s
annotations:
summary: "prometheus的gorotine數(shù)據(jù)超過40!"

Prometheus AlertManager配置
alertmanager 配置文件,加入×××配置信息
global:
resolve_timeout: 2m
wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
wechat_×××: 'xxx'
wechat_api_corp_id: 'xxx'

route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'wechat'
receivers:
- name: 'wechat'
wechat_configs:
- send_resolved: true
to_party: '1'
agent_id: '1000002'

===================================================================

如果是用helm安裝的,那么我們的promethues和alertmanager的配置是在一個文件中的

vim ?prometheus-operator-custom.yaml ? # 修改配置

alertmanager: 下配置
config:
global:
# 每2分鐘檢查一次是否恢復(fù)
resolve_timeout: 3m
templates:
- '/etc/alertmanager/config/template_wechat.tmpl'
route:
# 將傳入的報警中有這些標(biāo)簽的分為一個組.
group_by: ['wechat_alert']
# 指分組創(chuàng)建多久后才可以發(fā)送壓縮的警報,也就是初次發(fā)警報的延時.
# # 這樣會確保第一次通知的時候, 有更多的報警被壓縮在一起.
group_wait: 15s
# 當(dāng)?shù)谝粋€通知發(fā)送,等待多久發(fā)送壓縮的警報
group_interval: 15s
# 如果報警發(fā)送成功, 等待多久重新發(fā)送一次
repeat_interval: 3m
receiver: 'wechat'
routes:
- receiver: 'wechat'
continue: true
receivers:
- name: 'wechat'
wechat_configs:
# 是否發(fā)送恢復(fù)告警
- send_resolved: true
# ×××公眾號ID
corp_id: 'XXX'
# ×××應(yīng)用密鑰
×××: 'XXX'
# 可發(fā)送的用戶名 可以多個?
#to_user: '@all'
# 部門ID 點擊部門的時候 右下角的彈窗可以看到 比較隱蔽
to_party: '92'
agent_id: '1000010'
# 模板格式:
templateFiles:
template_wechat.tmpl: |-
{{ define "wechat.default.message" }}
{{ range .Alerts }}
=====start======
告警程序: k8s_prometheus_alert
告警級別: {{ .Labels.severity }}
告警類型: {{ .Labels.alertname }}
故障主機: {{ .Labels.name?}}
告警閾值: {{ .Annotations.value }}
告警主題: {{ .Annotations.summary }}
# 時間默認(rèn)UTC 所以后邊加入28800e9 也就是多了啦8個小時?
觸發(fā)時間: {{ (.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
======end======
{{ end }}
{{ end }}

報警規(guī)則配置文件:
helm安裝配合文件合并,所以報警規(guī)則獨立出一個文件,加載時多加載一個文件即可。

vim ?rules-custom.yaml ?# 編輯規(guī)則文件

additionalPrometheusRules:
- name: cpu1
groups:
- name: cpu load
rules:
- alert: pod cpu 超過1%
expr: (sum by(name)(rate(container_cpu_usage_seconds_total{image!=""}[5m]))*100) > 30
for: 1m
labels:
severity: critical
annotations:
value: "{{ $value }}"
description: The configuration of the instances of the Alertmanager cluster`{{$labels.service}}` are out of sync.
summary: "這是第一個組的第一個測試 OK"
# - alert: pod memcache 超過1%
# expr: (sum by(name)(rate(container_cpu_usage_seconds_total{image!=""}[5m]))*100) > 5
# for: 5m
# labels:
# severity: critical
# annotations:
# description: An unexpected number of Alertmanagers are scraped or Alertmanagers disappeared from discovery.
# summary: "這是第一個組的第二個測試"
- name: cpu2
groups:
- name: node load
rules:
- alert: 另一個group pod 超過 1%
expr: (sum by(name)(rate(container_cpu_usage_seconds_total{image!=""}[5m]))*100) > 30
for: 1m
labels:
severity: critical
annotations:
value: "{{ $value }}"
summary: "這是第二個組的測試 ok"

最后我們在加載的時候只需多加載一個配置文件:

可同時加載兩個配置:
helm upgrade monitoring stable/prometheus-operator --version=5.0.3 --namespace=monitoring -f prometheus-operator-custom.yaml -f rules-custom.yaml

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)站欄目:prometheusAlertManager微信報警配置-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://www.muchs.cn/article46/deojeg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、移動網(wǎng)站建設(shè)、Google、定制網(wǎng)站、關(guān)鍵詞優(yōu)化、小程序開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)