SpringCloud Hystrix-Dashboard儀表盤(pán)的實(shí)現(xiàn)
Hystrix Dashboard,它主要用來(lái)實(shí)時(shí)監(jiān)控Hystrix的各項(xiàng)指標(biāo)信息。通過(guò)Hystrix Dashboard反饋的實(shí)時(shí)信息,可以幫助我們快速發(fā)現(xiàn)系統(tǒng)中存在的問(wèn)題。下面通過(guò)一個(gè)例子來(lái)學(xué)習(xí)。
一、新建一個(gè)Spring Cloud 項(xiàng)目,命名為hystrix-dashboard
1.1在pom.xml引入相關(guān)的依賴(lài)
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
1.2在spring boot 的啟動(dòng)類(lèi)上面引入注解@EnableHystrixDashboard,啟用Hystrix Dashboard功能。
package org.hope.hystrix.dashboard; import org.springframework.boot.SpringApplication; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @EnableHystrixDashboard @SpringCloudApplication public class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); } }
1.3修改配置文件application.properties
spring.application.name=hystrix-dashboard server.port=2001
1.4啟動(dòng)應(yīng)用,然后再瀏覽器中輸入http://localhost:2001/hystrix可以看到如下界面
通過(guò)Hystrix Dashboard主頁(yè)面的文字介紹,我們可以知道,Hystrix Dashboard共支持三種不同的監(jiān)控方式
☞默認(rèn)的集群監(jiān)控:通過(guò)URL:http://turbine-hostname:port/turbine.stream開(kāi)啟,實(shí)現(xiàn)對(duì)默認(rèn)集群的監(jiān)控。
☞指定的集群監(jiān)控:通過(guò)URL:http://turbine-hostname:port/turbine.stream?cluster=[clusterName]開(kāi)啟,實(shí)現(xiàn)對(duì)clusterName集群的監(jiān)控。
☞單體應(yīng)用的監(jiān)控:通過(guò)URL:http://hystrix-app:port/hystrix.stream開(kāi)啟,實(shí)現(xiàn)對(duì)具體某個(gè)服務(wù)實(shí)例的監(jiān)控。
☞Delay:控制服務(wù)器上輪詢監(jiān)控信息的延遲時(shí)間,默認(rèn)為2000毫秒,可以通過(guò)配置該屬性來(lái)降低客戶端的網(wǎng)絡(luò)和CPU消耗。
☞Title:該參數(shù)可以展示合適的標(biāo)題。
二、要有一個(gè)eureka-server用來(lái)提供eureka的服務(wù)注冊(cè)中心,在碼云上有,可以作為參考。此處不再粘代碼。
三、要有一個(gè)eureka-service來(lái)提供服務(wù),工程名為hello-service,項(xiàng)目地址同上。
四、新建一個(gè)服務(wù)被監(jiān)控的工程,工程名為ribbon-customer。
4.1pom.xml引入相關(guān)依賴(lài)
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency>
4.2在啟動(dòng)類(lèi)上添加@EnableCircuitBreaker 開(kāi)啟斷路器功能
package com.didispace; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; @EnableCircuitBreaker //開(kāi)啟斷路器功能 @EnableDiscoveryClient @SpringBootApplication public class ConsumerApplication { @Bean @LoadBalanced RestTemplate restTemplate() { return new RestTemplate(); } public static void main(String[] args) { SpringApplication.run(ConsumerApplication.class, args); } }
4.3 RestController
package com.didispace.web; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController public class ConsumerController { @Autowired HelloService helloService; @RequestMapping(value = "/ribbon-consumer", method = RequestMethod.GET) public String helloConsumer() { return helloService.hello(); } }
4.4 application.properties配置文件
spring.application.name=ribbon-consumer server.port=9000 eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000
通過(guò)上面的步驟,已經(jīng)基本完成了準(zhǔn)備工作,下面我們進(jìn)行測(cè)試。
1.啟動(dòng)eureka-server
2.啟動(dòng)hello-service
3.啟動(dòng)ribbon-customer
4.啟動(dòng)hystrix-dashboard
5.在瀏覽器輸入http://localhost:2001/hystrix
6.在瀏覽器的新窗口輸入http://localhost:9000/ribbon-consumer
7.在Hystrix-Dashboard的主界面上輸入: http://localhost:9000/hystrix.stream然后點(diǎn)擊 Monitor Stream按鈕
在監(jiān)控的界面有兩個(gè)重要的圖形信息:一個(gè)實(shí)心圓和一條曲線。
- 實(shí)心圓:1、通過(guò)顏色的變化代表了實(shí)例的健康程度,健康程度從綠色、黃色、橙色、紅色遞減。2、通過(guò)大小表示請(qǐng)求流量發(fā)生變化,流量越大該實(shí)心圓就越大。所以可以在大量的實(shí)例中快速發(fā)現(xiàn)故障實(shí)例和高壓實(shí)例。
- 曲線:用來(lái)記錄2分鐘內(nèi)流浪的相對(duì)變化,可以通過(guò)它來(lái)觀察流量的上升和下降趨勢(shì)。
注意:當(dāng)使用Hystrix Board來(lái)監(jiān)控Spring Cloud Zuul構(gòu)建的API網(wǎng)關(guān)時(shí),Thread Pool信息會(huì)一直處于Loading狀態(tài)。這是由于Zuul默認(rèn)會(huì)使用信號(hào)量來(lái)實(shí)現(xiàn)隔離,只有通過(guò)Hystrix配置把隔離機(jī)制改成為線程池的方式才能夠得以展示。
參考:
[1]《Spring Cloud微服務(wù)實(shí)戰(zhàn)》,翟永超
[2]博客,純潔的微笑,http://www.dbjr.com.cn/article/167053.htm
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- SpringCloud-Hystrix-Dashboard客戶端服務(wù)監(jiān)控的實(shí)現(xiàn)方法
- Springcloud hystrix服務(wù)熔斷和dashboard如何實(shí)現(xiàn)
- SpringCloud之熔斷監(jiān)控Hystrix Dashboard的實(shí)現(xiàn)
- springcloud 熔斷監(jiān)控Hystrix Dashboard和Turbine
- SpringCloud中的斷路器(Hystrix)和斷路器監(jiān)控(Dashboard)
- Hystrix?Dashboard斷路監(jiān)控儀表盤(pán)的實(shí)現(xiàn)詳細(xì)介紹
相關(guān)文章
模仿mybatis-plus實(shí)現(xiàn)rpc調(diào)用
這篇文章主要為大家介紹了模仿mybatis-plus實(shí)現(xiàn)rpc調(diào)用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02Java泛型extends關(guān)鍵字設(shè)置邊界的實(shí)現(xiàn)
這篇文章主要介紹了Java泛型extends關(guān)鍵字設(shè)置邊界的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09springboot整合druid及多數(shù)據(jù)源配置的demo
這篇文章主要介紹了springboot整合druid及多數(shù)據(jù)源配置的demo,本篇主要分兩部分 ①springboot整合druid的代碼配置,以及druid的監(jiān)控頁(yè)面演示;②對(duì)實(shí)際場(chǎng)景中多數(shù)據(jù)源的配置使用進(jìn)行講解,需要的朋友可以參考下2024-01-01Mybatis 中Mapper使用package方式配置報(bào)錯(cuò)的解決方案
這篇文章主要介紹了Mybatis 中Mapper使用package方式配置報(bào)錯(cuò)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07