前言:

必需学会SpringBoot基础知识

简介:

spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理、服务发现、断路器、路由、微代理、事件总线、全局锁、决策竞选、分布式会话等等。它运行环境简单,可以在开发人员的电脑上跑。

工具:

JDK8

apache-maven-3.5.2

IntelliJ IDEA 2017.3 x64

在之前第四篇已经介绍过 Hystrix , 本篇会详细少少介绍该组件

一、Hystrix Dashboard简介

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

二、准备工作

本文的的工程章节,来源于第一篇的文章,在它的基础上进行仿照新建项目。

三、新建项目

(1) eureka-server-hystrix-dashboard

不贴代码, 完全一样!!!!

(2) eureka-client-hystrix-dashboard

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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5.  
  6. <groupId>com.lwc</groupId>
  7. <artifactId>eureka-client-hystrix-dashboard</artifactId>
  8. <version>0.0.1-SNAPSHOT</version>
  9. <packaging>jar</packaging>
  10.  
  11. <name>eureka-client-hystrix-dashboard</name>
  12. <description>Demo project for Spring Boot</description>
  13.  
  14. <parent>
  15. <groupId>org.springframework.boot</groupId>
  16. <artifactId>spring-boot-starter-parent</artifactId>
  17. <version>1.5.10.RELEASE</version>
  18. <relativePath/> <!-- lookup parent from repository -->
  19. </parent>
  20.  
  21. <properties>
  22. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  23. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  24. <java.version>1.8</java.version>
  25. <spring-cloud.version>Edgware.SR2</spring-cloud.version>
  26. </properties>
  27.  
  28. <dependencies>
  29. <dependency>
  30. <groupId>org.springframework.boot</groupId>
  31. <artifactId>spring-boot-starter-web</artifactId>
  32. </dependency>
  33. <dependency>
  34. <groupId>org.springframework.cloud</groupId>
  35. <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  36. </dependency>
  37.  
  38. <dependency>
  39. <groupId>org.springframework.boot</groupId>
  40. <artifactId>spring-boot-starter-test</artifactId>
  41. <scope>test</scope>
  42. </dependency>
  43.  
  44. <dependency>
  45. <groupId>org.projectlombok</groupId>
  46. <artifactId>lombok</artifactId>
  47. </dependency>
  48.  
  49. <dependency>
  50. <groupId>org.springframework.cloud</groupId>
  51. <artifactId>spring-cloud-starter-hystrix</artifactId>
  52. </dependency>
  53. <dependency>
  54. <groupId>org.springframework.boot</groupId>
  55. <artifactId>spring-boot-starter-actuator</artifactId>
  56. </dependency>
  57. <dependency>
  58. <groupId>org.springframework.cloud</groupId>
  59. <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
  60. </dependency>
  61. </dependencies>
  62.  
  63. <dependencyManagement>
  64. <dependencies>
  65. <dependency>
  66. <groupId>org.springframework.cloud</groupId>
  67. <artifactId>spring-cloud-dependencies</artifactId>
  68. <version>${spring-cloud.version}</version>
  69. <type>pom</type>
  70. <scope>import</scope>
  71. </dependency>
  72. </dependencies>
  73. </dependencyManagement>
  74.  
  75. <build>
  76. <plugins>
  77. <plugin>
  78. <groupId>org.springframework.boot</groupId>
  79. <artifactId>spring-boot-maven-plugin</artifactId>
  80. </plugin>
  81. </plugins>
  82. </build>
  83.  
  84. <repositories>
  85. <repository>
  86. <id>spring-milestones</id>
  87. <name>Spring Milestones</name>
  88. <url>https://repo.spring.io/milestone</url>
  89. <snapshots>
  90. <enabled>false</enabled>
  91. </snapshots>
  92. </repository>
  93. </repositories>
  94.  
  95. </project>

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

  1. package com.lwc;
  2.  
  3. import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
  4. import org.springframework.boot.SpringApplication;
  5. import org.springframework.boot.autoconfigure.SpringBootApplication;
  6. import org.springframework.boot.web.servlet.ServletRegistrationBean;
  7. import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
  8. import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
  9. import org.springframework.cloud.netflix.hystrix.EnableHystrix;
  10. import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
  11. import org.springframework.context.annotation.Bean;
  12.  
  13. /**
  14. * @author Eddie
  15. */
  16. @EnableCircuitBreaker
  17. @EnableHystrix
  18. @EnableHystrixDashboard
  19. @EnableEurekaClient
  20. @SpringBootApplication
  21. public class EurekaClientHystrixDashboardApplication {
  22.  
  23. public static void main(String[] args) {
  24. SpringApplication.run(EurekaClientHystrixDashboardApplication.class, args);
  25. }
  26.  
  27. }

运行程序: 依次开启eureka-server-hystrix-dashboard 和 eureka-client-hystrix-dashboard

四、Hystrix Dashboard图形展示

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

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

在界面依次输入:locahost:8762/hystrix.stream 、2000 、eddie;点确定。

在另一个窗口输入: http://localhost:8762/eureka/client?name=eddie

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

五、踩坑汇总

(1) WebUI 提示: Unable to connect to Command Metric Stream.

排除方法有几种:  1, 没有加三个依赖  2, 没有加注解  3,springboot版本 (我做这个demo时候是第3种)

如果是第3种: 可以尝试解决 1, 仿照本篇的pom.xml里面的做 2, 添加servlet 如下:

  1. @Bean
  2. public ServletRegistrationBean getServlet(){
  3. HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
  4. ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
  5. registrationBean.setLoadOnStartup(1);
  6. registrationBean.addUrlMappings("/hystrix.stream");
  7. registrationBean.setName("HystrixMetricsStreamServlet");
  8. return registrationBean;
  9. }

