【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 介绍及使用

相关推荐
珹洺23 分钟前
Java-servlet(完结篇)过滤器乱码解决与监听器
java·运维·服务器·hive·servlet·jsp
小开不是小可爱1 小时前
leetcode_383. 赎金信_java
java·数据结构·算法·leetcode
敏君宝爸1 小时前
SpringBoot2.x整合Prometheus+Grafana以及自定义采集
spring boot·grafana·prometheus
kill bert4 小时前
Java八股文背诵 第四天JVM
java·开发语言·jvm
在荒野的梦想5 小时前
若依微服务集成Flowable仿钉钉工作流
spring cloud·微服务·钉钉
uhakadotcom7 小时前
RunPod:AI云计算的强大助手
后端·面试·github
Pitayafruit7 小时前
📌 Java 工程师进阶必备:Spring Boot 3 + Netty 构建高并发即时通讯服务
spring boot·后端·netty
uhakadotcom7 小时前
Google AlloyDB AI 与 PostgreSQL 的核心区别
后端·面试·github
uhakadotcom7 小时前
使用Go语言编写简单爬虫程序
后端·面试·github
梦想实现家_Z7 小时前
SpringBoot实现MCP Server实战详解
spring boot·后端·mcp