首页 > 其他分享 >prometheus + alertmanager 搭建告警通知

prometheus + alertmanager 搭建告警通知

时间:2024-10-19 14:22:00浏览次数:1  
标签:alertmanager 0.1 9104 prometheus 127.0 mysqld 告警

prometheus

下载prometheus-2.53.2

prometheus.yml文件修改

global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets:
          - 127.0.0.1:9093

rule_files:
  - "rules/rule-*.yml"

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090", "127.0.0.1:9104"]

其中127.0.0.1:9104是mysqld_exporter的metric地址

新建rules目录,并创建规则 rule-first.yml

groups:
  - name: InstanceDown_Rule
    rules:
      - alert: InstanceDown  # 告警名称
        expr: up == 0        # 告警条件
        for: 30s              # 告警触发前需要持续满足条件的时间
        labels:
          severity: critical # 告警的严重程度
        annotations:
          summary: "Instance {{ $labels.instance }} down"
          description: "Instance {{ $labels.instance }} has been down for more than 5 minutes."

启动Prometheus

prometheus --config.file=prometheus.yml --storage.tsdb.path=./data --web.enable-lifecycle

访问Prometheus

http://127.0.0.1:9090/

alertmanager

下载alertmanager-0.27.0

修改配置文件alertmanager.yml

route:
  group_by: ['instance']
  group_wait: 10s
  group_interval: 20s
  #repeat_interval: 1h
  receiver: 'web.hook'
receivers:
  - name: 'web.hook'
    webhook_configs:
      - url: 'http://127.0.0.1:5001/alert/hook'
        send_resolved: true
#inhibit_rules:
#  - source_match:
#      severity: 'critical'
#    target_match:
#      severity: 'warning'
#    equal: ['instance']

其中 http://127.0.0.1:5001/alert/hook 是接收告警的钩子接口

启动alertmanager

alertmanager --config.file=alertmanager.yml

访问alertmanager

http://127.0.0.1:9093/

grafana

下载grafana-11.2.1

启动grafana

grafana-server

访问grafana

http://127.0.0.1:3000

mysqld_exporter

下载 mysqld_exporter-0.15.1

在mysqld_exporter根目录创建.my.cnf文件

[client]
user=root
password=root

user和password分别是MySQL数据库的用户和密码;mysqld_exporter需要安装与mysql_server同一个服务器上。

启动mysqld_exporter

mysqld_exporter

访问mysqld_exporter

http://127.0.0.1:9104/

编写hook

@PostMapping("/alert/hook")
public Response<String> alertHook(@RequestBody Map<String, Object> alertDataMap) {
	//TODO 在这里实现告警处理,发微信、邮件、钉钉都可以
	System.out.println(JSON.toJSONString(alertDataMap));
	return Response.ok("success");
}

以上使用Java编写接口,根据实际可以使用任何一种语言编写。

可以关闭mysqld_exporter,模拟服务宕机。/alert/hook接口收到的数据如下:

{
	"receiver": "web\\.hook",
	"status": "firing",
	"alerts": [{
		"status": "firing",
		"labels": {
			"alertname": "InstanceDown",
			"instance": "127.0.0.1:9104",
			"job": "prometheus",
			"severity": "critical"
		},
		"annotations": {
			"description": "Instance 127.0.0.1:9104 has been down for more than 5 minutes.",
			"summary": "Instance 127.0.0.1:9104 down"
		},
		"startsAt": "2024-10-10T11:27:58.11Z",
		"endsAt": "0001-01-01T00:00:00Z",
		"generatorURL": "http://olive-my:9090/graph?g0.expr=up+%3D%3D+0&g0.tab=1",
		"fingerprint": "106b3a6075af7628"
	}],
	"groupLabels": {
		"instance": "127.0.0.1:9104"
	},
	"commonLabels": {
		"alertname": "InstanceDown",
		"instance": "127.0.0.1:9104",
		"job": "prometheus",
		"severity": "critical"
	},
	"commonAnnotations": {
		"description": "Instance 127.0.0.1:9104 has been down for more than 5 minutes.",
		"summary": "Instance 127.0.0.1:9104 down"
	},
	"externalURL": "http://olive-my:9093",
	"version": "4",
	"groupKey": "{}:{instance=\"127.0.0.1:9104\"}",
	"truncatedAlerts": 0
}

