Spring Actuator常用接口

  • http://localhost:9080/actuator
    导入依赖
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

配置文件添加如下配置

management.endpoints.web.exposure.include=*

启动服务后调用上方接口可以看到暴露出来的监控信息

{"_links":{"self":{"href":"http://localhost:9080/actuator","templated":false},"archaius":{"href":"http://localhost:9080/actuator/archaius","templated":false},"nacos-config":{"href":"http://localhost:9080/actuator/nacos-config","templated":false},"nacos-discovery":{"href":"http://localhost:9080/actuator/nacos-discovery","templated":false},"auditevents":{"href":"http://localhost:9080/actuator/auditevents","templated":false},"beans":{"href":"http://localhost:9080/actuator/beans","templated":false},"caches-cache":{"href":"http://localhost:9080/actuator/caches/{cache}","templated":true},"caches":{"href":"http://localhost:9080/actuator/caches","templated":false},"health-component":{"href":"http://localhost:9080/actuator/health/{component}","templated":true},"health":{"href":"http://localhost:9080/actuator/health","templated":false},"health-component-instance":{"href":"http://localhost:9080/actuator/health/{component}/{instance}","templated":true},"conditions":{"href":"http://localhost:9080/actuator/conditions","templated":false},"configprops":{"href":"http://localhost:9080/actuator/configprops","templated":false},"env":{"href":"http://localhost:9080/actuator/env","templated":false},"env-toMatch":{"href":"http://localhost:9080/actuator/env/{toMatch}","templated":true},"info":{"href":"http://localhost:9080/actuator/info","templated":false},"loggers":{"href":"http://localhost:9080/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:9080/actuator/loggers/{name}","templated":true},"heapdump":{"href":"http://localhost:9080/actuator/heapdump","templated":false},"threaddump":{"href":"http://localhost:9080/actuator/threaddump","templated":false},"prometheus":{"href":"http://localhost:9080/actuator/prometheus","templated":false},"metrics":{"href":"http://localhost:9080/actuator/metrics","templated":false},"metrics-requiredMetricName":{"href":"http://localhost:9080/actuator/metrics/{requiredMetricName}","templated":true},"scheduledtasks":{"href":"http://localhost:9080/actuator/scheduledtasks","templated":false},"httptrace":{"href":"http://localhost:9080/actuator/httptrace","templated":false},"mappings":{"href":"http://localhost:9080/actuator/mappings","templated":false},"refresh":{"href":"http://localhost:9080/actuator/refresh","templated":false},"features":{"href":"http://localhost:9080/actuator/features","templated":false},"service-registry":{"href":"http://localhost:9080/actuator/service-registry","templated":false},"hystrix.stream":{"href":"http://localhost:9080/actuator/hystrix.stream","templated":false}}}

/health

  • http://localhost:8080/actuator/health
    用于监控各种服务健康,还可以监控tomcat,mq,redis等
"status":"UP","details":{"nacosConfig":{"status":"UP"},"diskSpace":{"status":"UP","details":{"total":125872107520,"free":88245694464,"threshold":10485760}},"db":{"status":"UP","details":{"database":"MySQL","hello":1}},"mail":{"status":"UP","details":{"location":"smtp.qq.com:-1"}},"refreshScope":{"status":"UP"},"discoveryComposite":{"status":"UP","details":{"discoveryClient":{"status":"UP","details":{"services":["platform-admin"]}}}},"hystrix":{"status":"UP"},"redis":{"status":"UP","details":{"version":"3.0.504"}}}}

注:配置文件需开启展示详细信息

#显示健康状态详细信息
management.endpoint.health.show-details=always

/metrics

  • http://localhost:8080/actuator/metrics
    展示出所有可监控的指标
{"names":["jvm.threads.states","tomcat.global.request.max","jvm.buffer.memory.used","jvm.gc.pause","tomcat.sessions.created","tomcat.global.request","jvm.threads.daemon","system.cpu.usage","jvm.gc.memory.allocated","jvm.memory.used","jvm.memory.committed","tomcat.global.received","tomcat.sessions.expired","hikaricp.connections.idle","jvm.threads.live","jvm.threads.peak","hikaricp.connections.pending","process.uptime","tomcat.threads.config.max","hikaricp.connections","tomcat.sessions.rejected","process.cpu.usage","requests_error_total","hikaricp.connections.active","hikaricp.connections.creation","http.server.requests","tomcat.global.error","jvm.classes.loaded","jvm.classes.unloaded","tomcat.sessions.active.current","tomcat.threads.current","jvm.memory.max","tomcat.sessions.alive.max","jvm.gc.live.data.size","hikaricp.connections.max","hikaricp.connections.min","jvm.buffer.count","jvm.buffer.total.capacity","tomcat.threads.busy","hikaricp.connections.usage","tomcat.sessions.active.max","hikaricp.connections.timeout","process.start.time","hikaricp.connections.acquire","jvm.gc.memory.promoted","jdbc.connections.max","jdbc.connections.min","logback.events","jvm.gc.max.data.size","tomcat.global.sent","system.cpu.count"]}

