【Spring Boot Admin】介绍以及使用

介绍

概述

Spring Boot Admin是一个监控工具,旨在以一种漂亮且易于访问的方式可视化Spring Boot Actuators提供的信息。

主要功能点

  • 显示应用程序的监控状态
  • 应用程序上下线监控
  • 查看 JVM,线程信息
  • 可视化的查看日志以及下载日志文件
  • 动态切换日志级别
  • Http 请求信息跟踪
  • 其他功能点......

相关网址推荐:GitHub仓库官方文档

创建Spring Boot Admin监控平台和客户端服务

Spring Boot Admin 监控平台服务

pom依赖

xml 复制代码
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.6.11</version>
        </dependency>
    </dependencies>
    
    <dependencyManagement>
        <dependencies>
            <!--Spring Boot 相关依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.5.3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

yml配置

yml 复制代码
server:
  port: 18000

spring:
  application:
    name: admin-server

启动类@EnableAdminServer

java 复制代码
package com.admin;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@EnableAdminServer
@SpringBootApplication
public class AdminServerApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(AdminServerApplication.class,args);
    }
}

服务启动成功后,访问链接:http://127.0.0.1:18000,查看监控平台。

客户端服务

pom依赖

xml 复制代码
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.6.11</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.14</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    
    <dependencyManagement>
        <dependencies>
            <!--Spring Boot 相关依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.5.3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

yml配置

yml 复制代码
spring:
  application:
    name: admin-order
  # spring boot admin
  boot:
    admin:
      client:
        url: http://127.0.0.1:18000
        instance:
          prefer-ip: true
          name: ${spring.application.name}

server:
  port: 18001

#  endpoints config
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always

logging:
  # 只有配置了日志文件,才能被监控收集
  file:
    name: logs/${spring.application.name}/${spring.application.name}.log

启动类

java 复制代码
package com.admin;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Slf4j
@SpringBootApplication
public class AdminOrderApp {
    public static void main(String[] args) {
        SpringApplication.run(AdminOrderApp.class, args);
    }
}

服务启动成功后,访问监控平台,就能监控admin-order服务了。

注意:如果监控平台上没有看见客户端服务,则需要重启Spring Boot Admin 监控服务

控制台展示

其他功能(专栏中其他文档)

【Spring Boot Admin】使用(整合Spring Cloud服务)
【Spring Boot Admin】使用(整合Spring Security服务,添加鉴权)

参考连接:Spring Boot Admin 介绍及使用

相关推荐
程序员爱钓鱼28 分钟前
Go语言实战案例-创建模型并自动迁移
后端·google·go
javachen__33 分钟前
SpringBoot整合P6Spy实现全链路SQL监控
spring boot·后端·sql
uzong6 小时前
技术故障复盘模版
后端
GetcharZp6 小时前
基于 Dify + 通义千问的多模态大模型 搭建发票识别 Agent
后端·llm·agent
桦说编程7 小时前
Java 中如何创建不可变类型
java·后端·函数式编程
lifallen7 小时前
Java Stream sort算子实现:SortedOps
java·开发语言
IT毕设实战小研7 小时前
基于Spring Boot 4s店车辆管理系统 租车管理系统 停车位管理系统 智慧车辆管理系统
java·开发语言·spring boot·后端·spring·毕业设计·课程设计
wyiyiyi7 小时前
【Web后端】Django、flask及其场景——以构建系统原型为例
前端·数据库·后端·python·django·flask
没有bug.的程序员8 小时前
JVM 总览与运行原理:深入Java虚拟机的核心引擎
java·jvm·python·虚拟机
一只爱撸猫的程序猿8 小时前
使用Spring AI配合MCP(Model Context Protocol)构建一个"智能代码审查助手"
spring boot·aigc·ai编程