6.springcloud_hytrix-dashboard監(jiān)控(Finchley.SR2).md

這是一個從零開始的springcloud的系列教程,如果你從中間開始看,可能會看不明白.請進(jìn)入我的系列教程開始從頭開始學(xué)習(xí).spring-cloud教程

Hytrix-Dashboard監(jiān)控

在微服務(wù)架構(gòu)中為例保證程序的可用性,防止程序出錯導(dǎo)致網(wǎng)絡(luò)阻塞,出現(xiàn)了斷路器模型。斷路器的狀況反應(yīng)了一個程序的可用性和健壯性,它是一個重要指標(biāo)。Hystrix Dashboard是作為斷路器狀態(tài)的一個組件,提供了數(shù)據(jù)監(jiān)控和友好的圖形化界面。


沿用上節(jié)課創(chuàng)建eureka-client-feign工程,修改eureka-client-feign工程.

pom.xml

<?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">
    <parent>
        <artifactId>spring-cloud-learn</artifactId>
        <groupId>com.jack</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>eureka-client-feign</artifactId>


    <dependencies>
        <!--
        一定要寫稱spring-cloud-starter-netflix-eureka-client
        如果寫錯成spring-cloud-netflix-eureka-client,將無法注冊
        -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <!--引入feign-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--引入hytrix-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        
        <!--引入hytrix dashboard-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>

        <!--
        spring-boot-starter-actuator
        springboot的Actuator提供了運(yùn)行狀態(tài)監(jiān)控的功能,可以通過REST、遠(yuǎn)程Shell和JMX方式來查看
        -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

    </dependencies>

</project>

修改EurekaClientFeignApplication

package com.jack.feign;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
// 啟動feign的注解
@EnableFeignClients
// 啟動dashboard
@EnableHystrixDashboard
// 啟動hystrix
@EnableHystrix
public class EurekaClientFeignApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaClientFeignApplication.class, args );
    }
}

application.yml需要加入以下配置,非常關(guān)鍵,因?yàn)閿?shù)據(jù)是通過springboot的actuator來持續(xù)返回的,我們需要讓actuator開放節(jié)點(diǎn)給我們,它默認(rèn)開放health和info來個節(jié)點(diǎn)

# springboot的Actuator提供了運(yùn)行狀態(tài)監(jiān)控的功能,可以通過REST、遠(yuǎn)程Shell和JMX方式來查看。
# 這個配置非常重要,否則會導(dǎo)致/actuator/hystrix.stream無法訪問,hystrix.stream節(jié)點(diǎn)會持續(xù)提供熔斷狀態(tài)
management:
  endpoints:
    web:
#      2.0之前默認(rèn)是/   2.0默認(rèn)是 /actuator
#      base-path: /actuator
#      顯示健康具體信息  默認(rèn)不會顯示詳細(xì)信息
#      management.endpoint.health.show-details=always
      exposure:
        # 默認(rèn)開啟health、info,可以通過/actuator/info訪問,如果要暴露所有接口,填"*"
        include: hystrix.stream
      cors:
        allowed-origins: "*"
        allowed-methods: "*"

ok,啟動服務(wù),訪問http://localhost:7773/actuator/hystrix.stream,會發(fā)現(xiàn)不斷有數(shù)據(jù)返回,不過因?yàn)闆]有訪問api,返回都是空

image.png

當(dāng)我們訪問http://localhost:7773/hello_store api (eureka-client服務(wù)沒有啟動)

此時服務(wù)就會出現(xiàn)數(shù)據(jù)

image.png

我們來打開圖形界面控制面板,http://localhost:7773/hystrix

image.png

對著中間輸入我們運(yùn)行狀態(tài)流服務(wù)節(jié)點(diǎn)http://localhost:7773/actuator/hystrix.stream

image.png

點(diǎn)擊monitor stream.觀察流.并且請求一次/hello_store服務(wù).會發(fā)現(xiàn)出現(xiàn)一次錯誤.方法為FeignService#sayStore

image.png

這樣我們就可以通過dashboard來觀察熔斷器的狀態(tài)了.

但是這個遠(yuǎn)遠(yuǎn)是不夠的,只能觀察一臺機(jī)器,并沒有什么意義.接下來我們會介紹turbine.可以收集所有服務(wù)熔斷器狀態(tài)流

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容