通过之前的文章我们使用Prometheus监控了应用服务器node_exporter,数据库mysqld_exporter,今天我们来监控一下你的应用。(本文以SpringBoot 2.1.9.RELEASE 作为监控目标)

使用Prometheus监控SpringBoot应用只需要在pom文件添加如下两个依赖:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-actuator</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>io.micrometer</groupId>
  7. <artifactId>micrometer-registry-prometheus</artifactId>
  8. </dependency>

修改application.properties或者application.yml文件,对外暴露监控端点

  1. spring.application.name = blog
  2. management.endpoints.web.exposure.include = prometheus
  3. management.metrics.tags.application = ${spring.application.name}

访问http://localhost:50378/actuator/查看开放端点
file

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

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

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

  1. - job_name: 'SpringBoot'
  2. metrics_path: '/actuator/prometheus'
  3. static_configs:
  4. - targets: ['10.1.61.10:50378','10.1.61.10:50822']

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

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

查看效果

file
file

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

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


相关文章

avatar

版权声明:本文为jianzh5原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/jianzh5/p/11730165.html