jianzh5

通过之前的文章我们使用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/查看开放端点
file

访问http://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

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

查看效果

file
file

彩蛋

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

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


相关文章

avatar

分类:

技术点:

相关文章:

  • 2021-07-12
  • 2019-07-02
  • 2021-08-14
  • 2021-08-09
  • 2021-03-05
  • 2019-08-29
  • 2021-08-20
  • 2020-06-29
猜你喜欢
  • 2020-03-25
  • 2021-07-21
  • 2021-12-08
  • 2022-01-24
  • 2021-11-29
  • 2021-10-25
相关资源
相似解决方案