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可以在生产环境监控当前应用的健康,虚拟机等信息,通过前端以可视化的界面展示出来

  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值