17越平,熔斷監(jiān)控hystrix Dashboard和turbine

dc54564e9258d1095bbd2e3cda58ccbf6d814de6.jpg

hystrix-dashboard是一款針對(duì)hystrix進(jìn)行實(shí)時(shí)監(jiān)控的工具基公,通過(guò)Hystrix Dashboard 我們可以在直觀地看到各Hystrix Command是請(qǐng)求響應(yīng)時(shí)間琴庵,請(qǐng)求成功率等數(shù)據(jù)伤溉。但是只使用hystrixDashboard的話辫秧,你只能看到單個(gè)應(yīng)用內(nèi)的服務(wù)信息束倍,這明顯不夠,我們需要一個(gè)工具能讓我們匯總系統(tǒng)內(nèi)部多個(gè)服務(wù)的數(shù)據(jù)并顯示到hystrix Dashboard上盟戏,這個(gè)工具就是Turbine.
hystrix Dasboard


我們?cè)谌蹟鄬?shí)例項(xiàng)目spring-cloud-consumer-hystrix的基礎(chǔ)上更改绪妹,重新命名為:spring-cloud-consumer-hystrix-dashboard。
1柿究、添加依賴

         <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-javanica</artifactId>
            <version>RELEASE</version>
        </dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    <version>1.3.0.RELEASE</version>
</dependency>
                                    
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

這三個(gè)包必須添加

2邮旷,啟動(dòng)類(lèi)

啟動(dòng)類(lèi)添加啟用Hystrix Dashboard和熔斷器

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    
}



  @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }  
}

3、測(cè)試

啟動(dòng)工程后訪問(wèn) http://localhost:9001/hystrix蝇摸,將會(huì)看到如下界面:

image

圖中會(huì)有一些提示:

Cluster via Turbine (default cluster): http://turbine-hostname:port/turbine.stream
Cluster via Turbine (custom cluster): http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
Single Hystrix App: http://hystrix-app:port/hystrix.stream

大概意思就是如果查看默認(rèn)集群使用第一個(gè)url,查看指定集群使用第二個(gè)url,單個(gè)應(yīng)用的監(jiān)控使用最后一個(gè)婶肩,我們暫時(shí)只演示單個(gè)應(yīng)用的所以在輸入框中輸入: http://localhost:9001/hystrix.stream 办陷,輸入之后點(diǎn)擊 monitor,進(jìn)入頁(yè)面律歼。

如果沒(méi)有請(qǐng)求會(huì)先顯示Loading ...民镜,訪問(wèn)http://localhost:9001/hystrix.stream 也會(huì)不斷的顯示ping。

請(qǐng)求服務(wù)http://localhost:9001/hello/neo险毁,就可以看到監(jiān)控的效果了殃恒,首先訪問(wèn)http://localhost:9001/hystrix.stream,顯示如下:

ping: 

data: {"type":...}

data: {"type":...}

說(shuō)明已經(jīng)返回了監(jiān)控的各項(xiàng)結(jié)果

到監(jiān)控頁(yè)面就會(huì)顯示如下圖:

image

其實(shí)就是http://localhost:9001/hystrix.stream返回結(jié)果的圖形化顯示辱揭,Hystrix Dashboard Wiki上詳細(xì)說(shuō)明了圖上每個(gè)指標(biāo)的含義离唐,如下圖:

image

到此單個(gè)應(yīng)用的熔斷監(jiān)控已經(jīng)完成。

Turbine

在復(fù)雜的分布式系統(tǒng)中问窃,相同服務(wù)的節(jié)點(diǎn)經(jīng)常需要部署上百甚至上千亥鬓,很多時(shí)候,運(yùn)維人員希望你能夠把相同的服務(wù)節(jié)點(diǎn)狀態(tài)以一個(gè)整體集群的形式表現(xiàn)出來(lái)域庇,這樣可以更好地把握整個(gè)系統(tǒng)的狀態(tài)嵌戈。為此,Netflix提供了一個(gè)開(kāi)源項(xiàng)目(Turbine)來(lái)提供把多個(gè)hystrix.stream 的內(nèi)容聚合成為一個(gè)數(shù)據(jù)源提供Dashboard展示

