springboot(二)Actuator的作用和使用

Actuator

actuator是springboot中的一个附加功能,官方是对它这样介绍的:

Spring Boot includes a number of additional features to help you monitor and manage your application when you push it to production. You can choose to manage and monitor your application by using HTTP endpoints or with JMX. Auditing, health, and metrics gathering can also be automatically applied to your application.

用法:

1.首先在springboot工程中引入依赖:

Maven方式:

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

Gradle:

 dependencies { compile("org.springframework.boot:
 spring-boot-starter-actuator")

2.启动springboot项目
这里写图片描述
在启动log日志中,可以看到springboot把一些默认的地址都映射好了,其中我们配置的actuator中health和info已经被映射上了,我们打开地址:http://localhost:8080/actuator/info 或者 http://localhost:8080/actuator/health
这里写图片描述

springboot 官方提供的Actuator

这里写图片描述
当然,这只是一部分,我这里不全部粘贴出来了,感兴趣的同学可以到官网上去看,springboot2.0之后,在Http环境下将默认的endpoint只设置为info和health,要想开启其他的监控功能,需要手动配置
打开application.properties或者application.yml:
备注:application.yml文件作为例子:

server:
  port: 8080 #web服务端口
management:  #actuator
  server:
    port: 8081
  endpoints:
    web:
      base-path: /
      exposure:
        include: "*"

如果将include这只为*,则开启全部监控功能,如果只想开启某个功能的监控,则,include中传你要开启的endpoint的名称,例如,我要开启beans和metrics功能include: beans,metrics
这里写图片描述
从图中可以看出,所有的功能都被mapping到响应的URL上了

通过访问http://localhost:8081/httptrace
我们可以看到最近浏览的网页记录
这里写图片描述

总结

通过Actuator可以在生产环境监控当前应用的健康,虚拟机等信息,通过前端以可视化的界面展示出来

猜你喜欢

转载自blog.csdn.net/tangyaya8/article/details/81157747
今日推荐