springboot整合prometheus(三)
1. 加入prometheus依赖
prometheus 官方提供了spring boot 的依赖,但是该客户端已经不支持spring boot 2
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.4.0</version>
</dependency>由于 spring boot 2 的actuator 使用了 Micrometer 进行监控数据统计, 而Micrometer 提供了prometheus 支持,我们可以使用 micrometer-registry-prometheus 来集成 spring boot 2 加入相应依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>2. 配置开启prometheus
3. 验证
4. 关闭不需要的内置监控项
Whether meter IDs starting-with the specified name should be enabled. The longest match wins, the key all can also be used to configure all meters.
4. 配置自定义监控项
自定义一个metrics 收集器
https://segmentfault.com/a/1190000018642077
自定义一个metrics 收集器,只需要继承 prometheus 的 Collector,重写抽象方法collect
注册 YourCustomCollector 到 spring 容器
Last updated
Was this helpful?