前言:

必需学会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的工程文件引入相应的依赖:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.lwc</groupId>
<artifactId>eureka-client-hystrix-dashboard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>eureka-client-hystrix-dashboard</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR2</spring-cloud.version>
</properties> <dependencies>
<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> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</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-hystrix-dashboard</artifactId>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> <repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> </project>

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

package com.lwc;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean; /**
* @author Eddie
*/
@EnableCircuitBreaker
@EnableHystrix
@EnableHystrixDashboard
@EnableEurekaClient
@SpringBootApplication
public class EurekaClientHystrixDashboardApplication { public static void main(String[] args) {
SpringApplication.run(EurekaClientHystrixDashboardApplication.class, args);
} }

运行程序: 依次开启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 如下:

@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}

六、源码下载

标签 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扩展功能 ---- 页面静态化(OB缓冲)

    一.入门三部曲 1.什么是页面静态化 百度百科介绍: 静态页面是网页的代码都在页面中,不需要执行asp,php,jsp,.net等程序生成客户端网页代码的网页,静态页面网址中一般不含"?&q ...

  2. printf重定向问题

    1.使用printf库函数时,要加入头文件<stdio.h> 2.另外在keil里面需要把:use MicroLIB 勾选上,不然程序没办法在线调试.编译的时候不会报错. 3.当然可以不用 ...

  3. Android AIDL浅析及异步使用

    AIDL:Android Interface Definition Language,即 Android 接口定义语言. AIDL 是什么 Android 系统中的进程之间不能共享内存,因此,需要提供 ...

  4. 创建 个人 pod

    创建一个自己的 pod 大致需要以下步骤 创建git repository 编辑.podspec 创建LICENSE(许可证/授权)文件 标记 tag 验证 注册CocoaPods 发布 搜索验证 1 ...

  5. iOS文本文件的编码检测

    windows上很多文本未必是用UTF8,所以在iOS上读取的时候,如何得到文件的编码是个问题.网上有很多读取中文的例子,但是那些不够通用.比如说要读取日文,韩文,阿拉伯文等等的时候,就不行了(虽然一 ...

  6. Java编程基础知识总结大全(Ⅰ)

    Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承.指针等概念,因此Java语言具有功能强大和简单易用两个特征.Java语言作为静态面向对象编程语言的代表 ...

  7. [NOI2015]软件包管理器(树链剖分,线段树)

    题目描述 Linux用户和OSX用户一定对软件包管理器不会陌生.通过软件包管理器,你可以通过一行命令安装某一个软件包,然后软件包管理器会帮助你从软件源下载软件包,同时自动解决所有的依赖(即下载安装这个 ...

  8. mysql 8 windows 版本zip方式安装步骤

    mysql 8 windows 版本zip方式安装步骤(下载地址:https://dev.mysql.com/downloads/mysql/)1,解压ZIP文件到指定目录下:如D:\mysql-8. ...

  9. 【memcached的常用操作】

    memcache是一个KEY-VALUE存储缓存数据库,常用作网站数据请求的存储; 提供多种API: 语法简单类似于redis; #设置一个键值存储 #添加一个键值存储 #获取键值 #删除键值 #清空 ...

  10. VUE 采坑之旅-- Mint-ui 按需引入报出Module build failed: Error: Couldn't find preset "es2015" relative to directory "C:\\phpStudy\\PHPTutorial\\WWW\\text\\vuep\\vue-demo"

    首先按照mint-ui的文档中按需引入的要求,先执行 npm install babel-plugin-component -D 然后,将.babelrc文件替换了,但是后来我又将其改了(采坑过程我也 ...