[TOC]
## 什么是Spring Boot Admin?
>Spring Boot Admin 是一個管理和監控Spring Boot 應用程序的開源軟件。每個應用都認為是一個客戶端,通過HTTP或者使用 Eureka注冊到admin server中進行展示,Spring Boot Admin UI部分使用AngularJs將數據展示在前端。
Spring Boot Admin 是一個針對spring-boot的actuator接口進行UI美化封裝的監控工具。他可以:在列表中瀏覽所有被監控spring-boot項目的基本信息,詳細的Health信息、內存信息、JVM信息、垃圾回收信息、各種配置信息(比如數據源、緩存列表和命中率)等,還可以直接修改logger的level。
這篇文章給大家介紹如何使用Spring Boot Admin對Spring Boot應用進行監控。
參考:

## Actuator 監控
Spring Boot 自帶了 Actuator 監控功能,主要用于提供對應用程序監控,以及控制的能力,比如監控應用程序的運行狀況,或者內存、線程池、Http 請求統計等,同時還提供了關閉應用程序等功能。
Actuator 提供了 19 個接口,接口請求地址和代表含義如下表所示:
| 訪問路徑 | 描述 |
| --- | --- |
|/auditevents| 顯示應用暴露的審計事件(比如認證進入)|
|/beans| 顯示應用程序中所有 Spring Bean 的完整列表|
|/caches |公開可用的緩存|
|/conditions |顯示在配置和自動配置類上評估的條件以及它們匹配或不匹配的原因|
|/configprops |顯示所有 @ConfigurationPropertie 的整理列表|
|/env |獲取全部環境屬性|
|/flyway| 提供一份 Flyway 數據庫遷移信息|
|/health| 顯示應用程序運行狀況信息|
|/httptrace |顯示 HTTP 跟蹤信息(默認情況下,最近 100 個 HTTP 請求-響應交換)
|/info |獲取應用程序的定制信息,這些信息由 info 開頭的屬性提供|
|/integrationgraph |顯示 Spring Integration 圖,需要依賴于 spring-integration-core|
|/loggers| 顯示和修改應用程序的配置|
|/liquibase| 顯示已應用的所有 Liquibase 數據庫遷移|
|/metrics/{name} |報告指定名稱的應用程序度量值|
|/mappings |顯示所有 @RequestMapping 路徑的列表|
|/scheduledtasks| 顯示應用程序中的計劃任務|
|/sessions |允許從 Spring Session 支持的會話存儲中檢索和刪除用戶會話,需要使用 Spring Session 基于 Servlet 的 Web 應用程序|
|/shutdown |使應用程序正常關閉,默認禁用|
|/threaddump |獲取線程活動的快照|
## 監控單體應用
>這節給大家展示如何使用Spring Boot Admin監控單個Spring Boot應用。
### Admin Server端
```
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.1</version>
</dependency>
```
配置文件
~~~
server.port=9001
~~~
服務端設置端口為:9001。
啟動類
~~~
package com.open.capacity;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author 作者 owen E-mail: 624191343@qq.com
* @version 創建時間:2017年12月8日 上午9:03:32
* 類說明
*/
@EnableAdminServer
@EnableDiscoveryClient
@SpringBootApplication
public class MonitorApp {
public static void main(String[] args) {
SpringApplication.run(MonitorApp.class, args);
}
}
~~~
完成上面三步之后,啟動服務端,瀏覽器訪問`http://localhost:9001`可以看到以下界面:

