Hystrix Dashboard 配置及圖形化監控


除了隔離依賴服務的電泳以外, Hystrix還提供了准時的調用監控(Hystrix Dashboard), Hystrix會持續地記錄所有通過Hystrix發起的請求的執行信息, 並以統計報表和圖形的形式展示給用戶, 包括每秒執行多少請求多少成功,多少失敗等. Netflix通過 hystrix-metrics-event-stream項目實現了對以上指標的監控.SpringCloud 也提供了Hystrix Dashboard的整合, 對監控內容轉化成可視化界面.

配置

相關依賴

 <dependencies>

        <!-- hystrix dashboard 圖形化監控依賴 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

主啟動類 再加上 @EnableHystrixDashboard 開啟dashboard監控

相關依賴

每個被監控的服務都要有豪豬 hystrix 並且主啟動類開啟 @EnableCircuitBreaker 熔斷

        <!-- hystrix -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <!-- actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

另外!

由於springcloud 升級的坑 --- SerlvetRegistrationBean 因為 springboot 的默認路徑不是 "/hystrix.stream" 需要在被監控的項目的主啟動類中配置一下下面的servlet

    @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;
    }

說明圖

請求頻率為 服務請求頻率

百分位延遲統計為 最后一分鍾的百分位延遲統計


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM