前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用Prometheus监控SpringBoot应用

使用Prometheus监控SpringBoot应用

作者头像
JAVA日知录
发布2019-10-24 18:29:55
8190
发布2019-10-24 18:29:55
举报
文章被收录于专栏:JAVA杂谈JAVA杂谈

今天我们来监控一下你的应用。(本文以SpringBoot 2.1.9.RELEASE 作为监控目标)

编码

添加依赖

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

代码语言:javascript
复制
<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文件,对外暴露监控端点

代码语言:javascript
复制
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,增加监控任务

代码语言:javascript
复制
  - 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分钟,然后邮箱会收到这样一封告警邮件

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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-10-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 JAVA日知录 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 添加依赖
  • 修改配置
  • 启动应用
  • 监控配置
    • Prometheus
      • Grafana
      相关产品与服务
      Prometheus 监控服务
      Prometheus 监控服务(TencentCloud Managed Service for Prometheus,TMP)是基于开源 Prometheus 构建的高可用、全托管的服务,与腾讯云容器服务(TKE)高度集成,兼容开源生态丰富多样的应用组件,结合腾讯云可观测平台-告警管理和 Prometheus Alertmanager 能力,为您提供免搭建的高效运维能力,减少开发及运维成本。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档