简介
spring-actuator
做度量统计收集,使用Prometheus(普罗米修斯)进行数据收集,Grafana(增强ui)进行数据展示,用于监控生成环境机器的性能指标和业务数据指标。一般,我们叫这样的操作为”埋点”。SpringBoot中的依赖spring-actuator
中集成的度量统计API使用的框架是Micrometer,官网是Micrometer.io。在实践中发现了业务开发者滥用了Micrometer的度量类型Counter
,导致无论什么情况下都只使用计数统计的功能。这篇文章就是基于Micrometer分析其他的度量类型API的作用和适用场景。
1 pom 添加依赖
<!--micrometer -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2配置文件设置
yml 类型为
management:
endpoints:
web:
exposure:
include: prometheus
property类型为
management.endpoints.web.exposure.include=prometheus
3启动类添加代码
@Bean
MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${ruoyi.name}") String applicationName){
return registry -> registry.config().commonTags("application", applicationName);
}
4 访问地址http://localhost:8088/actuator/prometheus
5注意事项
有url拦截器的,注意放开拦截器,否则 http://localhost:8088/actuator/prometheus访问失败
filterChainDefinitionMap.put("/actuator/prometheus", "anon");