Prometheus+Grafana+AlertManager监控SpringBoot项目并发送邮件告警通知

文章目录

Prometheus+Grafana+AlertManager监控平台搭建

Docker搭建并配置Prometheus

Docker拉取并配置Grafana

Docker安装并配置Node-Exporter

Docker安装并配置cAdvisor

Docker安装并运行Alertmanager

新建SpringBoot项目

为Prometheus提供指标

新建项目,引入依赖

java 复制代码
<!--用于导出prometheus系统类型的指标数据-->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
    <version>1.9.8</version>
</dependency>

新建接口,运行程序

Prometheus配置文件中已添加该项目地址,运行后到Prometheus页面中查看连接情况

成功

推送指标到pushgateway

引入依赖

java 复制代码
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient</artifactId>
    <version>0.12.0</version>
</dependency>
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_pushgateway</artifactId>
    <version>0.12.0</version>
</dependency>

新增push接口,用于推送指标(job=B,instance=A)到Pushgateway

java 复制代码
@GetMapping("push")
public void executeBatchJob(){
    try{
        String url = "192.168.251.44:9091";
        CollectorRegistry registry = new CollectorRegistry();
        Gauge guage = Gauge.build("my_custom_metric11", "This is my custom metric.").create();
        guage.set(1.22);
        guage.register(registry);
        PushGateway pg = new PushGateway(url);
        Map<String, String> groupingKey = new HashMap<String, String>();
        groupingKey.put("instance", "A");
        pg.pushAdd(registry, "B", groupingKey);
    } catch (Exception e){
        e.printStackTrace();
    }
}

运行后调用接口,访问Pushgateway

指标已被推送至Pushgateway

开始监控

Grafana连接Prometheus数据源

点击Add your first data source

选择Prometheus

Prometheus server URL中输入IP地址及端口号

注意:此处IP地址为Prometheus在Docker容器内部的IP地址

查看容器内ID方法:

linux 复制代码
docker exec -it 容器ID sh
linux 复制代码
ifconfig

退出:Ctrl+D

点击底部Save&Test

导入Grafana模板

填入模板号,点击load

选择之前设置的Prometheus作为数据源即可

监控SpringBoot项目

邮件告警通知

开启邮箱POP3/SMTP服务(以QQ邮箱为例)


开启后获得授权码,填到alertmanager配置文件相应位置中,并补全其他必要信息,重启alertmanager服务。

停止SpringBoot项目,等待一段时间。

进入Prometheus的Alerts页面,可以看到有告警信息,提示所监控机器不可用,状态已经为Firing,这表示已经将告警发送至Alertmanager。

进入AlertManager界面,可以看到告警信息。

AlertManager会根据配置好的规则将消息发送至邮箱。


操作完成


同系列文章

Linux安装Docker

Docker搭建并配置Prometheus

Docker拉取并配置Grafana

Docker安装并配置Node-Exporter

Docker安装并配置cAdvisor

Docker安装并运行Alertmanager

Prometheus+Grafana+AlertManager监控Linux主机状态

相关推荐
bug攻城狮7 小时前
Spring Boot应用内存占用分析与优化
java·jvm·spring boot·后端
迪巴拉15257 小时前
基于Vue与Spring Boot+Open Cv的智慧校园考勤系统
前端·vue.js·spring boot
A-刘晨阳8 小时前
【Prometheus】Alertmanager配置钉钉告警
运维·云原生·钉钉·prometheus·监控
me8328 小时前
【Java】踩坑实录:Spring Boot + Nginx 本地部署404终极排查:从80端口被占用到配置生效全流程
java·spring boot·nginx
韩立学长8 小时前
基于Springboot校园志愿者服务平台77pz7812(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·后端
qq_12498707539 小时前
基于SpringBoot微信小程序的智能在线预约挂号系统(源码+论文+部署+安装)
spring boot·后端·微信小程序·毕业设计·计算机毕设·毕业设计源码
小马爱打代码9 小时前
SpringBoot + 异地多活 + 消息回放:金融级数据一致性容灾架构设计与演练
spring boot·金融
AD钙奶-lalala11 小时前
SpringBoot 4.0.3配置Swagger
java·spring boot·后端
ldj202011 小时前
安装prometheus + grafana
grafana·prometheus
weixin_3993806912 小时前
Prometheus(普罗米修斯)+grafana 监控Tongweb80909(by lqw)
java·grafana·prometheus