当前位置: 移动技术网 > IT编程>开发语言>Java > 使用Prometheus监控SpringBoot应用

使用Prometheus监控SpringBoot应用

2019年10月24日  | 移动技术网IT编程  | 我要评论

通过之前的文章我们使用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://www.lhsxpumps.com/_localhost:50378/actuator/查看开放端点
file

访问http://www.lhsxpumps.com/_localhost:50378/actuator/prometheus查看metrics
file

之前的文章中都是监控一个实例,这次咱们把端口设置成随机,启动两个实例,等下看看监控效果。

监控配置

prometheus

修改prometheus.yml,增加监控任务

  - job_name: 'springboot'
    metrics_path: '/actuator/prometheus'
    static_configs:
    - targets: ['10.1.61.10:50378','10.1.61.10:50822']

重启prometheus,查看监控状态。
file

grafana

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

查看效果

file
file

彩蛋

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

怎么实现的呢?咱们下期有缘再见!


相关文章

avatar

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网