1听皿、添加依賴

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.taotao</groupId>
    <artifactId>service-turbine</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>service-turbine</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.RC2</spring-cloud.version>
    </properties>

    <dependencies>
        <!--Turbine-->
        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-turbine -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-turbine</artifactId>
                <version>1.4.4.RELEASE</version>
        </dependency>

        <!--Hystrix Dashboard-->
        <dependency>
    <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.3.0.RELEASE</version>
        </dependency>
        <dependency>
    <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-turbine</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</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-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.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>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>

</project>

2熟呛、配置文件

spring.application.name=service-turbine
server.port=8766
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka
turbine.aggregator.cluster-config=default
turbine.app-config=service-ribbon
turbine.cluster-name-expression="default"
turbine.combine-host-port=true

turbine.appConfig :配置Eureka中的serviceId列表,表明監(jiān)控哪些服務(wù)
turbine.aggregator.clusterConfig :指定聚合哪些集群尉姨,多個(gè)使用”,”分割庵朝,默認(rèn)為default∮掷鳎可使用http://.../turbine.stream?cluster={clusterConfig之一}訪問(wèn)
turbine.clusterNameExpression : 1. clusterNameExpression指定集群名稱九府,默認(rèn)表達(dá)式appName;此時(shí):turbine.aggregator.clusterConfig需要配置想要監(jiān)控的應(yīng)用名稱覆致;2. 當(dāng)clusterNameExpression: default時(shí)侄旬,turbine.aggregator.clusterConfig可以不寫(xiě),因?yàn)槟J(rèn)就是default煌妈;3. 當(dāng)clusterNameExpression: metadata[‘cluster’]時(shí)儡羔,假設(shè)想要監(jiān)控的應(yīng)用配置了eureka.instance.metadata-map.cluster: ABC,則需要配置璧诵,同時(shí)turbine.aggregator.clusterConfig: ABC
3益眉、啟動(dòng)類(lèi)

啟動(dòng)類(lèi)添加@EnableTurbine贮缕,激活對(duì)Turbine的支持

@EnableTurbine
@SpringBootApplication
public class ServiceTurbineApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceTurbineApplication.class, args);
    }



}

到此Turbine(hystrix-dashboard-turbine)配置完成

到此Turbine(hystrix-dashboard-turbine)配置完成

4畏浆、測(cè)試
在示例項(xiàng)目spring-cloud-consumer-hystrix基礎(chǔ)上修改為兩個(gè)服務(wù)的調(diào)用者spring-cloud-consumer-node1和spring-cloud-consumer-node2

spring-cloud-consumer-node1項(xiàng)目改動(dòng)如下: application.properties文件內(nèi)容

spring.application.name=node01
server.port=9001
feign.hystrix.enabled=true

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

spring-cloud-consumer-node2項(xiàng)目改動(dòng)如下: application.properties文件內(nèi)容

spring.application.name=node02
server.port=9002
feign.hystrix.enabled=true

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

HelloRemote類(lèi)修改:

@FeignClient(name= "spring-cloud-producer2", fallback = HelloRemoteHystrix.class)
public interface HelloRemote {

    @RequestMapping(value = "/hello")
    public String hello2(@RequestParam(value = "name") String name);

}

對(duì)應(yīng)的HelloRemoteHystrixConsumerController類(lèi)跟隨修改身害,具體查看代碼

修改完畢后赞枕,依次啟動(dòng)spring-cloud-eureka澈缺、spring-cloud-consumer-node1坪创、spring-cloud-consumer-node1、hystrix-dashboard-turbine(Turbine)

打開(kāi)eureka后臺(tái)可以看到注冊(cè)了三個(gè)服務(wù):

[圖片上傳失敗...(image-e42495-1548076675425)]

訪問(wèn) http://localhost:8001/turbine.stream

返回:

: ping
data: {"reportingHostsLast10Seconds":1,"name":"meta","type":"meta","timestamp":1494921985839}

