如何监控springboot的健康状况


如何监控springboot的健康状况

SpringBoot1.5.19.RELEASE

一、使用Actuator检查与监控

actuaotr是spring boot项目中非常强大的一个功能,有助于对应用程序进行监控和管理,通过restful api请求来监管、审计、收集应用的运行情况,针对微服务而言它是必不可少的一个环节。

  1. 在pom文件中添加Actuator坐标
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
  1. 在全局配置文件中设置关闭安全限制

    management.security.enabled=false

  1. 运行,会发现控制台打印信息变多了

  1. 直接访问
    eg: <http://localhost:8080/health> <http://localhost:8080/dump><http://localhost:8080/beans>

具体可参考:<https://www.cnblogs.com/baidawei/p/9183531.html>

二、Spring Boot Admin

Spring Boot Admin 提供了很多功能,如显示 name、id 和 version,显示在线状态,Loggers 的日志级别管理,Threads 线程管理,Environment 管理等。

  1. 访问spring boot admin的github页面:https://github.com/codecentric/spring-boot-admin

-------以下内容在服务端操作:

  1. 在pom文件中添加spring boot admin 坐标
<dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>1.5.7</version>
        </dependency>
    </dependencies>
  1. 在启动类中增加注解:@EnableAdminServer
@SpringBootApplication
    @EnableAdminServer
    public class SpringbootHelloworldApplication {
        public static void main(String[] args) {
            SpringApplication.run(SpringbootHelloworldApplication.class, args);
        }
    }

-------以下内容在客户端操作:

  1. 客户端 (另一个项目)pom文件添加依赖
<dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-client</artifactId>
        <version>1.5.7</version>
    </dependency>
  1. 修改properties文件
#服务端的ip地址和端口
    spring.boot.admin.url: http://localhost:8383
    management.security.enabled=false
  1. 此时客户端的端口是:8080 ; 服务端的端口是8383

  2. 先启动服务端,打开网页:http://localhost:8383 (什么都没有,因为客户端还没启动)

  1. 启动客户端


原文链接:https://www.cnblogs.com/net-safe/p/13529230.html