Spring Boot Admin 2.0开箱体验


概述

在我以前的 《Spring Boot应用监控实战》 一文中,讲述了如何利用 Spring Boot Admin 1.5.X 版原本可视化地监控 Spring Boot 应用。说时迟,那时快,如今 Spring Boot Admin 都更新到 2.0 版本了,而且能够对当下热门的 Spring Boot 2.0Spring Cloud Finchley.RELEASE 进行监控,所以本文就来了解并实践一下!git

注: 本文首发于 My 公众号 CodeSheep ,可 长按扫描 下面的 当心心 来订阅 ↓ ↓ ↓github

CodeSheep · 程序羊



Spring Boot Admin 2.0新特性

Spring Boot Admin 2.0 变化仍是挺多的,具体参考 官网说明,这里列几条主要的:web

  • 使用Vue.js重写了UI界面,漂亮得不像实力派spring

  • 直接集成了基于 spring security 的认证,无需引入第三方模块编程

  • 加入 session endpoint 的监控支持c#

等等...浏览器

下面就实际试验来操做感觉一下!bash



搭建 Spring Boot Admin Server

  • 建立一个 SpringBoot 2.0.3 RELEASE 工程并添加依赖
<dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.0.1</version>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
复制代码
  • 应用主类添加注解
@SpringBootApplication
@EnableAdminServer
public class SbaServer20Application {

    public static void main(String[] args) {
        SpringApplication.run(SbaServer20Application.class, args);
    }
}
复制代码
  • 启动 Spring Boot Admin Server

浏览器打开 localhost:8080,就能够看到小清新的页面了服务器

小清新的页面

能够看到这个 UI 的变化和 1.5.X 时代的差距仍是蛮大的,此时被监控的应用数目还为0。markdown

接下来咱们就来建立一个待监控的Spring Boot 2.0示例。



建立 Spring Boot Admin Client

此处咱们依然建立一个 Spring Boot 2.0.3.RELEASE 的应用,而后加入到Spring Boot Admin之中进行监控

  • pom.xml中添加依赖
<dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

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

复制代码
  • 编辑配置文件
server.port=8081
spring.application.name=Spring Boot Client
spring.boot.admin.client.url=http://localhost:8080
management.endpoints.web.exposure.include=*
复制代码
  • 启动 Spring Boot Admin Client 应用

此时 Spring Boot Admin的页面上应用上线的消息推送过来了:

应用上线推送



实际实验

被监控应用上线以后,咱们进入 Spring Boot Admin页面鼓捣看看

  • Wallboard 有点小清新

Wallboard

  • Applications 概览

Applications概览

  • Applications上线日志一目了然

Applications上线日志一目了然

  • Applications Details

Applications Details

  • Metrics

Metrics

  • Environment

Environment

  • JMX

JMX

  • Threads

Threads

  • Http Traces

Http Traces



后记

做者更多的SpringBt实践文章在此:


若是有兴趣,也能够抽点时间看看做者一些关于容器化、微服务化方面的文章:


CodeSheep · 程序羊
相关文章
相关标签/搜索