最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

一、新建一個(gè)Spring Cloud 項(xiàng)目,命名為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 的啟動(dòng)類上面引入注解@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啟動(dòng)應(yīng)用,然后再瀏覽器中輸入http://localhost:2001/hystrix可以看到如下界面

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

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

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

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

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

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

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

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

四、新建一個(gè)服務(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在啟動(dòng)類上添加@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)基本完成了準(zhǔn)備工作,下面我們進(jìn)行測試。

1.啟動(dòng)eureka-server

2.啟動(dòng)hello-service

3.啟動(dòng)ribbon-customer

4.啟動(dòng)hystrix-dashboard

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

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

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

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

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

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

參考:

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

[2]博客,純潔的微笑,http://m.fzitv.net/article/167053.htm

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

相關(guān)文章

最新評論

东兰县| 肥城市| 西和县| 牟定县| 尼玛县| 武安市| 万山特区| 阳泉市| 岳阳市| 翼城县| 酉阳| 万州区| 沈阳市| 潼南县| 大冶市| 孝义市| 托克托县| 贵德县| 桦川县| 四会市| 武强县| 新营市| 赞皇县| 克什克腾旗| 德保县| 澄江县| 南江县| 平定县| 秦安县| 延川县| 大厂| 辰溪县| 清涧县| 宝丰县| 东乡县| 新田县| 卓资县| 四平市| 团风县| 万源市| 个旧市|