您当前的位置: 首页 >  微服务

微服务技术系列教程(09) - SpringBoot - 监控管理 - Actuator

杨林伟 发布时间:2019-11-08 11:40:44 ,浏览量:4

代码已添加至Github,有兴趣的同学可以下载来看看:https://github.com/ylw-github/SpringBoot-Monitor-Demo

1. Actuator监控应用

Actuator 是spring boot的一个附加功能,可帮助你在应用程序生产环境时监视和管理应用程序。可以使用HTTP的各种请求来监管、审计、收集应用的运行情况,特别对于微服务管理十分有意义。

但是Actuator也有缺点:没有可视化界面。

下面我们来看看如何使用Actuator:

步骤一:添加maven依赖


    org.springframework.boot
    spring-boot-starter-parent
    2.0.0.RELEASE




    
        org.springframework.boot
        spring-boot-starter-web
    

    
        org.springframework.boot
        spring-boot-starter-actuator
    


2.在/src/main/resources/目录下新增application.yml

###通过下面的配置启用所有的监控端点,默认情况下,这些端点是禁用的;
management:
  endpoints:
    web:
      exposure:
        include: "*"
spring:
  profiles:
    active: prod

3.运行程序,通过actuator/+端点名就可以获取相应的信息 例如访问http://localhost:8080/actuator/env,可以看到陈列了所有的环境变量: 在这里插入图片描述

2. Actuator端点

从上面的讲解,我们知道可以通过actuator/+端点名就可以获取相应的信息。

路径作用/actuator/beans显示应用程序中所有Spring bean的完整列表。/actuator/configprops显示所有配置信息。/actuator/env陈列所有的环境变量。/actuator/mappings显示所有@RequestMapping的url整理列表。/actuator/health显示应用程序运行状况信息 up表示成功 down失败/actuator/info查看应用信息

比如现在想查看应用的信息,可以在application.yml新增info,如下: 在这里插入图片描述 运行http://localhost:8080/actuator/info: 在这里插入图片描述

总结

在这里插入图片描述

关注
打赏
1688896170
查看更多评论

杨林伟

暂无认证

  • 4浏览

    0关注

    3183博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0518s