通过之前的文章我们使用Prometheus监控了应用服务器node_exporter,数据库mysqld_exporter,今天我们来监控一下你的应用。(本文以SpringBoot 2.1.9.RELEASE 作为监控目标)
编码
添加依赖
使用Prometheus监控SpringBoot应用只需要在pom文件添加如下两个依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
修改配置
修改application.properties或者application.yml文件,对外暴露监控端点
spring.application.name = blog
management.endpoints.web.exposure.include = prometheus
management.metrics.tags.application = ${spring.application.name}
启动应用
访问http://localhost:50378/actuator/
查看开放端点

访问http://localhost:50378/actuator/prometheus
查看Metrics

之前的文章中都是监控一个实例,这次咱们把端口设置成随机,启动两个实例,等下看看监控效果。
监控配置
Prometheus
修改prometheus.yml,增加监控任务
- job_name: 'SpringBoot'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['10.1.61.10:50378','10.1.61.10:50822']
重启Prometheus,查看监控状态。

Grafana
直接从grafana官网寻找JVM监控DashBoard,然后导入到Grafana中(在环境搭建篇中已经讲述了操作过程,这里就不再赘述)。

查看效果


彩蛋
我们关掉其中一个SpringBoot实例,等2分钟,然后邮箱会收到这样一封告警邮件

怎么实现的呢?咱们下期有缘再见!
相关文章
欢迎关注我的个人公众号:JAVA日知录
网友评论