并且會(huì)不斷刷新以獲取實(shí)時(shí)的監(jiān)控?cái)?shù)據(jù)姐赡,說(shuō)明和單個(gè)的監(jiān)控類(lèi)似莱预,返回監(jiān)控項(xiàng)目的信息。進(jìn)行圖形化監(jiān)控查看项滑,輸入:http://localhost:8001/hystrix依沮,返回酷酷的小熊界面,輸入: http://localhost:8001/turbine.stream枪狂,然后點(diǎn)擊 Monitor Stream ,可以看到出現(xiàn)了倆個(gè)監(jiān)控列表

image
6c224f4a20a4462398480fff9322720e0df3d7a9.jpg
1254583-20180128220443600-243457834.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末危喉,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子州疾,更是在濱河造成了極大的恐慌辜限,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,122評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件严蓖,死亡現(xiàn)場(chǎng)離奇詭異薄嫡,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)颗胡,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,070評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)毫深,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人毒姨,你說(shuō)我怎么就攤上這事哑蔫。” “怎么了弧呐?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,491評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵鸳址,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我泉懦,道長(zhǎng)稿黍,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,636評(píng)論 1 293
  • 正文 為了忘掉前任崩哩,我火速辦了婚禮巡球,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘邓嘹。我一直安慰自己酣栈,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,676評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布汹押。 她就那樣靜靜地躺著矿筝,像睡著了一般。 火紅的嫁衣襯著肌膚如雪棚贾。 梳的紋絲不亂的頭發(fā)上窖维,一...
    開(kāi)封第一講書(shū)人閱讀 51,541評(píng)論 1 305
  • 那天榆综,我揣著相機(jī)與錄音,去河邊找鬼铸史。 笑死鼻疮,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的琳轿。 我是一名探鬼主播判沟,決...
    沈念sama閱讀 40,292評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼崭篡!你這毒婦竟也來(lái)了挪哄?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,211評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤琉闪,失蹤者是張志新(化名)和其女友劉穎中燥,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體塘偎,經(jīng)...
    沈念sama閱讀 45,655評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡疗涉,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,846評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了吟秩。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片咱扣。...
    茶點(diǎn)故事閱讀 39,965評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖涵防,靈堂內(nèi)的尸體忽然破棺而出闹伪,到底是詐尸還是另有隱情,我是刑警寧澤壮池,帶...
    沈念sama閱讀 35,684評(píng)論 5 347
  • 正文 年R本政府宣布偏瓤,位于F島的核電站,受9級(jí)特大地震影響椰憋,放射性物質(zhì)發(fā)生泄漏厅克。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,295評(píng)論 3 329
  • 文/蒙蒙 一橙依、第九天 我趴在偏房一處隱蔽的房頂上張望证舟。 院中可真熱鬧,春花似錦窗骑、人聲如沸女责。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,894評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)抵知。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間刷喜,已是汗流浹背残制。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,012評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留吱肌,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,126評(píng)論 3 370
  • 正文 我出身青樓仰禽,卻偏偏與公主長(zhǎng)得像氮墨,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子吐葵,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,914評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 請(qǐng)先閱讀之前的內(nèi)容: Spring Cloud 學(xué)習(xí)筆記 - No.1 服務(wù)注冊(cè)發(fā)現(xiàn) Spring Cloud 學(xué)...
    專職跑龍?zhí)?/span>閱讀 1,807評(píng)論 0 6
  • 早上的時(shí)候规揪,被拖起來(lái)去吃城北的餛燉。 那是一家從我七歲開(kāi)始就存在的餛燉店温峭,他們只做餛燉猛铅,卻成為了這十年來(lái)小城里做的...
    羥羊閱讀 160評(píng)論 0 1
  • 黑暗里,你伸出雙手凤藏, 望向天空的明月 月光里奸忽,你低下頭, 看見(jiàn)自己的影子 影子里揖庄,你陷入沉思栗菜, 孤獨(dú)和渴望在流動(dòng) ...
    黃彩霞1121閱讀 182評(píng)論 0 1
  • 大家好,我叫花貝蹄梢。 我遇到了我現(xiàn)在的主人疙筹,紅紅。是她給我取名叫做花貝的禁炒,為什么要叫做這個(gè)名字呢而咆?我記得她當(dāng)時(shí)正在刷...
    橘子屋閱讀 933評(píng)論 5 13