Spring Boot Admin

Spring Boot Admin 是一个针对spring-boot的actuator接口进行UI美化封装的监控工具。

<?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>

    <groupId>com.example</groupId>
    <artifactId>admin-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>admin-server</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.12.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>1.5.7</spring-boot-admin.version>
        <spring-cloud.version>Edgware.SR3</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-hystrix</artifactId>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-turbine</artifactId>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-activiti</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>

        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>${spring-boot-admin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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


</project>

添加 @EnableAdminServer

@EnableAdminServer
@EnableDiscoveryClient
@SpringBootApplication
public class AdminServerApplication {

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

application.yml

server:
  port: 9001
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8081/eureka-server/eureka/
spring:
  application:
    name: admin-server
  boot:
    admin:
      context-path: /monitor
#      turbine:
#        clusters: default
#        location: turbine
      routes:
        endpoints: env,metrics,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents,hystrix.stream
      monitor:
#      更新应用信息的频率,单位毫秒
        period:  1000
#      被监控的应用信息的过期时间,单位毫秒
        status-lifetime: 1000
management:
  security:
    enabled: false
endpoints:
  logfile:
#   配置了 external-file 才能在监控页面上看到 Log 这一列
    external-file: C:\Users\市丸 银\AppData\Local\Temp\spring.log

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration >

    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <!-- 开启JMX监控 -->
    <jmxConfigurator/>

</configuration> 

只要有服务注册到 Eureka 上,Spring Boot Admin 就能自动获取它的监控信息,无需多余的配置

注意:如果服务配置了server.context-path,一定还要配置下面2个,否则Spring Boot Admin无法获取该服务完整的监控数据(eureka server 会维护一份只读的服务清单返回给客户端,同时该缓存清单默认会每隔30s更新一次,metadataMap 中的信息会包含在清单里面)

    /**
     * Gets the metadata name/value pairs associated with this instance. This information
     * is sent to eureka server and can be used by other instances.
     */
     private Map<String, String> metadataMap = new HashMap<>();
eureka.instance.metadata-map.management.context-path=${server.context-path}
eureka.instance.metadata-map.management.context-port=${server.port}

Spring Boot Admin 的监控页面
这里写图片描述

Spring Boot Admin 有很多定时任务,当有新的服务注册到 Eureka了,会自动通知你,监控页面的信息也会自动更新
这里写图片描述

如果监控的服务使用了Hystrix,Spring Boot Admin只要添加依赖spring-boot-admin-server-ui-hystrix ,就可以监控到

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-hystrix</artifactId>
        </dependency>

这里写图片描述

详细的监控数据
这里写图片描述
这里写图片描述

这里可以查看和更改环境变量
这里写图片描述

这里可以修改日志级别,会立即生效
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值