Spring Boot Admin 监控中心

时间:2022-12-23 19:27:49

Spring Boot Admin 监控中心

Spring Boot Admin用来收集微服务系统的健康状态、会话数量、并发数、服务资源、延迟等度量信息

服务端

建立spring-cloud-admin maven工程,导入pom依赖和完善目录结构

pom依赖

pom.xml 注意增加了两个依赖:

org.jolokia:jolokia-core、de.codecentric:spring-boot-admin-starter-server

注意maven依赖的版本:在新建maven项目完善结构时,下载,启动报错很大可能就是maven版本依赖不对,因为版本在不断更新,有些版本和插件会被更新或废弃,这时需要自己去仓库确认

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<groupId>com.outlook.liufei32</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../spring-cloud-dependencies/pom.xml</relativePath>
</parent> <artifactId>spring-cloud-admin</artifactId>
<packaging>jar</packaging> <name>spring-cloud-admin</name>
<url></url>
<inceptionYear>2019-Now</inceptionYear> <dependencies>
<!-- Spring Boot Begin -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<!-- Spring Boot End --> <!-- Spring Cloud Begin -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!-- Spring Cloud End -->
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.outlook.liufei32.spring.cloud.admin.AdminApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

启动类中增加@EnableAdminServer注解

package com.outlook.liufei32.spring.cloud.admin;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication
@EnableAdminServer
@EnableEurekaClient
public class AdminApplication {
public static void main( String[] args ) {
SpringApplication.run(AdminApplication.class, args);
}
}

配置application.yml

spring:
application:
name: spring-cloud-admin
zipkin:
base-url: http://localhost:9411 server:
port: 8084 management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: health,info eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/

启动访问

输入yml配置的url :http://localhost:8084

Spring Boot Admin 监控中心

客户端

客户端的配置就是将需要监控的微服务注册到admin的服务端

1.增加pom依赖

<!--admin监控客户端 start-->
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<!--admin监控客户端 end-->

2.配置yml

spring:
boot:
admin:
client:
url: http://localhost:8084

启动完成就能监控服务情况

Spring Boot Admin 监控中心

本博客为Swagger-Ranger的笔记分享,文章会持续更新

文中源码地址: https://github.com/Swagger-Ranger

欢迎交流指正,如有侵权请联系作者确认删除: liufei32@outlook.com