最新版 !快速掌握 JDK17 + springboot3 + springcloud Alibaba :12、Spring Boot Admin 实现服务监控

1 功能

实现健康 (Health)信息、内存信息、JVM 系统和环境属性、垃圾回收信息、日志设置和查看、定时任务查看、Spring Boot 缓存查看和管理等功能

2 新增 admin-server子服务

2.1 父工程新增依赖

<spring.boot.admin.version>3.0.4spring.boot.admin.version> 
 

 <dependency>
     <groupId>de.codecentricgroupId>
     <artifactId>spring-boot-admin-starter-serverartifactId>
     <version>${spring.boot.admin.version}version>
 dependency>
 <dependency>
     <groupId>de.codecentricgroupId>
     <artifactId>spring-boot-admin-starter-clientartifactId>
     <version>${spring.boot.admin.version}version>
 dependency>

2.2 admin服务增加依赖

         
		<dependency>
			<groupId>com.alibaba.cloudgroupId>
			<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
		dependency>
		<dependency>
			<groupId>de.codecentricgroupId>
			<artifactId>spring-boot-admin-starter-serverartifactId>
		dependency>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-actuatorartifactId>
		dependency>

2.3 主程序支持admin

启动入口程序,加上@EnableAdminServer注解即可

package com.example.admin;

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

@SpringBootApplication
@EnableAdminServer
public class ShopAdminServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(ShopAdminServerApplication.class, args);
	}

}

2.4 配置yaml

server:
  port: 7001
  servlet:
    context-path: /admin
spring:
  application:
    name: shop-admin
  cloud:
    nacos:
      #服务发现
      discovery:
        enabled: true
        server-addr: localhost:8848
        metadata:
          management:
            context-path: ${server.servlet.context-path}/actuator
    
  thymeleaf:
    check-template: false
    check-template-location: false


#暴露端点
management:
  endpoint:
    health:
      show-details: always
  endpoints:
    web:
      exposure:
        include: '*'


3 被监控子服务改造

3.1 增加依赖

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-actuatorartifactId>
        dependency>

3.2 增加admin配置

# SpringBoot Admin 新增
# 暴露端点
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

启动服务,验证。注意最后启动admin服务

最新版 !快速掌握 JDK17 + springboot3 + springcloud Alibaba :12、Spring Boot Admin 实现服务监控_第1张图片

你可能感兴趣的:(springcloud,Alibaba,spring,cloud,spring,boot,spring)