2021-11-30 周二
## 因子
最近在學`springclound`,然后看書的時候,學習到通過`actuator`來監控`springboot`應用的各項指標。又因`actuator`只提供一組`endpoints`(`restful`接口),查看不直觀,才有集成`springboot admin server`來通過界面查看監控。(當然還有其他的界面監控,比如很牛逼的`普羅米修斯`)
## springboot actuator介紹
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/)等。這些系統提供了非常好的儀表盤、圖標、分析和告警等功能,使得你可以通過統一的接口輕松的監控和管理你的應用。
示例:
`http://localhost:9101/actuator/health`
``` json
{
"status": "UP",
"components": {
"db": {
"status": "UP",
"details": {
"database": "SQLite",
"result": 1,
"validationQuery": "SELECT 1"
}
},
"diskSpace": {
"status": "UP",
"details": {
"total": 250790436864,
"free": 64770326528,
"threshold": 10485760
}
},
"ping": {
"status": "UP"
},
"redis": {
"status": "UP",
"details": {
"version": "5.0.8"
}
}
}
}
```
## springboot admin server介紹
Actuator功能強大,便于其他應用使用端點(只需要簡單的REST調用)。但是開發人員使用時就沒那么方便了。對于開發人員,有良好的交互界面會更方便瀏覽監控數據和管理應用。這正是Spring Boot Admin做的工作。它為actuator端點提供了良好的交互界面,并提供了額外的特性。
Spring Boot Admin不是Spring團隊提供的模塊,它是由[Codecentric](https://blog.codecentric.de/en/)公司創建的,代碼在[Github](https://github.com/codecentric/spring-boot-admin)上公開。
示例:

## springboot應用集成actuator
1. pom.xml里添加依賴
``` xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
```
2. `actuator`相關配置
``` properties
# 顯示actuator詳情
management.endpoint.health.show-details=always
# 解除瀏覽器訪問路徑,* 是所有,也可以指定為beans,health
management.endpoints.web.exposure.include=*
# 端點信息接口使用的端口,為了和主系統接口使用的端口進行分離
management.server.port=9101
management.server.servlet.context-path=/
```
## springboot應用集成springboot admin server
分為`Server`和`Client`,`Server`可以理解為注冊中心,`Client`則是將集成了`actuator`的springboot應用的注冊到`Server`上,然后通過界面監控各項指標。
### Server端
1. 添加依賴
``` xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${springboot.admin.version}</version>
</dependency>
</dependencies>
```
2. 啟動類上添加`@EnableAdminServer`注解
``` java
@EnableAdminServer
@SpringBootApplication
public class StartupApplication {
public static void main(String[] args) {
SpringApplication.run(StartupApplication.class,args);
}
}
```
3. 啟動后訪問`Server`的端口`http://127.0.0.1:9100`

### Client端
1. 添加依賴
``` xml
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${springboot.admin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
```
2. 添加配置
``` properties
# 顯示actuator詳情
management.endpoint.health.show-details=always
# 解除瀏覽器訪問路徑,* 是所有,也可以指定為beans,health
management.endpoints.web.exposure.include=*
# 端點信息接口使用的端口,為了和主系統接口使用的端口進行分離
management.server.port=9101
management.server.servlet.context-path=/
spring.application.name=card-api
# 配置spring-boot-admin服務端的地址
spring.boot.admin.client.enabled=true
spring.boot.admin.client.url=http://localhost:9100
```
3. 啟動Client端后,就能看到界面上有示例連上


## 總結
1. 為了監控`springboot`應用的各項指標,才有了`springboot actuator`項目。
2. 為了更直觀查看各項監控數據,就有了`springboot admin server`項目,其他的還有`Prometheus`等
3. `springboot admin`的`Server`和`Client`端都可以集成`spring-security`認證,提供安全性。
4. 框架的版本一定要對應,不然啟動的時候會出各種問題。spring和spring boot和spring cloud,以及spring boot admin的版本。可以通過mvn repo參考查看。(
5. 我的版本:spring clound Hoxton.SR10 + spring boot 2.2.7 RELEASE + spring boot admin 2.2.4 )
## 參考資料
1. https://www.jianshu.com/p/1749f04105fb
2. https://www.itmuch.com/spring-cloud/finchley-3/
- Redis來回摩擦
- redis的數據結構SDS和DICT
- redis的持久化和事件模型
- Java
- 從何而來之Java IO
- 發布Jar包到公共Maven倉庫
- Java本地方法調用
- 面試突擊
- Linux
- Nginx
- SpringBoot
- Springboot集成Actuator和SpringbootAdminServer監控
- SpringCloud
- Spring Cloud初識
- Spring Cloud的5大核心組件
- Spring Cloud的注冊中心
- Spring Cloud注冊中心之Eureka
- Spring Cloud注冊中心之Consul
- Spring Cloud注冊中心之Nacos
- Spring Cloud的負載均衡之Ribbon
- Spring Cloud的服務調用之Feign
- Spring Cloud的熔斷器
- Spring Cloud熔斷器之Hystrix
- Spring Cloud的熔斷器監控
- Spring Cloud的網關
- Spring Cloud的網關之Zuul
- Spring Cloud的配置中心
- Spring Cloud配置中心之Config Server
- Spring Cloud Config配置刷新
- Spring Cloud的鏈路跟蹤
- Spring Cloud的鏈路監控之Sleuth
- Spring Cloud的鏈路監控之Zipkin
- Spring Cloud集成Admin Server
- Docker
- docker日常基本使用
- docker-machine的基本使用
- Kubernetes
- kubernetes初識
- kubeadm安裝k8s集群
- minikube安裝k8s集群
- k8s的命令行管理工具
- k8s的web管理工具
- k8s的相關發行版
- k3s初識及安裝
- rancher的安裝及使用
- RaspberryPi
- 運維
- 域名證書更新
- 騰訊云主機組建內網
- IDEA插件開發
- 第一個IDEA插件hello ide開發
- 千呼萬喚始出來的IDEA筆記插件mdNote
- 大剛學算法
- 待整理
- 一些概念和知識點
- 位運算
- 數據結構
- 字符串和數組
- LC242-有效的字母異位詞
- 鏈表
- LC25-K個一組翻轉鏈表
- LC83-刪除有序單鏈表重復的元素
- 棧
- LC20-有效的括號
- 隊列
- 雙端隊列
- 優先隊列
- 樹
- 二叉樹
- 二叉樹的遍歷
- 二叉樹的遞歸序
- 二叉樹的前序遍歷(遞歸)
- 二叉樹的前序遍歷(非遞歸)
- 二叉樹的中序遍歷(遞歸)
- 二叉樹的中序遍歷(非遞歸)
- 二叉樹的后序遍歷(遞歸)
- 二叉樹的后序遍歷(非遞歸)
- 二叉樹的廣度優先遍歷(BFS)
- 平衡二叉樹
- 二叉搜索樹
- 滿二叉樹
- 完全二叉樹
- 二叉樹的打印(二維數組)
- 樹的序列化和反序列化
- 前綴樹
- 堆
- Java系統堆優先隊列
- 集合數組實現堆
- 圖
- 圖的定義
- 圖的存儲方式
- 圖的Java數據結構(鄰接表)
- 圖的表達方式及對應場景創建
- 圖的遍歷
- 圖的拓撲排序
- 圖的最小生成樹之Prim算法
- 圖的最小生成樹之Kruskal算法
- 圖的最小單元路徑之Dijkstra算法
- 位圖
- Java實現位圖
- 并查集
- Java實現并查集
- 滑動窗口
- 單調棧
- 排序
- 冒泡排序BubbleSort
- 選擇排序SelectSort
- 插入排序InsertSort
- 插入排序InsertXSort
- 歸并排序MergeSort
- 快速排序QuickSort
- 快速排序優化版QuickFastSort
- 堆排序HeapSort
- 哈希Hash
- 哈希函數
- guava中的hash函數
- hutool中的hash函數
- 哈希表實現
- Java之HashMap的實現
- Java之HashSet的實現
- 一致性哈希算法
- 經典問題
- 荷蘭國旗問題
- KMP算法
- Manacher算法
- Go