SpringCloud怎么實現(xiàn)斷路器監(jiān)控

這篇文章主要介紹“SpringCloud怎么實現(xiàn)斷路器監(jiān)控”,在日常操作中,相信很多人在SpringCloud怎么實現(xiàn)斷路器監(jiān)控問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”SpringCloud怎么實現(xiàn)斷路器監(jiān)控”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

河南網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,河南網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為河南成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的河南做網(wǎng)站的公司定做!

一、Hystrix Dashboard簡介

在微服務(wù)架構(gòu)中為例保證程序的可用性,防止程序出錯導(dǎo)致網(wǎng)絡(luò)阻塞,出現(xiàn)了斷路器模型。斷路器的狀況反應(yīng)了一個程序的

可用性和健壯性,它是一個重要指標。Hystrix Dashboard是作

為斷路器狀態(tài)的一個組件,提供了數(shù)據(jù)監(jiān)控和友好的圖形化界面。

二、準備工作

本文的的來源于第一篇文章的栗子,在它的基礎(chǔ)上進行改造。

三、開始改造service-hi

在pom的工程文件引入相應(yīng)的依賴:

<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        
    </dependencies>

其中,這三個依賴是必須的,缺一不可。

在程序的入口ServiceHiApplication類,加上@EnableHystrix注解開啟斷路器,這個是必須的,并且需要在程序中聲明斷路點

HystrixCommand;加上@EnableHystrixDashboard注解,開啟HystrixDashboard

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@RestController
@EnableHystrix
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ServiceHiApplication {
    /**
     * 訪問地址 http://localhost:8762/actuator/hystrix.stream
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run( ServiceHiApplication.class, args );
    }
    @Value("${server.port}")
    String port;
    @RequestMapping("/hi")
    @HystrixCommand(fallbackMethod = "hiError")
    public String home(@RequestParam(value = "name", defaultValue = "forezp") String name) {
        return "hi " + name + " ,i am from port:" + port;
    }
    public String hiError(String name) {
        return "hi,"+name+",sorry,error!";
    }
}

運行程序: 依次開啟eureka-server 和service-hi.

四、Hystrix Dashboard圖形展示
打開http://localhost:8762/actuator/hystrix.stream,可以看到一些具體的數(shù)據(jù):

SpringCloud怎么實現(xiàn)斷路器監(jiān)控

打開localhost:8762/hystrix 可以看見以下界面:

SpringCloud怎么實現(xiàn)斷路器監(jiān)控

在界面依次輸入:http://localhost:8762/actuator/hystrix.stream 、2000 、miya;點確定。

在另一個窗口輸入: http://localhost:8762/hi?name=forezp

重新刷新hystrix.stream網(wǎng)頁,你會看到良好的圖形化界面:

SpringCloud怎么實現(xiàn)斷路器監(jiān)控

到此,關(guān)于“SpringCloud怎么實現(xiàn)斷路器監(jiān)控”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

網(wǎng)站名稱:SpringCloud怎么實現(xiàn)斷路器監(jiān)控
當前路徑:http://muchs.cn/article14/ihsgde.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、標簽優(yōu)化、建站公司微信小程序、網(wǎng)站改版、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)