义乌市建设局官方网站,php网站开发业务,网络营销和传统营销的区别,国家精品课程网官网创建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