Prometheus接入(四、Spring Boot接入)
环境
CentOS 7.9 + Spring Boot 2.6.8
安装
1、依赖引入
<!-- 预设监控 --> <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、配置文件
management:
endpoints:
web:
base-path: "/status" ## 自定义暴露地址
exposure:
include: "*"
server:
port: 12012 ## 自定义暴露端口
metrics:
tags:
application: ${spring.application.name}
security:
enabled: false
4、在Application.java中添加
/** * 应用名称 */ @Value("${spring.application.name}") private String application; @Bean MeterRegistryCustomizer<MeterRegistry> configurer() { return (registry -> registry.config().commonTags("MyApplication", application)); }
5、启动查看指标
http://localhost:12012/status/prometheus