/loggers

  • localhost:9080/actuator/loggers
    Spring Actuator常用接口_第1张图片

改变运行时的日志等级,不需要重启服务

Spring Actuator常用接口_第2张图片

{
    "configuredLevel":"DEBUG"
}

Spring Actuator常用接口_第3张图片
Spring Actuator常用接口_第4张图片
Spring Actuator常用接口_第5张图片
Spring Actuator常用接口_第6张图片

/info

  • http://localhost:9080/actuator/info
    Spring Actuator常用接口_第7张图片

/beans

  • http://localhost:9080/actuator/beans
    在这里插入图片描述
{"contexts":{"platform-admin-1":{"beans":{"springMQProducer":{"aliases":[],"scope":"singleton","type":"com.ecidi.rocketmq.support.SpringMQProducer","resource":"class path resource [com/ecidi/rocketmq/config/RocketMqConfig.class]","dependencies":["transactionListener"]},"spring.jpa-org.springframework.boot.autoconfigure.orm.jpa.JpaProperties":{"aliases":[],"scope":"singleton","type":"org.springframework.boot.autoconfigure.orm.jpa.JpaProperties","resource":null,"dependencies":[]},"com.maihaoche.starter.mq.config.MQProducerAutoConfiguration":{"aliases":[],"scope":"singleton","type":"com.maihaoche.starter.mq.config.MQProducerAutoConfiguration$$EnhancerBySpringCGLIB$$9d1ed0dd","resource":null,"dependencies":["spring.rocketmq-com.maihaoche.starter.mq.config.MQProperties"]},"nacosServiceRegistry":{"aliases":[],"scope":"singleton","type":"com.alibaba.cloud.nacos.registry.NacosServiceRegistry","resource":"class path resource [com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.class]","dependencies":["nacosProperties"]},"fieldProvider":{"aliases":[],"scope":"singleton","type":"springfox.documentation.schema.property.field.FieldProvider","resource":"URL [jar:file:/D:/apache-maven-3.6.2/repository/io/springfox/springfox-schema/2.9.2/springfox-schema-2.9.2.jar!/springfox/documentation/schema/property/field/FieldProvider.class]","dependencies":["typeResolver"]},"apiListingReferenceScanner":{"aliases":[],"scope":"singleton","type":"springfox.documentation.spring.web.scanners.ApiListingReferenceScanner","resource":"URL [jar:file:/D:/apache-maven-3.6.2/repository/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/scanners/ApiListingReferenceScanner.class]","dependencies":[]},"organizationController":{"aliases":...

/heapdump

http://localhost:9080/actuator/heapdump
Spring Actuator常用接口_第8张图片
将下载下来的文件用它打开即可
Spring Actuator常用接口_第9张图片
Spring Actuator常用接口_第10张图片

/threaddump

  • http://localhost:9080/actuator/threaddump
    Spring Actuator常用接口_第11张图片
{"threads":[{"threadName":"Keep-Alive-Timer","threadId":1960,"blockedTime":-1,"blockedCount":0,"waitedTime":-1,"waitedCount":1,"lockName":null,"lockOwnerId":-1,"lockOwnerName":null,"inNative":false,"suspended":false,"threadState":"TIMED_WAITING","stackTrace":[{"methodName":"sleep","fileName":"Thread.java","lineNumber":-2,"className":"java.lang.Thread","nativeMethod":true},{"methodName":"run","fileName":"KeepAliveCache.java","lineNumber":172,"className":"sun.net.www.http.KeepAliveCache","nativeMethod":false},{"methodName":"run","fileName":"Thread.java","lineNumber":748,"className":"java.lang.Thread","nativeMethod":false}],"lockedMonitors":[],"lockedSynchronizers":[],"lockInfo":null},{"threadName":"com.alibaba.nacos.client.Worker.longPolling.fixed-127.0.0.1_8848","threadId":345,"blockedTime":-1,"blockedCount":0,"waitedTime":-1,"waitedCount":55,"lockName":"java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@3fc652","lockOwnerId":-1,"lockOwnerName":null,"inNative":false,"suspended":false,"threadState":"WAITING","stackTrace":[{"methodName":"park","fileName":"Unsafe.java","lineNumber":-2,"className":"sun.misc.Unsafe","nativeMethod":true},{"methodName":"park","fileName":"LockSupport.java","lineNumber":175,"className":"java.util.concurrent.locks.LockSupport","nativeMethod":false}....

/shutdown

Spring Actuator常用接口_第12张图片

你可能感兴趣的:(Spring Actuator常用接口)