zoukankan      html  css  js  c++  java
  • 业余草 SpringCloud教程 | 第十一篇: 断路器监控(Hystrix Dashboard)(Finchley版本)

    在我的第四篇文章断路器讲述了如何使用断路器,并简单的介绍了下Hystrix Dashboard组件,这篇文章更加详细的介绍Hystrix Dashboard。

    一、Hystrix Dashboard简介

    在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。

    二、准备工作

    本文的的工程栗子,来源于第一篇文章的栗子,在它的基础上进行改造。

    三、开始改造service-hi

    在pom的工程文件引入相应的依赖:

     1 <dependencies>
     2         <dependency>
     3             <groupId>org.springframework.cloud</groupId>
     4             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
     5         </dependency>
     6         <dependency>
     7             <groupId>org.springframework.boot</groupId>
     8             <artifactId>spring-boot-starter-web</artifactId>
     9         </dependency>
    10         <dependency>
    11             <groupId>org.springframework.boot</groupId>
    12             <artifactId>spring-boot-starter-actuator</artifactId>
    13         </dependency>
    14         <dependency>
    15             <groupId>org.springframework.cloud</groupId>
    16             <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    17         </dependency>
    18         <dependency>
    19             <groupId>org.springframework.cloud</groupId>
    20             <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
    21         </dependency>
    22  
    23     </dependencies>

    其中,这三个依赖是必须的,缺一不可。

    在程序的入口ServiceHiApplication类,加上@EnableHystrix注解开启断路器,这个是必须的,并且需要在程序中声明断路点HystrixCommand;加上@EnableHystrixDashboard注解,开启HystrixDashboard

     1 @SpringBootApplication
     2 @EnableEurekaClient
     3 @EnableDiscoveryClient
     4 @RestController
     5 @EnableHystrix
     6 @EnableHystrixDashboard
     7 @EnableCircuitBreaker
     8 public class ServiceHiApplication {
     9  
    10     /**
    11      * 访问地址 http://localhost:8762/actuator/hystrix.stream
    12      * @param args
    13      */
    14  
    15     public static void main(String[] args) {
    16         SpringApplication.run( ServiceHiApplication.class, args );
    17     }
    18  
    19     @Value("${server.port}")
    20     String port;
    21  
    22     @RequestMapping("/hi")
    23     @HystrixCommand(fallbackMethod = "hiError")
    24     public String home(@RequestParam(value = "name", defaultValue = "forezp") String name) {
    25         return "hi " + name + " ,i am from port:" + port;
    26     }
    27  
    28     public String hiError(String name) {
    29         return "hi,"+name+",sorry,error!";
    30     }
    31  
    32 }

    运行程序: 依次开启eureka-server 和service-hi.

    四、Hystrix Dashboard图形展示

    打开http://localhost:8762/actuator/hystrix.stream,可以看到一些具体的数据:

    这里写图片描述

    打开locahost:8762/hystrix 可以看见以下界面:

    这里写图片描述

    在界面依次输入:http://localhost:8762/actuator/hystrix.stream 、2000 、miya 
    ;点确定。

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

    重新刷新hystrix.stream网页,你会看到良好的图形化界面:

    这里写图片描述

    源码下载: 
    https://github.com/forezp/SpringCloudLearning/tree/master/sc-f-chapter12

    五、参考资料

    hystrix-dashboard

    业余草微信公众号

    感谢您的关注!可加QQ1群:135430763,QQ2群:454796847,QQ3群:187424846。QQ群进群密码:xttblog,想加微信群的朋友,可以微信搜索:xmtxtt,备注:“xttblog”,添加助理微信拉你进群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作可添加助理微信进行沟通!

  • 相关阅读:
    TF-IDF理解及其Java实现
    Java两种方式简单实现:爬取网页并且保存
    PHP网站环境搭配: Apache Http+PHP+Mysql
    String与InputStream相互转换
    Eclipse工程文件夹 红叹号
    查准与召回(Precision & Recall)
    IR的评价指标-MAP,NDCG和MRR
    Dubbo简介2
    SpringCloud 集锦
    dubbox 的各种管理和监管[转]
  • 原文地址:https://www.cnblogs.com/panda2/p/9419542.html
Copyright © 2011-2022 走看看