欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringCloud Hystrix-Dashboard儀表盤的實現(xiàn)

 更新時間:2019年08月06日 14:34:02   作者:尋找風口的豬  
這篇文章主要介紹了SpringCloud Hystrix-Dashboard儀表盤的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

Hystrix Dashboard,它主要用來實時監(jiān)控Hystrix的各項指標信息。通過Hystrix Dashboard反饋的實時信息,可以幫助我們快速發(fā)現(xiàn)系統(tǒng)中存在的問題。下面通過一個例子來學習。

一、新建一個Spring Cloud 項目,命名為hystrix-dashboard

1.1在pom.xml引入相關(guān)的依賴

<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 的啟動類上面引入注解@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啟動應用,然后再瀏覽器中輸入http://localhost:2001/hystrix可以看到如下界面

通過Hystrix Dashboard主頁面的文字介紹,我們可以知道,Hystrix Dashboard共支持三種不同的監(jiān)控方式

☞默認的集群監(jiān)控:通過URL:http://turbine-hostname:port/turbine.stream開啟,實現(xiàn)對默認集群的監(jiān)控。

☞指定的集群監(jiān)控:通過URL:http://turbine-hostname:port/turbine.stream?cluster=[clusterName]開啟,實現(xiàn)對clusterName集群的監(jiān)控。

☞單體應用的監(jiān)控:通過URL:http://hystrix-app:port/hystrix.stream開啟,實現(xiàn)對具體某個服務(wù)實例的監(jiān)控。

☞Delay:控制服務(wù)器上輪詢監(jiān)控信息的延遲時間,默認為2000毫秒,可以通過配置該屬性來降低客戶端的網(wǎng)絡(luò)和CPU消耗。

☞Title:該參數(shù)可以展示合適的標題。

二、要有一個eureka-server用來提供eureka的服務(wù)注冊中心,在碼云上有,可以作為參考。此處不再粘代碼。

三、要有一個eureka-service來提供服務(wù),工程名為hello-service,項目地址同上。

四、新建一個服務(wù)被監(jiān)控的工程,工程名為ribbon-customer。

4.1pom.xml引入相關(guān)依賴

<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在啟動類上添加@EnableCircuitBreaker 開啟斷路器功能

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 //開啟斷路器功能
@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

通過上面的步驟,已經(jīng)基本完成了準備工作,下面我們進行測試。

1.啟動eureka-server

2.啟動hello-service

3.啟動ribbon-customer

4.啟動hystrix-dashboard

5.在瀏覽器輸入http://localhost:2001/hystrix

6.在瀏覽器的新窗口輸入http://localhost:9000/ribbon-consumer

7.在Hystrix-Dashboard的主界面上輸入: http://localhost:9000/hystrix.stream然后點擊 Monitor Stream按鈕

在監(jiān)控的界面有兩個重要的圖形信息:一個實心圓和一條曲線。

  • 實心圓:1、通過顏色的變化代表了實例的健康程度,健康程度從綠色、黃色、橙色、紅色遞減。2、通過大小表示請求流量發(fā)生變化,流量越大該實心圓就越大。所以可以在大量的實例中快速發(fā)現(xiàn)故障實例和高壓實例。
  • 曲線:用來記錄2分鐘內(nèi)流浪的相對變化,可以通過它來觀察流量的上升和下降趨勢。

注意:當使用Hystrix Board來監(jiān)控Spring Cloud Zuul構(gòu)建的API網(wǎng)關(guān)時,Thread Pool信息會一直處于Loading狀態(tài)。這是由于Zuul默認會使用信號量來實現(xiàn)隔離,只有通過Hystrix配置把隔離機制改成為線程池的方式才能夠得以展示。

參考:

[1]《Spring Cloud微服務(wù)實戰(zhàn)》,翟永超

[2]博客,純潔的微笑,http://www.dbjr.com.cn/article/167053.htm

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java執(zhí)行JS腳本工具

    Java執(zhí)行JS腳本工具

    今天小編就為大家分享一篇關(guān)于Java執(zhí)行JS腳本工具,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • 深入理解Spring的事務(wù)傳播行為

    深入理解Spring的事務(wù)傳播行為

    spring特有的事務(wù)傳播行為,spring支持7種事務(wù)傳播行為,確定客戶端和被調(diào)用端的事務(wù)邊界(說得通俗一點就是多個具有事務(wù)控制的service的相互調(diào)用時所形成的復雜的事務(wù)邊界控制),這篇文章主要給大家介紹了關(guān)于Spring事務(wù)傳播行為的相關(guān)資料,需要的朋友可以參考下。
    2018-02-02
  • 模仿mybatis-plus實現(xiàn)rpc調(diào)用

    模仿mybatis-plus實現(xiàn)rpc調(diào)用

    這篇文章主要為大家介紹了模仿mybatis-plus實現(xiàn)rpc調(diào)用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-02-02
  • Java泛型extends關(guān)鍵字設(shè)置邊界的實現(xiàn)

    Java泛型extends關(guān)鍵字設(shè)置邊界的實現(xiàn)

    這篇文章主要介紹了Java泛型extends關(guān)鍵字設(shè)置邊界的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-09-09
  • java調(diào)用c程序通信示例代碼

    java調(diào)用c程序通信示例代碼

    這篇文章主要介紹了java調(diào)用c程序通信示例,大家參考使用吧
    2013-12-12
  • Java異常學習之自定義異常詳解

    Java異常學習之自定義異常詳解

    你的程序總有一天會崩潰掉,在崩潰掉的時候我們要知道它在哪,為了什么而崩潰掉,數(shù)據(jù)的保存或者丟失情況如何等問題。下面這篇文章主要給大家介紹了關(guān)于Java異常學習之自定義異常的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-06-06
  • springboot整合druid及多數(shù)據(jù)源配置的demo

    springboot整合druid及多數(shù)據(jù)源配置的demo

    這篇文章主要介紹了springboot整合druid及多數(shù)據(jù)源配置的demo,本篇主要分兩部分 ①springboot整合druid的代碼配置,以及druid的監(jiān)控頁面演示;②對實際場景中多數(shù)據(jù)源的配置使用進行講解,需要的朋友可以參考下
    2024-01-01
  • DecimalFormat多種用法詳解

    DecimalFormat多種用法詳解

    這篇文章主要為大家詳細介紹了DecimalFormat的多種用法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Mybatis 中Mapper使用package方式配置報錯的解決方案

    Mybatis 中Mapper使用package方式配置報錯的解決方案

    這篇文章主要介紹了Mybatis 中Mapper使用package方式配置報錯的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • springBoot集成flowable的流程解析

    springBoot集成flowable的流程解析

    這篇文章主要介紹了springBoot集成flowable的流程,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-02-02

最新評論