Actuator插件是SpringBoot原生提供的一个服务,能够经过暴露端点路由,用来输出应用中的诸多 端点信息。实战一下!git
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
启动Spring Boot应用程序以后,只要在浏览器中输入端点信息就能得到应用的一些状态信息。github
经常使用端点列举以下,能够一个个详细试一下:spring
固然此时只能使用/health
和 /info
端点,其余由于权限问题没法访问。想访问指定端点的话能够在yml配置中添加相关的配置项,好比/metrics
端点则须要配置:浏览器
endpoints: metrics: sensitive: false
此时浏览器访问/metrics端点就能获得诸以下面所示的信息:session
{ "mem": 71529, "mem.free": 15073, "processors": 4, "instance.uptime": 6376, "uptime": 9447, "systemload.average": -1.0, "heap.committed": 48024, "heap.init": 16384, "heap.used": 32950, "heap": 506816, "nonheap.committed": 23840, "nonheap.init": 160, "nonheap.used": 23506, "nonheap": 0, "threads.peak": 25, "threads.daemon": 23, "threads.totalStarted": 28, "threads": 25, "classes": 6129, "classes.loaded": 6129, "classes.unloaded": 0, "gc.copy.count": 74, "gc.copy.time": 173, "gc.marksweepcompact.count": 3, "gc.marksweepcompact.time": 88, "httpsessions.max": -1, "httpsessions.active": 0 }
固然也能够开启所有端点权限,只需以下配置便可:spring-boot
endpoints: sensitive: false
因为Actuator插件提供的监控能力毕竟有限,并且UI比较简陋,所以须要一个更加成熟一点的工具工具
SBA则是基于Actuator更加进化了一步,其是一个针对Actuator接口进行UI美化封装的监控工具。咱们来实验一下。ui
pom.xml中加入以下依赖:url
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.5.7</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.5.7</version> </dependency>
而后在应用主类上经过加注解来启用Spring Boot Adminspa
@EnableAdminServer @SpringBootApplication public class SpringbtAdminServerApplication { public static void main(String[] args) { SpringApplication.run(SpringbtAdminServerApplication.class, args); } }
启动程序,浏览器打开 localhost:8081
查看Spring Boot Admin主页面:
Spring Boot Admin主页面
此时Application一栏空空如也,等待待监控的应用加入
pom.xml中加入如下依赖
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>1.5.7</version> </dependency>
而后在yml配置中添加以下配置,将应用注册到Admin服务端去:
spring: boot: admin: url: http://localhost:8081 client: name: AdminTest
Client应用一启动,Admin服务立马推送来了消息,告诉你AdminTest上线了:
应用上线推送消息
此时去Admin主界面上查看,发现Client应用确实已经注册上来了:
Client应用已注册上来
Detail信息
Metrics信息
Enviroment信息
JMX信息
Threads信息
Trace信息
点击最上方JOURNAL,会看到被监控应用程序的事件变化:
应用程序的事件变化信息
图中能够清晰地看到,应用从 REGISTRATION → UNKNOWN → UP 的状态跳转。
这样就将Actuator插件提供的全部端点信息在SBA中所有尝试了一遍。