Spring Boot Admin 监控搭建

文章目录

  • Spring Boot Admin 监控
    • 前言
    • 一图简介
    • Spring Boot 集成 Spring Boot Admin
      • Spring Boot Admin Server
        • pom.xml
        • 应用启动程序
        • yml
      • Spring Boot Admin Client
        • pom.xml
        • 应用启动程序
        • yml
      • admin控制台
        • applications
        • Wallboard
    • 注意

Spring Boot Admin 监控

前言

通过Spring Boot Admin 对系统进行监控,可以同时监控多个客户端。

分为至少两个端(server & client),server作为监控主进程,client作为加入监控主进程的客户端,需要一个admin server,然后再admin client(客户端)的yml总配置即可。

一图简介

Spring Boot Admin 监控搭建_第1张图片

  • 如上图所示,服务器监控系统同时对PC、ADMIN、APP进行监控,在监控系统中(server端),即可以看到这些对应的客户端运行情况。

Spring Boot 集成 Spring Boot Admin

创建spring boot项目,版本使用2.1+ 如下:


<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.0modelVersion>

    <groupId>spring-boot-admingroupId>
    <artifactId>spring-boot-adminartifactId>
    <packaging>pompackaging>
    <version>1.0-SNAPSHOTversion>
    <modules>
        <module>spring-boot-admin-clientmodule>
        <module>spring-boot-admin-serversmodule>
    modules>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.1.0.RELEASEversion>
        <relativePath/>
    parent>

    <properties>
        <java.version>1.8java.version>
    properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>

project>

Spring Boot Admin Server

Admin Server作为服务器监控的程序,类似于一个服务提供者,其他客户端要与之建立关系(其实不该这么不专业的作为解释,为了方便理解,这里我就这么记载了)

pom.xml

    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>de.codecentricgroupId>
            <artifactId>spring-boot-admin-starter-serverartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
    dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>de.codecentricgroupId>
                <artifactId>spring-boot-admin-dependenciesartifactId>
                <version>2.1.3version>
                <type>pomtype>
                <scope>importscope>
            dependency>
        dependencies>
    dependencyManagement>

应用启动程序

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

yml

spring:
  application:
    name: spring-boot-admin-server
server:
  port: 8769

Spring Boot Admin Client

同样是Spring Boot项目,版本也要相一致

pom.xml

	<dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>de.codecentricgroupId>
            <artifactId>spring-boot-admin-starter-clientartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
    dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>de.codecentricgroupId>
                <artifactId>spring-boot-admin-dependenciesartifactId>
                <version>2.1.3version>
                <type>pomtype>
                <scope>importscope>
            dependency>
        dependencies>
    dependencyManagement>

应用启动程序

常规启动类

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

yml

spring:
  application:
    name: spring-bootadmin-client
  boot:
    admin:
      client:
        # 要注册的Spring Boot Admin Server的URL
        url: http://localhost:8769
server:
  port: 8768

# 与Spring Boot 2一样,默认情况下,大多数actuator的端口都不会通过http公开,* 代表公开所有这些端点。对于生产环境,应该仔细选择要公开的端点。
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: ALWAYS

admin控制台

按照上面的配置,我们的Admin监控就可以使用了。
访问地址:http://localhost:8769
系统自动跳转到:http://localhost:8769/#/applications
这个例子我们并没有配置 Security来作服务器端鉴权。

applications

Spring Boot Admin 监控搭建_第2张图片

Wallboard

Spring Boot Admin 监控搭建_第3张图片
进入之后:

Spring Boot Admin 监控搭建_第4张图片

注意

因为使用的 Spring Boot Admin的版本是2.1+,所以Spring Boot也要使用2.1+以上版本,否则无法启动admin server。

你可能感兴趣的:(Spring,Boot,Admin,Spring,Boot,监控,技术总结,Java,项目管理,监控系统)