随笔- 310  文章- 1  评论- 0  阅读- 85350 

下载&启动

1
2
3
4
5
6
【下载】
https://prometheus.io/download/
【启动】
1. cd D:\Program Files\alertmanager-0.24.0.windows-amd64
2. 双击 alertmanager.exe
3.访问 http://localhost:9093

关联Prometheus

1
2
3
4
5
6
7
8
9
10
在Prometheus的架构中被划分成两个独立的部分。
Prometheus负责产生告警,而Alertmanager负责告警产生后的后续处理。
因此Alertmanager部署完成后,需要在Prometheus中设置Alertmanager相关的信息。
 
编辑Prometheus配置文件prometheus.yml,并添加以下内容
alerting:
  alertmanagers:
    - static_configs:
        - targets:
            - localhost:9093

定义告警规则

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
groups:
- name: example
  rules:
  - alert: HighErrorRate
    expr: job:request_latency_seconds:mean5m{job="myjob"} > 0.5
    for: 10m
    labels:
      severity: page
    annotations:
      summary: High request latency
      description: description info
       
解析:
    在告警规则文件中,我们可以将一组相关的规则设置定义在一个group下。
    在每一个group中我们可以定义多个告警规则(rule)。
     
    一条告警规则主要由以下几部分组成:
    alert:  告警规则的名称。
    expr:   基于PromQL表达式告警触发条件,用于计算是否有时间序列满足该条件。
    for:    评估等待时间,可选参数。用于表示只有当触发条件持续一段时间后才发送告警。在等待期间新产生告警的状态为pending。
    labels: 自定义标签,允许用户指定要附加到告警上的一组附加标签。
    annotations:用于指定一组附加信息,比如用于描述告警详细信息的文字等,annotations的内容在告警产生时会一同作为参数发送到Alertmanager。
                 在告警规则文件的annotations中使用summary描述告警的概要信息,description用于描述告警的详细信息

接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1.查询告警信息
curl http://localhost:9093/api/v2/alerts
 
2.查看静默告警信息
# 查看所有静默的告警列表
curl http://localhost:9093/api/v2/silences
 
# 查看某条静默的告警
curl http://localhost:9093/api/v2/silence/{silenceID}
         
3.添加静默
curl -XPOST  http://localhost:9093/api/v2/silences \
>  --header 'Content-Type: application/json' \
>  --data '{"comment": "test", "status": {"state": "active"}, "endsAt": "2022-05-26T01:51:01.143796Z", "matchers": [{"isRegex": false, "name": "alertname", "value": "YellowFrameworkBuildJobCheck"}, {"isRegex": false, "name": "severity", "value": "critical"}], "createdBy": "userName", "startsAt": "2022-05-25T15:51:01.143796Z", "id": ""}'
 
4.删除静默
# 删除指定silenceID的告警
curl -X DELETE http://alertmanager.com:9093/api/v2/silence/{silenceID}

 

发送告警信息 

1
curl -X POST 'http://localhost:9093/api/v2/alerts' -H 'Content-Type: application/json' -d '[{"labels":{"severity":"Warning","alertname":"内存使用过高","instance":"实例1","msgtype":"testing"},"annotations":{"summary":"node","description":"请检查实例1","value":"0.95"}},{"labels":{"severity":"Warning","alertname":"CPU使用过高","instance":"实例2","msgtype":"testing"},"annotations":{"summary":"node","description":"请检查实例2","value":"0.90"}}]'

  

 

 posted on   boye169  阅读(70)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
点击右上角即可分享
微信分享提示