Spring Cloud学习之三 actuator监控与管理

目录

一、版本介绍

二、依赖引入

三、actuator介绍


一、版本介绍

本次工程是使用springboot 2.1.9版本 

二、依赖引入

工程中引入web和actuator依赖

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

三、actuator介绍

actuator模块可以获取整个微服务应用的相关指标以及实现一些常规操作控制。;我们可以将这些端点分为三类:应用配置类、度量指标类和操作控制类。

应用配置类:程序中加载的应用配置、环境变量、自动化配置报告和springboot应用相关的配置类信息;

/beans端点:用来获取上下文中创建的所有bean。

/configprops端点:用来获取应用中配置的属性信息报告。

/env端点:用来获取应用所有可用的环境属性报告。

/mappings端点:用来返回所有SpringMVC的控制器映射关系报告。

/info端点:用来返回一些自定义信息。

度量指标类:获取应用中用于监控的度量指标,如内存信息、线程池信息等‘

/metrics端点:用于返回当前应用的各类重要度量指标。

{"names":["jvm.memory.max","jvm.threads.states","jvm.gc.memory.promoted","jvm.memory.used","jvm.gc.max.data.size","jvm.gc.pause","jvm.memory.committed","system.cpu.count","logback.events","tomcat.global.sent","jvm.buffer.memory.used","tomcat.sessions.created","jvm.threads.daemon","system.cpu.usage","jvm.gc.memory.allocated","tomcat.global.request.max","tomcat.global.request","tomcat.sessions.expired","jvm.threads.live","jvm.threads.peak","tomcat.global.received","process.uptime","tomcat.sessions.rejected","process.cpu.usage","tomcat.threads.config.max","jvm.classes.loaded","jvm.classes.unloaded","tomcat.global.error","tomcat.sessions.active.current","tomcat.sessions.alive.max","jvm.gc.live.data.size","tomcat.threads.current","jvm.buffer.count","jvm.buffer.total.capacity","tomcat.sessions.active.max","tomcat.threads.busy","process.start.time"]}

/health端点:用来获取应用的各类健康指标。

{"status":"UP"}

 /threaddump端点:用来暴露程序运行中的线程信息。

/httptrace端点:用来返回基本的HTTP跟踪信息。

操作控制类:对应用关闭等操作类功能。’

/shutdown 端点:关闭应用。

以下为端点配置信息,更详细的可以参考:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

##管理端点HTTP端口
management.server.port= 8090
#management.endpoints.enabled-by-default = true
##暴露所有端点
management.endpoints.web.exposure.include = *
##是否启用configprops端点。
#management.endpoint.configprops.enabled=true
##是否启用beans端点。
#management.endpoint.beans.enabled=true
##可以缓存响应的最长时间。
#management.endpoint.beans.cache.time-to-live= 0ms
##是否启用beans端点。
#management.endpoint.health.enabled=true
##是否启用info端点。
#management.endpoint.info.enabled=true
##应包含的端点ID或所有的“*”
#management.endpoints.jmx.exposure.include=*
##应排除的端点ID或所有的'*'。
#management.endpoints.jmx.exposure.exclude = *
##是否启用env端点。
#management.endpoint.env.enabled=true
##是否启用mappings端点。
#management.endpoint.mappings.enabled=true
##是否启用metrics端点。
#management.endpoint.metrics.enabled=true
##是否启用threaddump端点
#management.endpoint.threaddump.enabled=true
##是否启用httptrace端点。
#management.endpoint.httptrace.enabled=true

我们通过http://localhost:8090/actuator就可以获取访问每个端点的连接如下:

{"_links":{"self":{"href":"http://localhost:8090/actuator","templated":false},"auditevents":{"href":"http://localhost:8090/actuator/auditevents","templated":false},"beans":{"href":"http://localhost:8090/actuator/beans","templated":false},"caches-cache":{"href":"http://localhost:8090/actuator/caches/{cache}","templated":true},"caches":{"href":"http://localhost:8090/actuator/caches","templated":false},"health":{"href":"http://localhost:8090/actuator/health","templated":false},"health-component":{"href":"http://localhost:8090/actuator/health/{component}","templated":true},"health-component-instance":{"href":"http://localhost:8090/actuator/health/{component}/{instance}","templated":true},"conditions":{"href":"http://localhost:8090/actuator/conditions","templated":false},"configprops":{"href":"http://localhost:8090/actuator/configprops","templated":false},"env":{"href":"http://localhost:8090/actuator/env","templated":false},"env-toMatch":{"href":"http://localhost:8090/actuator/env/{toMatch}","templated":true},"info":{"href":"http://localhost:8090/actuator/info","templated":false},"loggers":{"href":"http://localhost:8090/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:8090/actuator/loggers/{name}","templated":true},"heapdump":{"href":"http://localhost:8090/actuator/heapdump","templated":false},"threaddump":{"href":"http://localhost:8090/actuator/threaddump","templated":false},"metrics":{"href":"http://localhost:8090/actuator/metrics","templated":false},"metrics-requiredMetricName":{"href":"http://localhost:8090/actuator/metrics/{requiredMetricName}","templated":true},"scheduledtasks":{"href":"http://localhost:8090/actuator/scheduledtasks","templated":false},"httptrace":{"href":"http://localhost:8090/actuator/httptrace","templated":false},"mappings":{"href":"http://localhost:8090/actuator/mappings","templated":false}}}

 

 

猜你喜欢

转载自blog.csdn.net/weixin_42228950/article/details/102533361