### Admin Client端
項目依賴
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
```
>Spring Boot Actuator可以幫助你監控和管理Spring Boot應用,比如健康檢查、審計、統計和HTTP追蹤等。所有的這些特性可以通過JMX或者HTTP endpoints來獲得。
Actuator同時還可以與外部應用監控系統整合,比如[Prometheus](https://prometheus.io/),[Graphite](https://graphiteapp.org/),[DataDog](https://www.datadoghq.com/),[Influx](https://www.influxdata.com/),[Wavefront](https://www.wavefront.com/),[New Relic](https://newrelic.com/)等。這些系統提供了非常好的儀表盤、圖標、分析和告警等功能,使得你可以通過統一的接口輕松的監控和管理你的應用。
Actuator使用[Micrometer](http://micrometer.io/)來整合上面提到的外部應用監控系統。這使得只要通過非常小的配置就可以集成任何應用監控系統。
啟動客戶端后

### 郵件告警
配置告警郵箱

>Spring Boot Admin將微服務中所有應用信息在后臺進行了展示,非常方便我們對微服務整體的監控和治理。但是我們的運營人員也不可能一天24小時盯著監控后臺,因此如果服務有異常的時候,有對應的郵件告警就太好了,其實Spring Boot Admin也給出了支持。
我們對上面的示例項目spring-boot-admin-server進行改造。
添加依賴
~~~
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
~~~
增加了郵件發送的starter包
配置文件
~~~
spring:
application:
name: admin-server
boot:
admin:
notify:
mail:
enabled: true
to: xxxxxxxxxxx
from: xxxxxxxxxxx
# ignore-changes: UNKNOWN:UP
ignore-changes:
-
"*:UP" #從任何狀態到up狀態都不要發郵件通知
routes:
endpoints: env,metrics,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents,hystrix.stream
turbine:
clusters: default
#,unieap-eureka-server-single
location: turbine
mail:
host: smtp.163.com
username: xxxxxxxxxxx
password: xxxxxxxxxxx
properties:
mail.smtp.auth : true
mail.smtp.timeout : 2000
mail.smtp.starttls.enable : true
mail.smtp.starttls.required : true
~~~
>在配置文件中添加郵件發送相關信息:郵件的發送者、接受者、協議、移動授權碼等。
配置完成后,重新啟動項目admin-server,這樣Admin Server就具備了郵件告警的功能。
- 前言
- 1.項目說明
- 2.項目更新日志
- 3.文檔更新日志
- 01.快速開始
- 01.maven構建項目
- 02.環境安裝
- 03.STS項目導入
- 03.IDEA項目導入
- 04.數據初始化
- 05.項目啟動
- 06.付費文檔說明
- 02.總體流程
- 1.oauth接口
- 2.架構設計圖
- 3.微服務介紹
- 4.功能介紹
- 5.梳理流程
- 03.模塊詳解
- 01.老版本1.0.1分支模塊講解
- 01.db-core模塊
- 02.api-commons模塊
- 03.log-core模塊
- 04.security-core模塊
- 05.swagger-core模塊
- 06.eureka-server模塊
- 07.auth-server模塊
- 08.auth-sso模塊解析
- 09.user-center模塊
- 10.api-gateway模塊
- 11.file-center模塊
- 12.log-center模塊
- 13.batch-center模塊
- 14.back-center模塊
- 02.spring-boot-starter-web那點事
- 03.自定義db-spring-boot-starter
- 04.自定義log-spring-boot-starter
- 05.自定義redis-spring-boot-starter
- 06.自定義common-spring-boot-starter
- 07.自定義swagger-spring-boot-starter
- 08.自定義uaa-server-spring-boot-starter
- 09.自定義uaa-client-spring-boot-starter
- 10.自定義ribbon-spring-boot-starter
- 11.springboot啟動原理
- 12.eureka-server模塊
- 13.auth-server模塊
- 14.user-center模塊
- 15.api-gateway模塊
- 16.file-center模塊
- 17.log-center模塊
- 18.back-center模塊
- 19.auth-sso模塊
- 20.admin-server模塊
- 21.zipkin-center模塊
- 22.job-center模塊
- 23.batch-center
- 04.全新網關
- 01.基于spring cloud gateway的new-api-gateway
- 02.spring cloud gateway整合Spring Security Oauth
- 03.基于spring cloud gateway的redis動態路由
- 04.spring cloud gateway聚合swagger文檔
- 05.技術詳解
- 01.互聯網系統設計原則
- 02.系統冪等性設計與實踐
- 03.Oauth最簡向導開發指南
- 04.oauth jdbc持久化策略
- 05.JWT token方式啟用
- 06.token有效期的處理
- 07.@PreAuthorize注解分析
- 08.獲取當前用戶信息
- 09.認證授權白名單配置
- 10.OCP權限設計
- 11.服務安全流程
- 12.認證授權詳解
- 13.驗證碼技術
- 14.短信驗證碼登錄
- 15.動態數據源配置
- 16.分頁插件使用
- 17.緩存擊穿
- 18.分布式主鍵生成策略
- 19.分布式定時任務
- 20.分布式鎖
- 21.網關多維度限流
- 22.跨域處理
- 23.容錯限流
- 24.應用訪問次數控制
- 25.統一業務異常處理
- 26.日志埋點
- 27.GPRC內部通信
- 28.服務間調用
- 29.ribbon負載均衡
- 30.微服務分布式跟蹤
- 31.異步與線程傳遞變量
- 32.死信隊列延時消息
- 33.單元測試用例
- 34.Greenwich.RELEASE升級
- 35.混沌工程質量保證
- 06.開發初探
- 1.開發技巧
- 2.crud例子
- 3.新建服務
- 4.區分前后臺用戶
- 07.分表分庫
- 08.分布式事務
- 1.Seata介紹
- 2.Seata部署
- 09.shell部署
- 01.eureka-server
- 02.user-center
- 03.auth-server
- 04.api-gateway
- 05.file-center
- 06.log-center
- 07.back-center
- 08.編寫shell腳本
- 09.集群shell部署
- 10.集群shell啟動
- 11.部署阿里云問題
- 10.網關安全
- 1.openresty https保障服務安全
- 2.openresty WAF應用防火墻
- 3.openresty 高可用
- 11.docker配置
- 01.docker安裝
- 02.Docker 開啟遠程API
- 03.采用docker方式打包到服務器
- 04.docker創建mysql
- 05.docker網絡原理
- 06.docker實戰
- 6.01.安裝docker
- 6.02.管理鏡像基本命令
- 6.03.容器管理
- 6.04容器數據持久化
- 6.05網絡模式
- 6.06.Dockerfile
- 6.07.harbor部署
- 6.08.使用自定義鏡像
- 12.統一監控中心
- 01.spring boot admin監控
- 02.Arthas診斷利器
- 03.nginx監控(filebeat+es+grafana)
- 04.Prometheus監控
- 05.redis監控(redis+prometheus+grafana)
- 06.mysql監控(mysqld_exporter+prometheus+grafana)
- 07.elasticsearch監控(elasticsearch-exporter+prometheus+grafana)
- 08.linux監控(node_exporter+prometheus+grafana)
- 09.micoservice監控
- 10.nacos監控
- 11.druid數據源監控
- 12.prometheus.yml
- 13.grafana告警
- 14.Alertmanager告警
- 15.監控微信告警
- 16.關于接口監控告警
- 17.prometheus-HA架構
- 18.總結
- 13.統一日志中心
- 01.統一日志中心建設意義
- 02.通過ELK收集mysql慢查詢日志
- 03.通過elk收集微服務模塊日志
- 04.通過elk收集nginx日志
- 05.統一日志中心性能優化
- 06.kibana安裝部署
- 07.日志清理方案
- 08.日志性能測試指標
- 09.總結
- 14.數據查詢平臺
- 01.數據查詢平臺架構
- 02.mysql配置bin-log
- 03.單節點canal-server
- 04.canal-ha部署
- 05.canal-kafka部署
- 06.實時增量數據同步mysql
- 07.canal監控
- 08.clickhouse運維常見腳本
- 15.APM監控
- 1.Elastic APM
- 2.Skywalking
- 01.docker部署es
- 02.部署skywalking-server
- 03.部署skywalking-agent
- 16.壓力測試
- 1.ocp.jmx
- 2.test.bat
- 3.壓測腳本
- 4.壓力報告
- 5.報告分析
- 6.壓測平臺
- 7.并發測試
- 8.wrk工具
- 9.nmon
- 10.jmh測試
- 17.SQL優化
- 1.oracle篇
- 01.基線測試
- 02.調優前奏
- 03.線上瓶頸定位
- 04.執行計劃解讀
- 05.高級SQL語句
- 06.SQL tuning
- 07.數據恢復
- 08.深入10053事件
- 09.深入10046事件
- 2.mysql篇
- 01.innodb存儲引擎
- 02.BTree索引
- 03.執行計劃
- 04.查詢優化案例分析
- 05.為什么會走錯索引
- 06.表連接優化問題
- 07.Connection連接參數
- 08.Centos7系統參數調優
- 09.mysql監控
- 10.高級SQL語句
- 11.常用維護腳本
- 12.percona-toolkit
- 18.redis高可用方案
- 1.免密登錄
- 2.安裝部署
- 3.配置文件
- 4.啟動腳本
- 19.消息中間件搭建
- 19-01.rabbitmq集群搭建
- 01.rabbitmq01
- 02.rabbitmq02
- 03.rabbitmq03
- 04.鏡像隊列
- 05.haproxy搭建
- 06.keepalived
- 19-02.rocketmq搭建
- 19-03.kafka集群
- 20.mysql高可用方案
- 1.環境
- 2.mysql部署
- 3.Xtrabackup部署
- 4.Galera部署
- 5.galera for mysql 集群
- 6.haproxy+keepalived部署
- 21.es集群部署
- 22.生產實施優化
- 1.linux優化
- 2.jvm優化
- 3.feign優化
- 4.zuul性能優化
- 23.線上問題診斷
- 01.CPU性能評估工具
- 02.內存性能評估工具
- 03.IO性能評估工具
- 04.網絡問題工具
- 05.綜合診斷評估工具
- 06.案例診斷01
- 07.案例診斷02
- 08.案例診斷03
- 09.案例診斷04
- 10.遠程debug
- 24.fiddler抓包實戰
- 01.fiddler介紹
- 02.web端抓包
- 03.app抓包
- 25.疑難解答交流
- 01.有了auth/token獲取token了為啥還要配置security的登錄配置
- 02.權限數據存放在redis嗎,代碼在哪里啊
- 03.其他微服務和認證中心的關系
- 04.改包問題
- 05.use RequestContextListener or RequestContextFilter to expose the current request
- 06./oauth/token對應代碼在哪里
- 07.驗證碼出不來
- 08./user/login
- 09.oauth無法自定義權限表達式
- 10.sleuth引發線程數過高問題
- 11.elk中使用7x版本問題
- 12.RedisCommandTimeoutException問題
- 13./oauth/token CPU過高
- 14.feign與權限標識符問題
- 15.動態路由RedisCommandInterruptedException: Command interrupted
- 26.學習資料
- 海量學習資料等你來拿
- 27.持續集成
- 01.git安裝
- 02.代碼倉庫gitlab
- 03.代碼倉庫gogs
- 04.jdk&&maven
- 05.nexus安裝
- 06.sonarqube
- 07.jenkins
- 28.Rancher部署
- 1.rancher-agent部署
- 2.rancher-server部署
- 3.ocp后端部署
- 4.演示前端部署
- 5.elk部署
- 6.docker私服搭建
- 7.rancher-server私服
- 8.rancher-agent docker私服
- 29.K8S部署OCP
- 01.準備OCP的構建環境和部署環境
- 02.部署順序
- 03.在K8S上部署eureka-server
- 04.在K8S上部署mysql
- 05.在K8S上部署redis
- 06.在K8S上部署auth-server
- 07.在K8S上部署user-center
- 08.在K8S上部署api-gateway
- 09.在K8S上部署back-center
- 30.Spring Cloud Alibaba
- 01.統一的依賴管理
- 02.nacos-server
- 03.生產可用的Nacos集群
- 04.nacos配置中心
- 05.common.yaml
- 06.user-center
- 07.auth-server
- 08.api-gateway
- 09.log-center
- 10.file-center
- 11.back-center
- 12.sentinel-dashboard
- 12.01.sentinel流控規則
- 12.02.sentinel熔斷降級規則
- 12.03.sentinel熱點規則
- 12.04.sentinel系統規則
- 12.05.sentinel規則持久化
- 12.06.sentinel總結
- 13.sentinel整合openfeign
- 14.sentinel整合網關
- 1.sentinel整合zuul
- 2.sentinel整合scg
- 15.Dubbo與Nacos共存
- 31.Java源碼剖析
- 01.基礎數據類型和String
- 02.Arrays工具類
- 03.ArrayList源碼分析
- 32.面試專題匯總
- 01.JVM專題匯總
- 02.多線程專題匯總
- 03.Spring專題匯總
- 04.springboot專題匯總
- 05.springcloud面試匯總
- 文檔問題跟蹤處理