Spring Actuator使用


1 增加pom


org.springframework.boot
spring-boot-starter-actuator

如果想增加prometheus的监控,则增加如下配置:

io.micrometer
micrometer-registry-prometheus



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接口实现自己的统计信息监控。