2021-12-19 周天
## Hystrix監控
### actuator的監控節點
在`actuator`下有用來監控`hystrix`的端點`/actuator/hystrix.stream`。
訪問:
```
http://localhost:9202/actuator/hystrix.stream
```
輸出:(注意監控時需要請求`@HystrixCommand`配置的微服務)
```
ping:
data: {"type":"HystrixCommand","name":"feignCardRand","group":"TestController","currentTime":1641272819332,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":1000,"rollingCountBadRequests":0,"rollingCountCollapsedRequests":0,"rollingCountEmit":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackEmit":0,"rollingCountFallbackFailure":0,"rollingCountFallbackMissing":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":1000,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":10,"latencyExecute_mean":0,"latencyExecute":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"latencyTotal_mean":0,"latencyTotal":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"THREAD","propertyValue_executionIsolationThreadTimeoutInMilliseconds":1000,"propertyValue_executionTimeoutInMilliseconds":1000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1,"threadPool":"TestController"}
```
### 集成hystrix dashboard
接口數據查看起來不直觀,可以運行`hystrix dashboard`通過界面來查看。
1. 先引入依賴
~~~ xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
~~~
2. 創建啟動類
~~~ java
@EnableHystrixDashboard
@SpringBootApplication(scanBasePackages = "com.github.mg0324")
public class StartupApplication {
public static void main(String[] args) {
SpringApplication.run(StartupApplication.class,args);
}
}
~~~
3. 添加首頁跳轉,支持端口直接到`hystrix`資源路徑
~~~ java
@Controller
public class HystrixIndexController {
@GetMapping("")
public String index() {
return "forward:/hystrix";
}
}
~~~
4. 添加配置端口
~~~
server:
port: 8030
hystrix:
dashboard:
# 設置允許連接的IP
proxy-stream-allow-list: "192.168.3.29"
~~~
5. 啟動服務,并訪問 `http://127.0.0.0:8030`

### 監控詳情解讀
在 Hystrix Dashboard 界面里的url處填寫要監控的hystrix數據流地址。
如:http://192.168.3.29:9202/actuator/hystrix.stream

如果連接后的界面里什么都沒有顯示,則需要手動請求后,才能展現數據。可以用 ab 命令做請求壓測,加大壓力,讓熔斷器開啟,圖中會出現紅色。

ab命令如下:
`ab -n 10000 -c 160 http://127.0.0.1:9201/test/test/feign/cardRand`

## 集成Turbine監控
Turbine是一個聚合Hystrix監控數據的工具,它可將所有相關/hystrix.stream端點的數據聚合到一個組合的/turbine.stream中,從而讓集群的監控更加方便。
1. 添加依賴。
~~~
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
~~~
2. 編寫啟動類。
~~~
@EnableTurbine
@SpringBootApplication(scanBasePackages = "com.github.mg0324")
public class StartupApplication {
public static void main(String[] args) {
SpringApplication.run(StartupApplication.class,args);
}
}
~~~
3. 添加配置。
~~~
server:
port: 8031
spring:
application:
name: card-hystrix-turbine
eureka:
client:
service-url:
defaultZone: http://192.168.3.29:8761/eureka/
instance:
prefer-ip-address: true
turbine:
# 要監控的微服務列表,多個用,分隔
appConfig: mic-card,mic-test
clusterNameExpression: "'default'"
~~~
4. 啟動服務后,得到 http://192.168.3.29:8031/turbine.stream 的聚合節點。
5. 填寫到hystrix dashboard的url中做監控。

## 參考
https://www.itmuch.com/spring-cloud/finchley-15/
- 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