中高级程序员都应该懂的SpringBoot集成Prometheus

Spring Boot集成Prometheus

Spring Boot中的 spring-boot-starter-actuator组件已经集成了对Micrometer的支持,其中Metrics端点的很多功能就是通过Micrometer实现的。Prometheus端点默认也是开启支持的,实际上Actuator依赖的spring-boot-actuator-autoconfigure中集成了对很多 框 架 “ 开 箱 即 用 ” 的 接 口 , 其 中 Prometheus 包 中 集 成 了 对Prometheus 的 支 持 , 使 用 Actuator 可 以 轻 易 地 让 项 目 暴 露 出Prometheus 的 端 点 接 口 。 作 为 Prometheus 收 集 数 据 的 客 户 端 ,Prometheus可以通过此端点收集应用中的Micrometer度量数据。

下面以Counter和Timer为例,讲解Spring Boot与Prometheus集成的主要步骤。

首 先 , 引 入 spring-boot-starter-actuator 和 spring-bootstarter-web依赖。

中高级程序员都应该懂的SpringBoot集成Prometheus_第1张图片

然后,在配置文件中添加如下配置。

中高级程序员都应该懂的SpringBoot集成Prometheus_第2张图片

添加启动类。

中高级程序员都应该懂的SpringBoot集成Prometheus_第3张图片

启动Prometheus,使用浏览器访问http://localhost:9090,查看具体的监控指标,如下图所示。

中高级程序员都应该懂的SpringBoot集成Prometheus_第4张图片

 

本文给大家讲解的内容是服务监控治理,Spring Boot集成Prometheus

  1. 下篇文章给大家讲解的内容是服务监控治理,日志监控方案

  2. 觉得文章不错的朋友可以转发此文关注小编;

  3. 感谢大家的支持!

你可能感兴趣的:(编程,Java,程序员,spring,boot,prometheus,java)