标签:alertmanager,0.1,9104,prometheus,127.0,mysqld,告警
From: https://www.cnblogs.com/happyhuangjinjin/p/18475837

相关文章

  • Kubernetes部署Prometheus并实现自定义指标HPA(安装、配置、实现全流程)
    1.安装kube-prometheusKube-Prometheus是一个开箱即用的监控解决方案,用于监控Kubernetes集群。它集成了Prometheus、Prometheus-Adapter、Alertmanager和一系列的导出器(exporters),使你能够轻松地收集和可视化集群中各种资源的监控数据。1.1克隆kube-prometheus仓库gitclon......
  • 【深度知识】5.Prometheus-PromQL查询监控数据和语法说明
    成就你的写作梦想立即下载 【深度知识】5.Prometheus-PromQL查询监控数据和语法说明笔名辉哥 简书优秀创作者0.8682021-03-2822:20IP属地:上海打开App  1.摘要PromQL(PrometheusQueryLanguage)是Prometheus自己开发的数据查询DSL......
  • prometheus 报错 Error on ingesting samples that are too old or are too far into
    level=warnts=2021-08-16T03:20:04.960Zcaller=scrape.go:1507component="scrapemanager"scrape_pool=mtailtarget=http://18.167.146.20:3903/metricsmsg="Erroroningestingsamplesthataretoooldoraretoofarintothefuture"num_dro......
  • Zabbix进阶实战!将告警推送到Syslog服务器详细教程
    需求场景:用户需要将zabbix产生的告警事件推送给rsyslog服务器,syslog服务器再对事件日志进行分析处理.环境配置信息服务器IP地址ZabbixServer192.168.200.195Rsyslog服务器192.168.200.128*Rsyslog服务器防火墙需要放通UDP/514端口推送脚本需要修......
  • AI识别工人安全绳佩戴告警系统
    AI识别工人安全绳佩戴告警系统是一种基于人工智能技术的创新解决方案。AI识别工人安全绳佩戴告警系统基于电力作业场景和工地及工厂高空人员作业是否穿戴安全绳进行识别预警,AI识别工人安全绳佩戴告警系统通过智能化图像识别和分析,实时监测工人的安全绳佩戴情况,并在发现异常时进行......
  • Grafana+ Node+ Prometheus对服务器进行性能监控
    目录一、Grafana1.把Grafana压缩文件上传到Linux服务器2.安装服务3.启动服务4.访问二、Node1.上传node_exporter-1.5.0.linux-amd64.tar到服务器2.解压3.启动服务三、Prometheus1.上传prometheus-2.43.0.linux-amd64.tar到服务器2.解压3.进入prometheus.yml中修改......
  • 阿里云Milvus配置监控告警
    阿里云Milvus提供了告警设置功能,通过对重要的监控指标设置报警规则,可以实时了解实例的运行状况,及时处理潜在风险,保障实例稳定运行。背景信息阿里云Milvus的监控报警是通过阿里云云监控产品实现的。通过云监控,您可以设置监控项,在触发监控项报警规则时,通知报警联系组中的所有联......
  • prometheus+grafana 监控nginx
    一:安装插件1.1 查看nginx已启用tub_status模块nginx-V2>&1|grep-owith-http_stub_status_module如果在终端输出with-http_stub_status_module,说明nginx已启用tub_status模块在nginx的配置文件添加如下配置location/nginx_status{stub_statuson;......
  • Ubuntu Server 24 安装 Prometheus
    UbuntuServer24安装Prometheus安装docker如果需要卸载:forpkgindocker.iodocker-docdocker-composedocker-compose-v2podman-dockercontainerdrunc;dosudoapt-getremove$pkg;done添加docker源:sudoapt-getinstallca-certificatescurlsudoinstall......
  • 政务大厅人员睡岗离岗玩手机识别告警系统
    政务大厅人员睡岗离岗玩手机识别告警系统利用摄像头和人工智能技术,政务大厅人员睡岗离岗玩手机识别告警系统实时监测人员的行为,政务大厅人员睡岗离岗玩手机识别告警系统通过图像识别和行为分析,识别出睡岗、离岗和玩手机等不符合规定的行为,并发出告警信号以提醒相关人员。政务大厅......