Spring Actuator使用

1 增加pom

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
如果想增加prometheus的监控,则增加如下配置:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>


2 增加配置
如果什么配置都不加,访问: http://localhost:8080/actuator/health 返回 UP,则初步成功。

增加精细化的配置:
management:
    server:
        port: 9002
     #   servlet:
        #    context-path: /demo
    endpoint:
        showdown:
            enabled: false
        health:
            show-details: always
    endpoints:
        web:
           # base-path: /web
            exposure:
                include: '*'
                exclude: env
    metrics:
        web:
            client:
                requests-metric-name: http.client.requests
            server:
                requests-metric-name: http.server.requests
                auto-time-requests: true

访问:http://localhost:9002/actuator/metrics/

http://localhost:9002/actuator/metrics/http.client.requests
显示结果,则配置成功。

3 通过实现 MeterBind接口实现自己的统计信息监控。




posted on 2022-06-24 17:05  lanhz  阅读(80)  评论(0编辑  收藏  举报