15、Feign整合断路器监控Hystrix Dashboard
ribbon可以整合整合断路器监控hystrix dashboard,feign也不能少, 本篇讲解一下feign如何整合断路器监控hystrix dashboard。本篇主要整合sc-eureka-client-consumer-feign-hystrix项目和sc-hystrix-dashboard项目。
1、 新建项目sc-feign-hystrix-dashboard,对应的pom.xml文件如下
<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>spring-cloud</groupid> <artifactid>sc-feign-hystrix-dashboard</artifactid> <version>0.0.1-snapshot</version> <packaging>jar</packaging> <name>sc-feign-hystrix-dashboard</name> <url>http://maven.apache.org</url> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>2.0.4.release</version> </parent> <dependencymanagement> <dependencies> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-dependencies</artifactid> <version>finchley.release</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencymanagement> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <!-- 说明是一个 eureka client --> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-netflix-eureka-client</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <!-- <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-feign</artifactid> <version>1.4.5.release</version> </dependency> --> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-openfeign</artifactid> </dependency> <!-- <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-hystrix-dashboard</artifactid> <version>1.4.5.release</version> </dependency> --> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-netflix-hystrix-dashboard</artifactid> </dependency> <!-- <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-hystrix</artifactid> <version>1.4.5.release</version> </dependency> --> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-netflix-hystrix</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-actuator</artifactid> </dependency> </dependencies> </project>
说明:可以看出这个pom.xml文件是sc-eureka-client-consumer-feign-hystrix项目和sc-hystrix-dashboard项目的并集。
2、 新建spring root 启动类feigndashboardapplication.java
package sc.consumer; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; import org.springframework.cloud.netflix.eureka.enableeurekaclient; import org.springframework.cloud.netflix.hystrix.dashboard.enablehystrixdashboard; import org.springframework.cloud.openfeign.enablefeignclients; @springbootapplication @enableeurekaclient @enablefeignclients @enablehystrixdashboard public class feigndashboardapplication { public static void main(string[] args) { springapplication.run(feigndashboardapplication.class, args); } }
这个启动类的注解是sc-eureka-client-consumer-feign-hystrix项目和sc-hystrix-dashboard项目的并集
3、 其他项目文件说明如下,具体见源码
4、 启动注册中心sc-eureka-server和服务提供者sc-eureka-client-provider,并确保启动成功
5、 启动sc-feign-hystrix-dashboard项目,并验证是否启动成功
方式一:访问注册中心查看sc-feign-hystrix-dashboard项目配置的服务名是否注册成功
方式二:访问仪表盘dashboard对的地址http://127.0.0.1:5800/hystrix
6、 使用hystrix dashboard查看服务情况
在下图标注处输入
然后点击monitor stream按钮
7、 使用postman访问任意服务接口,以访问获取用户信息接口为例
http://127.0.0.1:5800/feign/user/getuser/3
尽量多访问几次,然后查看仪表盘bashboard监控后台,发现之前一直处于loading的界面发生了变化,如下图,图中单元具体含义可以访问网站
https://github.com/netflix-skunkworks/hystrix-dashboard/wiki
访问也出现大量数据,这些数据就是对服务的监控数据。
上一篇: python两个_多个字典合并相加
下一篇: 降低页面相似度,增加收录