Springboot Admin 是用於管理監控springboot 程序。Springboot Admin 分爲admin-server 和 admin-client兩個端。client端向server端註冊,也可以通過springcloud的eureka進行註冊,springboot admin2 纔有VUE.js重新編寫了頁面,不再是 admin 1.X採用的AngularJS編寫的前端頁面。監控的內容包括 actuator ,turbine, jmx , logleve
下面介紹兩種監控的實現方式,1)通過client端向server端註冊, 2)二通過eureka進行註冊
1、通過client端向server端註冊
首先創建一個名字爲admin-service的springboot項目, pom中加入如下依賴包
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.jly.admin</groupId>
<artifactId>admin-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>admin-service</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.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>2.0.1</spring-boot-admin.version>
</properties>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</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-web</artifactId>
</dependency>
<!-- <dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.0.5.RELEASE</version>
</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>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
配置文件如下application.yml
server:
port: 8761
spring:
application:
name: admin-service
output:
ansi:
enabled: always
boot:
admin:
#監控的斷點有哪些
probed-endpoints: health, env, etrics, threaddump:dump, httptrace:trace,jolokia, info, logfile, refresh, flyway, liquibase, heapdump, loggers, auditevents
#配置郵件監控
notify:
mail:
to: 接收郵件的郵箱
enabled: true
template: "classpath:/META-INF/spring-boot-admin-server/mail/status-changed.html" --郵件模板
from: 發送郵件的郵箱
mail:
host: smtp.qq.com
username: [email protected]
password: 郵箱的授權碼
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
logging:
file: "logs/boot-admin-sample.log"
info:
version: 1.0.0
3、然後在application的啓動類中加入@EnableAdminServer的註解,即可,springboot admin的程序搭建完成,現在搭建client,client相對簡單,只要你的程序是基於springboot即可,只需修改pom文件和application.yml這兩個即可。
4、在想要監控的程序的pom.xml文件中增加如下依賴
<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.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
5、在appliance.yml文件中加入如下配置
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
logfile:
enabled: true
以及
spring:
application:
name: transfer-service-dev
boot:
admin:
client:
url: http://localhost:8761
6、分別啓動demo-service和admin-service ,在瀏覽器中輸入localhost:8761,就能看到admin的面板了