六、源码下载

标签 11-1

https://github.com/eddie-code/SpringCloudDemo

【SpringCloud】第十一篇: 断路器监控(Hystrix Dashboard)的更多相关文章

  1. 史上最简单的SpringCloud教程 | 第十二篇: 断路器监控(Hystrix Dashboard)(Finchley版本)

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springcloud/2018/08/30/sc-f12-dash/ 本文出自方志朋的博客 在我的第四篇文章断路 ...

  2. 史上最简单的SpringCloud教程 | 第十二篇: 断路器监控(Hystrix Dashboard)

    转载请标明出处: 首发于:https://www.fangzhipeng.com/springcloud/2017/07/12/sc12-hystix-dashbd/ 本文出自方志朋的博客 最新Fin ...

  3. SpringCloud教程 | 第十二篇: 断路器监控(Hystrix Dashboard)

    版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 ,博主地址:http://blog.csdn.net/forezp. http://blog.csdn.net/forezp/art ...

  4. Spring Cloud(五)断路器监控(Hystrix Dashboard)

    在上两篇文章中讲了,服务提供者 Eureka + 服务消费者 Feign,服务提供者 Eureka + 服务消费者(rest + Ribbon),本篇文章结合,上两篇文章中代码进行修改加入 断路器监控 ...

  5. 服务容错保护断路器Hystrix之三:断路器监控(Hystrix Dashboard)-单体监控

    turbine:英 [ˈtɜ:baɪn] 美 [ˈtɜ:rbaɪn] n.汽轮机;涡轮机;透平机 一.Hystrix Dashboard简介 在微服务架构中为了保证程序的可用性,防止程序出错导致网络阻 ...

  6. 【SpringCloud】第十二篇: 断路器监控(Hystrix Turbine)

    前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...

  7. SpringCloud 教程 (五) 断路器监控(Hystrix Dashboard)

    一.Hystrix Dashboard简介 在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型.断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标.Hystrix ...

  8. 服务容错保护断路器Hystrix之四:断路器监控(Hystrix Dashboard)-turbine集群监控

    turbine 英[ˈtɜ:baɪn] n. 汽轮机; 涡轮机; 透平机; OK,上文我们看了一个监控单体应用的例子,在实际应用中,我们要监控的应用往往是一个集群,这个时候我们就得采取Turbine集 ...

  9. Spring Cloud项目之断路器集群监控Hystrix Dashboard

    微服务(Microservices Architecture)是一种架构风格,一个大型复杂软件应用由一个或多个微服务组成.系统中的各个微服务可被独立部署,各个微服务之间是松耦合的.每个微服务仅关注于完 ...

随机推荐

  1. PHP扩展功能----发送邮件

    1.下载PHPMailer源码 github下载 (测试使用的是5.2.2 版本) 2.注册并登录网易邮箱(其他邮箱均可)[用于配置用户名和三方登录授权码,以及发送人邮箱地址]  (1)开启POP3协 ...

  2. ubuntu中phpstorm和sublime快速启动

    ubuntu gnome桌面 + dash to dock扩展 下载安装包手动安装phpstorm会遇到无法固定到dash上的情况(运行软件时在dash右击未出现Add to Favoriates) ...

  3. Exp6 信息收集与漏洞扫描 20164314

    一.实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 二.实践内容 1.各种搜索技巧的应用 2.DNS IP注册信息的查询 3.基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具体服务 ...

  4. OpenID Connect Core 1.0(五)使用授权码流验证(下)

    3.1.2.6 验证错误响应(Authentication Error Response) 验证错误响应是一个OAuth 2.0授权错误响应消息,是RP发送授权请求的消息,由OP授权终结点的响应返回. ...

  5. Notes 20180312 : String第四讲_String上的操作

    作为一个基本的工具类,同时又是使用频率很高的类,Java为其提供了丰富的方法支持.Java中的String类中包含了50多个方法.最令人惊讶的是绝大多数方法都很有用,下面我们根据功能来分类介绍一下: ...

  6. iOS:通信录(完成)(18-01-18更)

    1.读取通信录 1).9.0以前:AddressBook 2).9.0以后:Contacts 2.调用通信录UI(不弄) 1).9.0以前:AddressBookUI 2).9.0以后:Contact ...

  7. ios开发遇到的问题

    运行后界面空白,Xcode跳转到APPDelegate.swift文件提示如下 第一种可能原因: 做输出口后在代码中重新命名了输出口 解决方法: 右键控件关闭输出口的连接,变回+号,将它重新连到代码的 ...

  8. c#的传输组件dotnetty

    牛皮不多了,绩效吹起.... 最近一直看大家写的东西,了解的内容不少,我的牛皮也差不多吹完了.... 最后在说说最近测试的dotnetty.去年弄下来试了,不行,最近又弄下来了看看,可以了.哇哈哈哈哈 ...

  9. Mysql存中文字符出错:Incorrect string value: '\xC2\xE9\xD7\xED\解决方法

    1.数据库连接设置编码格式为UTF-8 jdbc:mysql://localhost:3306/jbpm_test?useUnicode=true&characterEncoding=UTF- ...

  10. jQuery实现全选、全不选以及反选操作

    在写购物车案例时实现全选操作使用的是js的getAttribute()setAttribute()方法获取checked属性的值是undefined实现完成之后全选操作,如果在全选中的情况下改变其中一 ...