91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

微服務熔斷限流Hystrix之Dashboard

發布時間:2020-08-09 07:13:39 來源:網絡 閱讀:680 作者:程序員果果 欄目:編程語言

簡介

Hystrix Dashboard是一款針對Hystrix進行實時監控的工具,通過Hystrix Dashboard可以直觀地看到各Hystrix Command的請求響應時間,請求成功率等數據。

快速上手

工程說明

工程名 端口 作用
eureka-server 8761 注冊中心
service-hi 8762 服務提供者
service-consumer 8763 服務消費者

核心代碼

eureka-server 工程
pom.xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
application.yml
server:
  port: 8761
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://${eureka.instance.hostname}:/${server.port}/eureka/
spring:
  application:
    name: eureka-server
啟動類
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run( EurekaServerApplication.class, args );
    }

}

service-hi 工程

pom.xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
application.yml
server:
  port: 8762

spring:
  application:
    name: service-hi
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
HelloController
@RestController
public class HelloController {

    @GetMapping("/hi")
    public String hi() {
        return "hello ~";
    }

    @GetMapping("/hey")
    public String hey() {
        return "hey ~";
    }

    @GetMapping("/oh")
    public String oh() {
        return "ah ~";
    }

    @GetMapping("/ah")
    public String ah() {
        //模擬接口1/3的概率超時
        Random rand = new Random();
        int randomNum = rand.nextInt(3) + 1;
        if (3 == randomNum) {
            try {
                Thread.sleep( 3000 );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "來了老弟~";
    }

}
啟動類
@SpringBootApplication
@EnableEurekaClient
public class ServiceHiApplication {

    public static void main(String[] args) {
        SpringApplication.run( ServiceHiApplication.class, args );
    }

}

service-consumer 工程

pom.xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-ribbon</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>
application.yml
server:
  port: 8763

  tomcat:
    uri-encoding: UTF-8
    max-threads: 1000
    max-connections: 20000

spring:
  application:
    name: service-consumer
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

management:
  endpoints:
    web:
      exposure:
        include: "*"
      cors:
        allowed-origins: "*"
        allowed-methods: "*"
HelloService
@Service
public class HelloService {

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 簡單用法
     */
    @HystrixCommand
    public String hiService() {
        return restTemplate.getForObject("http://SERVICE-HI/hi" , String.class);
    }

    /**
     * 定制超時
     */
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "30000") })
    public String heyService() {
        return restTemplate.getForObject("http://SERVICE-HI/hey" , String.class);
    }

    /**
     * 定制降級方法
     */
    @HystrixCommand(fallbackMethod = "getFallback")
    public String ahService() {
        return restTemplate.getForObject("http://SERVICE-HI/ah" , String.class);
    }

    /**
     * 定制線程池隔離策略
     */
    @HystrixCommand(fallbackMethod = "getFallback",
            threadPoolKey = "studentServiceThreadPool",
            threadPoolProperties = {
                    @HystrixProperty(name="coreSize", value="30"),
                    @HystrixProperty(name="maxQueueSize", value="50")
            }
    )
    public String ohService() {
        return restTemplate.getForObject("http://SERVICE-HI/oh" , String.class);
    }

    public String getFallback() {
        return "Oh , sorry , error !";
    }

}
HelloController
@RestController
public class HelloController {

    @Autowired
    private HelloService helloService;

    @GetMapping("/hi")
    public String hi() {
        return helloService.hiService();
    }

    @GetMapping("/hey")
    public String hey() {
        return helloService.heyService();
    }

    @GetMapping("/oh")
    public String oh() {
        return helloService.ohService();
    }

    @GetMapping("/ah")
    public String ah() {
        return helloService.ahService();
    }

}
啟動類
@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableHystrix
@EnableCircuitBreaker
public class ServiceConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run( ServiceConsumerApplication.class, args );
    }

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

}

Hystrix Dashboard 的使用

JSON格式監控信息

先訪問http://localhost:8762/hi
再打開http://localhost:8763/actuator/hystrix.stream,可以看到一些具體的數據:

微服務熔斷限流Hystrix之Dashboard

Hystrix儀表盤監控信息

單純的查看json數據,很難分析出結果,所以,要在Hystrix儀表盤中來查看這一段json,在hystrix儀表盤中輸入監控地址進行監控:
打開儀表盤地址:http://localhost:8762/hystrix

微服務熔斷限流Hystrix之Dashboard

在界面依次輸入:http://localhost:8763/actuator/hystrix.stream 、2000 、service-consumer;點確定。

微服務熔斷限流Hystrix之Dashboard

Hystrix儀表盤指標含義

微服務熔斷限流Hystrix之Dashboard

測試

編一個測試腳本curl.sh

while true;
do
curl "http://localhost:8763/hi";
curl "http://localhost:8763/hey";
curl "http://localhost:8763/oh";
curl "http://localhost:8763/ah";
done

執行測試腳本,查看Hystrix儀表盤:

微服務熔斷限流Hystrix之Dashboard

可以看出 ahService 因為模擬了1/3的概率超時,所以監控中呈現了30%左右的錯誤百分比。

源碼

https://github.com/gf-huanchupk/SpringCloudLearning/tree/master/chapter17

歡迎關注我的公眾號《程序員果果》,關注有驚喜~~
微服務熔斷限流Hystrix之Dashboard

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

平武县| 灵武市| 奎屯市| 焦作市| 临夏市| 曲阳县| 宝山区| 乌审旗| 镇远县| 黄浦区| 西充县| 金山区| 屏山县| 民丰县| 迁西县| 孝感市| 香格里拉县| 巨鹿县| 霍林郭勒市| 江津市| 甘肃省| 长春市| 额尔古纳市| 赤壁市| 偃师市| 胶州市| 朝阳市| 仙游县| 大洼县| 吉林省| 米泉市| 德昌县| 綦江县| 乌拉特后旗| 和顺县| 贵阳市| 阳泉市| 平江县| 玛多县| 瑞昌市| 利川市|