欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

spring boot 管理员设置,监控 springboot 程序运行状态

最编程 2024-04-10 16:11:21
...

新建一个spring boot web项目,添加以下依赖

    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-starter-server</artifactId>
      <version>2.3.0</version>
    </dependency>
<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

spring boot的监控端点依赖必须的。

关于版本,springboot的版本前两位是什么,上面依赖的版本就对应什么版本,比如现在spring boot parent的版本是2.3.5,这里的依赖可以选择2.3开头的版本。下面是开启相关的端点功能

management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

添加以上依赖之后,如果项目使用的服务发现机制,把当前这个项目和其它需要监控的项目在同一个注册中心,这个项目就可以监控到所有其它实例的信息了。

如果不是通过注册中心,需要在其它的项目里面先添加依赖

    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-starter-client</artifactId>
    </dependency>

手动指定admin的springboot项目地址,如下

spring.boot.admin.client.url=http://localhost:8080

 如果项目添加了“server.servlet.context-path”,需要添加以下配置,避免admin服务通过默认的/actuator获取不到端点信息

spring.cloud.nacos.discovery.metadata.management.context-path=${server.servlet.context-path}/actuator

成功之后的界面如下

这下面这里可以动态修改某个类或者包的日志级别,避免重启服务