Prometheus && Alertmanager + prometheus-webhook-dingtalk 告警

Prometheus

下载地址:https://prometheus.io/download/

安装 Prometheus

# 解压下载包
tar -zxvf prometheus-2.11.1.linux-amd64.tar.gz
# 做软链接
ln -s /usr/local/src/prometheus-2.11.1.linux-amd64 /usr/local/prometheus

配置 Prometheus

# 修改 prometheus.yml
###
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - 你的 alertmanager 服务器:9093
rule_files:
  - "rules/*.yml"
*** 其余 prometheus 刮取策略就不贴出来了,这部分就是告警所需的模块
###
# 添加告警规则(在 prometheus.yml 同级目录下创建 rules 目录)
mkdir rules
vim alerts.yml
###
# 组告警
groups:
# 组名,报警规则组名称
- name: cert_alerts
  rules:
  - alert: certificateEW
    expr: ceil((probe_ssl_earliest_cert_expiry - time())/86400) < 30
    for: 1m
    labels:
      serverity: warning
    annotations:
      summary: The remaining time of the certificate is insufficient
      console: You might want to Renewal certificate
###
# 配置 prometheus service
vim /etc/systemd/system/prometheus.service
###
ExecStart=/usr/local/prometheus/prometheus --
Documentation=https://prometheus.io/docs/introduction/overview/
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/After=network.target
[Service]
Restart=on-failure
WorkingDirectory=/usr/local/prometheus/
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
###
# 启动 prometheus
systemctl daemon-reload
systemctl start prometheus

Alertmanager

下载地址:https://prometheus.io/download/

安装

# 解压下载的包
tar -C /usr/local/alertmanager -zxvf alertmanager-0.21.0.linux-amd64.tar.gz
# 做软链接
ln -s /usr/local/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk /usr/local/bin/
cp /usr/local/alertmanager/alertmanager /usr/local/bin/
cp /usr/local/alertmanager/amtool /usr/local/bin/

配置

# 修改 alertmanager.yml
###
global:
# 每一分钟检查一次是否恢复
  resolve_timeout: 1m
route:
# 设置默认接收人
  receiver: 'webhook'
# 组告警等待时间,也就是告警产生后等待 10s
  group_wait: 10s
  #两组告警的间隔时间
  group_interval: 10s
  #重复告警的间隔时间,减少相同微信告警的发送频率
  repeat_interval: 1h
 #采用哪个标签来作为分组依据
  group_by: ['alertname']
  routes:
  - receiver: webhook
    group_wait: 10s
    match:
      team: node
receivers:
- name: 'webhook'
  webhook_configs:
  - url: http://localhost:8060/dingtalk/ops_dingding/send
    send_resolved: true
###
# 配置 prometheus service
vim /etc/systemd/system/alertmanager.service
###
[unit]
Description=altermanager
Documentation=http://prometheus.io/docs/

[Service]
ExecStart=/usr/local/alertmanager/alertmanager --config.file=/usr/local/alertmanager/alertmanager.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
###
# 启动 alertmanager
systemctl daemon-reload
systemctl start prometheus

prometheus-webhook-dingtalk

下载地址:https://github.com/timonwong/prometheus-webhook-dingtalk/releases/tag/v1.4.0

安装

# 解压下载的包
tar -C /usr/local/prometheus-webhook-dingtalk -zxvf prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
# 做软链接
ln -s /usr/local/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk /usr/local/bin/

配置

# 配置 prometheus-webhook-dingtalk service
vim /etc/systemd/system/prometheus-webhook-dingtalk.service
###
[Unit]
Description=prometheus-webhook-dingtalk
After=network-online.target

[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk --ding.profile=ops_dingding=https://oapi.dingtalk.com/robot/send?access_token=XXXX(这里可以换成自己的webhook)

[Install]
WantedBy=multi-user.target
###
# 启动 prometheus-webhook-dingtalk 告警
systemctl daemon-reload
systemctl start prometheus-webhook-dingtalk

查看钉钉告警:已经正常告警
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
prometheus-webhook-dingtalk 是一个用于将 Prometheus 监控告警消息发送到钉钉的 Webhook 工具。它可以帮助你将 Prometheus 监控告警通过钉钉机器人发送到指定的群组或用户。 你可以通过以下步骤来配置和使用 prometheus-webhook-dingtalk: 1. 安装 prometheus-webhook-dingtalk:你可以使用 Go 工具链来安装 prometheus-webhook-dingtalk,运行以下命令: ``` go get github.com/timonwong/prometheus-webhook-dingtalk/cmd/dingtalk ``` 2. 创建钉钉机器人:在钉钉中创建一个自定义机器人,并获取到它的 Webhook 地址,用于将告警消息发送到指定的群组或用户。 3. 创建配置文件:在 prometheus-webhook-dingtalk 的配置文件中,你需要指定钉钉机器人的 Webhook 地址以及其他相关参数。你可以创建一个名为 config.yml 的配置文件,并将以下示例内容填入: ```yaml listen: 0.0.0.0:8060 dingtalk: webhook: https://oapi.dingtalk.com/robot/send?access_token=your_webhook_token ``` 4. 启动 prometheus-webhook-dingtalk:运行以下命令来启动 prometheus-webhook-dingtalk: ``` dingtalk -config.file=config.yml ``` 5. 配置 Prometheus:在 Prometheus 的配置文件中,添加以下内容来指定告警消息的接收端: ```yaml receivers: - name: 'dingtalk' webhook_configs: - url: 'http://prometheus-webhook-dingtalk:8060/dingtalk/webhook' ``` 6. 重新启动 Prometheus:确保 Prometheus 已经重新加载了配置文件,并重启 Prometheus 服务。 现在,当 Prometheus 监控触发告警时,prometheus-webhook-dingtalk 将会将告警消息发送到钉钉机器人的 Webhook 地址,从而通知到指定的群组或用户。 请注意,以上步骤仅为一般示例,实际操作可能会因环境和需求而有所不

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值