Prometheus采集Java程序指标信息
采集Java程序JVM信息
本文实例代码#
https://github.com/yoyofx/java-metric-prometheus
创建 Spring Boot Application 应用程序#
进行 https://start.spring.io 使用版本 Spring Boot v2.7.11和JDK 17,并创建一个具有以下依赖项的简单JAVA应用程序。
- Spring Boot Actuator (Ops)
- Prometheus (Observability)
- Spring Web (Optional: only to create a simple REST controller.)
Maven POM 会生成以下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
接下来,我们需要公开一个执行器端点,Prometheus将通过该端点以Prometheus能够理解的格式收集指标数据。为此,我们需要添加以下属性。
management.endpoints.web.exposure.include=prometheus
接下来,让我们添加一个简单的控制器和一个简单的接口端点。
@RestController
@SpringBootApplication
public class MonitorApplication {
public static void main(String[] args) {
SpringApplication.run(MonitorApplication.class, args);
}
@GetMapping("/hello")
public String hello() {
return "Hello World!";
}
}
现在,让我们启动应用程序并打开以下URL。
http://localhost:8080/actuator/prometheus
打开上述端点后,您将发现以下格式的一些指标数据,例如:
jvm_memory_used_bytes{area="heap",id="G1 Survivor Space",} 1005592.0
作者: YOYOFx
出处:https://www.cnblogs.com/maxzhang1985/p/12673160.html
版权:本文采用「署名-非商业性使用-相同方式共享 4.0 国际」知识共享许可协议进行许可。

标签:
Prometheus
, Spring Boot
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库