SpringBoot监控
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
{ "_links":{ "self":{ "href":"http://localhost:8080/actuator", "templated":false }, "health":{ "href":"http://localhost:8080/actuator/health", "templated":false }, "health-component-instance":{ "href":"http://localhost:8080/actuator/health/{component}/{instance}", "templated":true }, "health-component":{ "href":"http://localhost:8080/actuator/health/{component}", "templated":true }, "info":{ "href":"http://localhost:8080/actuator/info", "templated":false } } }
info相关:
http://localhost:8080/actuator/info
info.name=lucy
info.age=99
结果:
{"name":"zhangsan","age":"23"}
http://localhost:8080/actuator/health
开启健康检查详细信息:
# 开启健康检查的完整信息
management.endpoint.health.show-details=always
结果:
{"status":"UP","details":{"diskSpace":{"status":"UP","details":{"total":128726331392,"free":41764163584,"threshold":10485760}},"redis":{"status":"UP","details":{"version":"3.2.100"}}}}
开启所有endpoint,在application.properties中配置:
# 将所有的监控endpoint暴露出来
management.endpoints.web.exposure.include=*
开启所有endpoint的返回结果:
{ "_links":{ "self":{ "href":"http://localhost:8080/actuator", "templated":false }, "auditevents":{ "href":"http://localhost:8080/actuator/auditevents", "templated":false }, "beans":{ "href":"http://localhost:8080/actuator/beans", "templated":false }, "caches-cache":{ "href":"http://localhost:8080/actuator/caches/{cache}", "templated":true }, "caches":{ "href":"http://localhost:8080/actuator/caches", "templated":false }, "health-component-instance":{ "href":"http://localhost:8080/actuator/health/{component}/{instance}", "templated":true }, "health":{ "href":"http://localhost:8080/actuator/health", "templated":false }, "health-component":{ "href":"http://localhost:8080/actuator/health/{component}", "templated":true }, "conditions":{ "href":"http://localhost:8080/actuator/conditions", "templated":false }, "configprops":{ "href":"http://localhost:8080/actuator/configprops", "templated":false }, "env":{ "href":"http://localhost:8080/actuator/env", "templated":false }, "env-toMatch":{ "href":"http://localhost:8080/actuator/env/{toMatch}", "templated":true }, "info":{ "href":"http://localhost:8080/actuator/info", "templated":false }, "loggers":{ "href":"http://localhost:8080/actuator/loggers", "templated":false }, "loggers-name":{ "href":"http://localhost:8080/actuator/loggers/{name}", "templated":true }, "heapdump":{ "href":"http://localhost:8080/actuator/heapdump", "templated":false }, "threaddump":{ "href":"http://localhost:8080/actuator/threaddump", "templated":false }, "metrics-requiredMetricName":{ "href":"http://localhost:8080/actuator/metrics/{requiredMetricName}", "templated":true }, "metrics":{ "href":"http://localhost:8080/actuator/metrics", "templated":false }, "scheduledtasks":{ "href":"http://localhost:8080/actuator/scheduledtasks", "templated":false }, "httptrace":{ "href":"http://localhost:8080/actuator/httptrace", "templated":false }, "mappings":{ "href":"http://localhost:8080/actuator/mappings", "templated":false } } }
SpringBoot Admin 有两个角色,客户端(Client)和服务端(Server)。
admin-server:
①创建 admin-server 模块
②导入依赖坐标 admin-starter-server
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> </dependency>
③在引导类上启用监控功能@EnableAdminServer
@EnableAdminServer @SpringBootApplication public class SpringbootAdminServerApplication { public static void main(String[] args) { SpringApplication.run(SpringbootAdminServerApplication.class, args); } }
admin-client:
①创建 admin-client 模块
②导入依赖坐标 admin-starter-client
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> </dependency>
③配置相关信息:server地址等
# 执行admin.server地址 spring.boot.admin.client.url=http://localhost:9000 management.endpoint.health.show-details=always management.endpoints.web.exposure.include=*
④启动server和client服务,访问server,有很多监控到的信息。(某个请求访问的次数,所有的beans,JVM相关的,线程执行情况)