5分鐘瞭解 SpringBootAdmin

SpringBootAdmin

概述

簡單來講,Spring Boot Admin是一個管理和監控Spring Boot應用程序的開源軟件。每一個應用都認爲是一個客戶端,經過HTTP或者服務註冊發現Spring Cloud(Eureka、Consul等等)註冊到admin server中進行展現,Spring Boot Admin UI部分使用AngularJs將數據展現在前端。前端

Spring Boot Admin是一個針對spring-boot的actuator接口進行UI美化封裝的監控工具。它能夠:在列表中瀏覽全部被監控spring-boot項目的基本信息,詳細的Health信息、內存信息、JVM信息、垃圾回收信息、各類配置信息(好比數據源、緩存列表和命中率)等,還能夠直接修改logger的level。java

工程搭建

搭建springboot-admin-server工程

  1. pom.xml配置,引入spring-boot-admin-starter-server
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.0.1</version>
</dependency>
複製代碼
  1. 建立application.yml文件,配置基本內容
server:
 port: 8080
spring:
 application:
 name: service-admin
複製代碼
  1. 建立引導類添加@EnableAdminServer開啓adminServer
@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {
    public static void main(String[] args) {
    	SpringApplication.run(AdminServerApplication.class, args);
    }
}
複製代碼
  1. 訪問localhost:8080,能看到如下頁面,就成功了。目前這裏面尚未任何springboot的工程項目被接入監控。

springboot工程接入監控

講web_a工程接入監控,在工程中加入如下信息web

  1. pom.xml中加入依賴
<dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.0.1</version>
        </dependency>
複製代碼
  1. 在application.yml中
 server:
 port: 8091
 spring:
 application:
 name: web_a
 boot:
 admin:
 client:
 url: http://127.0.0.1:8080  #配置須要接入的admin-server地址
 management:
 endpoints:
 web:
 exposure:
 include: "*"
   
複製代碼
  1. 刷新http://localhost:8080,查看web_a,已經接入admin的管理。

界面介紹

點擊web_a,進入監控管理頁面,介紹幾個經常使用的TAB界面。spring

Details

在details頁面,能看到應用的基本信息以下圖。緩存

Environment

在Environment頁面,能夠看到應用中國的各類環境變量。springboot

Loggers

在Loggers中能夠看到各層級包的日誌打印級別,而且能夠經過界面動態修改。app

  • 當前com包下面的日誌打印級別爲debug

  • 在web_a應用中添加以下的controller,訪問localhost:8091/hell0,就應該看到,error, warn,info,debug四種級別的日誌都打印出來。
package com.itheima.controller;  
  
@RestController
@Slf4j
public class AController {
      @GetMapping("/hello")
      public String hello(){
          log.warn("test 日誌切換 warn");
          log.info("test 日誌切換 info");
          log.debug("test 日誌切換 debug");
          log.error("test 日誌切換 error");
          return "this is a!";
     }
 }
複製代碼
  • 將com包下的日誌級別改成info,那麼再次訪問上面的接口,就只有error, warn,info,三種級別的日了。以下圖所示。

Thread

展現的是系統中各類線程隨時間變化的狀態,其中黃色部分爲WAITING等待狀態,而綠色部分爲RUNNALE運行狀態。spring-boot

HttpTraces

HttpTraces顯示的是應用隨着時間變化的http請求訪問量。固然點擊下面的每個具體的狀況,能夠看到請求的詳情,也能夠經過篩選,只查看訪問特定url的請求。工具

總結

本文介紹了SpringbootAdmin的基本搭建,Springboot工程快速接入,以及相關管理界面的介紹。幫助你們快速上手瞭解SpringBootAdmin對於Springboot工程服務的監控和健康管理。其實Springboot還能夠設置通知,好比當某個SpringBoot應用掛了,但願經過郵件的形式通知某些管理員。這些也都是能夠實現的。只是在本文中沒有詳細說明。this

相關文章
相關標籤/搜索