如何做好springboot监控集成
1. 引入prometheus 到 pom.xml
<!-- 作为web项目必须的依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
2. 在aop切面中写一个Counter
Counter.builder("request.times." + action).description("kkkk").
tag(action, method)
.register(meterRegistry)
.increment();
3. .properties配置
.properties
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=
management.endpoint.enabled=true
management.endpoint.httptrace.enabled=true
management.endpoint.shutdown.enabled=true
management.endpoint.metrics.enabled=true
management.endpoint.prometheus.enabled=true
management.endpoint.health.show-details=ALWAYS
management.enabled-by-default=true
management.metrics.export.appoptics.enabled: true
management.metrics.export.appoptics.step: 10s
management.metrics.export.appoptics.api-token: fake
# actuator的metrics接口是否需要安全保证
management.endpoints.metrics.sensitive = false
# actuator的metrics接口是否开启
management.endpoints.metrics.enabled=true
*.yml
spring:
##去除有问题的指标,因为指标名重复产生bug
metrics:
servo:
enabled: false
management:
security:
enabled: false
4. 下载相关服务
prometheus-2.17.1.windows-amd64.tar.gz
grafana-6.7.2.windows-amd64.zip
5.开启prometheus服务
5.1 根据情况补充 metrics_path 和 targets 到prometheus.yml配置中
5.2 执行 prometheus.exe
6. 启动 grafana 连接 prometheus服务
7.补充
7.1. 可以通过请求获取可用的资源
curl http://localhost:9090/api/v1/label/__name__/values