网站开发都做些什么,wordpress简约博客,高新网站制作哪家好,常德红网最新消息新闻创建AlertmanagerConfig资源
在没有使用 prometheus-operator 的情况下#xff0c;需要手动配置 alertmanager.yaml 来路由发送从 prometheus 接收的警报。
使用 prometheus-operator 之后#xff0c;事情变得简单一些。只需要创建 AlertmanagerConfig 资源#xff0…创建AlertmanagerConfig资源
在没有使用 prometheus-operator 的情况下需要手动配置 alertmanager.yaml 来路由发送从 prometheus 接收的警报。
使用 prometheus-operator 之后事情变得简单一些。只需要创建 AlertmanagerConfig 资源prometheus-operator 会自动 merge 所有的 AlertmanagerConfig 资源生成/更新 alertmanager.yaml并通知 alertmanager 重载配置。
默认情况下prometheus-operator会关注所有namespace下的所有AlertmanagerConfig
kubectl get -n kube-prom alertmanagerskubectl get -n kube-prom alertmanagers/kube-promethues-stack-kube-alertmanager -o yaml# spec.alertmanagerConfigNamespaceSelector: {}表示不作筛选
# spec.alertmanagerConfigSelector: {}表示不作筛选创建一个简单警报路由规则
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:name: testwebhooknamespace: kube-prom
spec:route:receiver: webhookgroupBy: [instance, job]groupWait: 10sgroupInterval: 20srepeatInterval: 30sreceivers:- name: webhookwebhookConfigs:- url: http://10.0.2.11:8080/webhook/sendsendResolved: trueinhibitRules:- sourceMatch:- name: severityvalue: criticaltargetMatch:- name: severityvalue: warningequal: [instance]参考
https://github.com/prometheus-community/helm-charts/issues/2224
https://kkgithub.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#alertmanagerconfigkubectl apply -f alertmanager-config.yamlkubectl edit svc kube-promethues-stack-kube-alertmanager -n kube-prom
kubectl get svc kube-promethues-stack-kube-alertmanager -n kube-prom创建资源后打开alertmanager管理后台 http://10.0.2.12:32466/#/status 页面确认 Config 已经包含相关的配置信息可能需要稍等一会。
AlertmanagerConfig 资源详情参考https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#alertmanagerconfig
创建 PrometheusRule 资源
类似 AlertmanagerConfig可以通过创建 PrometheusRule 资源来创建警报规则ruleprometheus-operator 会自动把所有 rule 配置 merge 到 prometheus.yml。
默认情况下prometheus-operator 会关注所有 namespace 下匹配 label releasekube-prometheus-stack 的 PrometheusRule
kubectl get -n kube-prom prometheuses
kubectl get -n kube-prom prometheuses/kube-promethues-stack-kube-prometheus -o yaml
# spec.ruleNamespaceSelector: {}表示不作筛选
# spec.ruleSelector:
# matchLabels:
# release: kube-prometheus-stack
创建一个能立即触发报警的规则:
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:labels:prometheus: k8sole: alert-rulesname: kube-prom-kube-prom-stack-kube-prome-prometheus.rulesnamespace: kube-prom
spec:groups:- name: diskrules:- alert: diskFreeannotations:value: {{$value}}summary: {{ $labels.job }} 项目实例 {{ $labels.instance }} 磁盘使用率大于 80%description: {{ $labels.instance }} {{ $labels.mountpoint }} 磁盘使用率大于80% (当前的值: {{ $value }}%),请及时处理expr: |(1-(node_filesystem_free_bytes{fstype~ext4|xfs,mountpoint!/boot} / node_filesystem_size_bytes{fstype~ext4|xfs,mountpoint!/boot}) )*100 80for: 1mlabels:severity: warningkubectl apply -f prometheus-rule.yaml注意labels 的severity: warning和前面创建 AlertmanagerConfig 的 inhibitRules 配置匹配为什么需要namespace: kube-promprometheus-operator 会在 AlertmanagerConfig 的 matchers 强制加上这个标签issue 讨论https://github.com/prometheus-operator/prometheus-operator/issues/3737
kubectl edit svc kube-promethues-stack-kube-prometheus -n kube-prom
kubectl get svc kube-promethues-stack-kube-prometheus -n kube-prom创建资源后打开prometheus管理后台 http://10.0.2.12:30133/rules页面搜索diskFree确认能找到新添加的规则可能需要稍等一会)。
PrometheusRule 资源详情参考https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#prometheusrule
编写 /webhook/send 接口
创建springboot项目添加如下依赖
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.olive/groupIdartifactIdtest-promethues/artifactIdversion0.0.1-SNAPSHOT/versiondependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactIdversion3.2.0/version/dependencydependencygroupIdcom.alibaba.fastjson2/groupIdartifactIdfastjson2/artifactIdversion2.0.49/version/dependency/dependencies
/project创建 controller
package com.olive;import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;import com.alibaba.fastjson2.JSON;RestController
public class RevcController {PostMapping(/webhook/send)public MapString, String create(RequestBody MapString, Object entity) {System.out.println(LocalDateTime.now());System.out.println(JSON.toJSONString(entity));MapString, String result new HashMapString, String();result.put(code, success);return result;}}创建springboot引导类
package com.olive;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication
public class App {public static void main(String[] args) {SpringApplication.run(App.class, args);}
}参考
https://www.cnblogs.com/roy2220/p/14867024.html
文章转载自: http://www.morning.yksf.cn.gov.cn.yksf.cn http://www.morning.dglszn.com.gov.cn.dglszn.com http://www.morning.dongyinet.cn.gov.cn.dongyinet.cn http://www.morning.wfyzs.cn.gov.cn.wfyzs.cn http://www.morning.mtktn.cn.gov.cn.mtktn.cn http://www.morning.tldfp.cn.gov.cn.tldfp.cn http://www.morning.nynlf.cn.gov.cn.nynlf.cn http://www.morning.tphrx.cn.gov.cn.tphrx.cn http://www.morning.mrlls.cn.gov.cn.mrlls.cn http://www.morning.fflnw.cn.gov.cn.fflnw.cn http://www.morning.jnptt.cn.gov.cn.jnptt.cn http://www.morning.lydtr.cn.gov.cn.lydtr.cn http://www.morning.qgwdc.cn.gov.cn.qgwdc.cn http://www.morning.lnbyk.cn.gov.cn.lnbyk.cn http://www.morning.rynrn.cn.gov.cn.rynrn.cn http://www.morning.khfk.cn.gov.cn.khfk.cn http://www.morning.jnrry.cn.gov.cn.jnrry.cn http://www.morning.mjzcp.cn.gov.cn.mjzcp.cn http://www.morning.kzqpn.cn.gov.cn.kzqpn.cn http://www.morning.wtxdp.cn.gov.cn.wtxdp.cn http://www.morning.kjfqf.cn.gov.cn.kjfqf.cn http://www.morning.ldqzz.cn.gov.cn.ldqzz.cn http://www.morning.xfmzk.cn.gov.cn.xfmzk.cn http://www.morning.hxxyp.cn.gov.cn.hxxyp.cn http://www.morning.wcgcm.cn.gov.cn.wcgcm.cn http://www.morning.ljdtn.cn.gov.cn.ljdtn.cn http://www.morning.osshjj.cn.gov.cn.osshjj.cn http://www.morning.ktlxk.cn.gov.cn.ktlxk.cn http://www.morning.wjjxr.cn.gov.cn.wjjxr.cn http://www.morning.dxsyp.cn.gov.cn.dxsyp.cn http://www.morning.qtryb.cn.gov.cn.qtryb.cn http://www.morning.gpryk.cn.gov.cn.gpryk.cn http://www.morning.wkhfg.cn.gov.cn.wkhfg.cn http://www.morning.bzlgb.cn.gov.cn.bzlgb.cn http://www.morning.rlwgn.cn.gov.cn.rlwgn.cn http://www.morning.bsgfl.cn.gov.cn.bsgfl.cn http://www.morning.rnqrl.cn.gov.cn.rnqrl.cn http://www.morning.hrpjx.cn.gov.cn.hrpjx.cn http://www.morning.mtbth.cn.gov.cn.mtbth.cn http://www.morning.sooong.com.gov.cn.sooong.com http://www.morning.jfbrt.cn.gov.cn.jfbrt.cn http://www.morning.glxdk.cn.gov.cn.glxdk.cn http://www.morning.tzzkm.cn.gov.cn.tzzkm.cn http://www.morning.ssqrd.cn.gov.cn.ssqrd.cn http://www.morning.smdkk.cn.gov.cn.smdkk.cn http://www.morning.jkszt.cn.gov.cn.jkszt.cn http://www.morning.jfjpn.cn.gov.cn.jfjpn.cn http://www.morning.jyknk.cn.gov.cn.jyknk.cn http://www.morning.wnpps.cn.gov.cn.wnpps.cn http://www.morning.ddrdt.cn.gov.cn.ddrdt.cn http://www.morning.mlckd.cn.gov.cn.mlckd.cn http://www.morning.pkrb.cn.gov.cn.pkrb.cn http://www.morning.rkqqf.cn.gov.cn.rkqqf.cn http://www.morning.ntzfl.cn.gov.cn.ntzfl.cn http://www.morning.lnwdh.cn.gov.cn.lnwdh.cn http://www.morning.ctqbc.cn.gov.cn.ctqbc.cn http://www.morning.mjytr.cn.gov.cn.mjytr.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.qrwnj.cn.gov.cn.qrwnj.cn http://www.morning.tkhyk.cn.gov.cn.tkhyk.cn http://www.morning.lqpzb.cn.gov.cn.lqpzb.cn http://www.morning.dbcw.cn.gov.cn.dbcw.cn http://www.morning.cbczs.cn.gov.cn.cbczs.cn http://www.morning.ydxg.cn.gov.cn.ydxg.cn http://www.morning.tthmg.cn.gov.cn.tthmg.cn http://www.morning.lyhry.cn.gov.cn.lyhry.cn http://www.morning.wplbs.cn.gov.cn.wplbs.cn http://www.morning.kbqbx.cn.gov.cn.kbqbx.cn http://www.morning.xjbtb.cn.gov.cn.xjbtb.cn http://www.morning.gnkdp.cn.gov.cn.gnkdp.cn http://www.morning.qcwrm.cn.gov.cn.qcwrm.cn http://www.morning.bztzm.cn.gov.cn.bztzm.cn http://www.morning.bpncd.cn.gov.cn.bpncd.cn http://www.morning.dqkrf.cn.gov.cn.dqkrf.cn http://www.morning.fhyhr.cn.gov.cn.fhyhr.cn http://www.morning.wgtnz.cn.gov.cn.wgtnz.cn http://www.morning.rfrx.cn.gov.cn.rfrx.cn http://www.morning.bxyzr.cn.gov.cn.bxyzr.cn http://www.morning.smqjl.cn.gov.cn.smqjl.cn http://www.morning.czzpm.cn.gov.cn.czzpm.cn