网站大全软件下载,网站建设利益分析,旅游营销网站开发,wordpress jet插件1. Hystrix Dashboard (断路器#xff1a;hystrix 仪表盘)
Hystrix一个很重要的功能是#xff0c;可以通过HystrixCommand收集相关数据指标. Hystrix Dashboard可以很高效的现实每个断路器的健康状况。
1#xff09;. 在Ribbon服务g和Feign服务的Maven工程的pom.xml中都加…1. Hystrix Dashboard (断路器hystrix 仪表盘)
Hystrix一个很重要的功能是可以通过HystrixCommand收集相关数据指标. Hystrix Dashboard可以很高效的现实每个断路器的健康状况。
1. 在Ribbon服务g和Feign服务的Maven工程的pom.xml中都加入依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-hystrix-dashboard/artifactId/dependency
spring-boot-starter-actuator用于手机metric 支持hystrix.stream。spring-cloud-starter-hystrix-dashboard支持dashboard的UI
2在Spring Boot启动类上用EnableHystrixDashboard注解和EnableCircuitBreaker注解。需要特别注意的是我们之前的Feign服务由于内置断路器支持 所以没有EnableCircuitBreaker注解但要使用Dashboard则必须加如果不加Dashboard无法接收到来自Feign内部断路器的监控数据会报“Unable to connect to Command Metric Stream”错误 SpringBootApplicationEnableDiscoveryClientEnableFeignClientsEnableCircuitBreakerEnableHystrixDashboardpublic class ServiceFeignApplication {public static void main(String[] args) {SpringApplication.run(ServiceFeignApplication.class, args);}}
3然后就可以访问/hystrix这个URL将dashboard指向定义在Hystrix客户端应用中的/hystrix.stream 在dashboard中输入服务的URL点击 monitor后进入监控界面访问我们之前创建的Ribbon服务localhost:8901/, 或者Feign服务localhost:8902/可以看到监控UI动态变化 2. 利用Turbine在一个Dashboard上监控多个流
以上例子只能监控一个要同时监控多个流怎么办 答案是 可以单独做一个Turbine服务专门监控所有断路器状态从而掌握整个系统中所有微服务的状态。下面我们就来创建一个Turbine服务来监控我们之前做的Feign服务和Ribbon服务
1. 创建一个maven工程 在pox.xml添加以下依赖 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-turbine/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-netflix-turbine/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-hystrix-dashboard/artifactId/dependency
整个个pox.xml文件如下
?xml version1.0 encodingUTF-8?project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcm.chry/groupIdartifactIdspring.helloworld.turbine.service/artifactIdversion0.0.1-SNAPSHOT/versionnamespring.helloworld.turbine.service/namedescriptionTurbine service demo/descriptionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion1.5.3.RELEASE/versionrelativePath/ !-- lookup parent from repository --/parentpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingjava.version1.8/java.version/propertiesdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-eureka/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-turbine/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-netflix-turbine/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-hystrix-dashboard/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependenciesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversionDalston.RC1/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/buildrepositoriesrepositoryidspring-milestones/idnameSpring Milestones/nameurlhttps://repo.spring.io/milestone/urlsnapshotsenabledfalse/enabled/snapshots/repository/repositories/project
2. 创建Turbine Dashboard启动类:
用EnableHystrixDashboard和EnableTurbine修饰主类 分别用于支持Hystrix Dashboard和Turbine package spring.helloworld.turbine.service;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;import org.springframework.cloud.netflix.turbine.EnableTurbine;SpringBootApplicationEnableHystrixDashboardEnableTurbinepublic class DashboardApplication {public static void main(String[] args) {SpringApplication.run(DashboardApplication.class, args);}}
3). 在application.yml中配置turbine参数 eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/server:port: 8903spring:application:name: hystrix-dashboard-turbineturbine:appConfig: service-feign, service-ribbonaggregator:clusterConfig: defaultclusterNameExpression: new String(default)
turbine.appConfig定义了要监控的服务这里是我们在前面章节创建的service-feign和sercice-ribbon; aggregator.clusterConfig定义了聚合方式 此处为default.
turbine.appConfig 配置Eureka中的serviceId列表表明监控哪些服务
turbine.aggregator.clusterConfig 指定聚合哪些集群多个使用”,”分割默认为default。可使用http://.../turbine.stream?cluster{clusterConfig之一}访问
turbine.clusterNameExpression 指定集群名称可以是三种类型的值 - 默认表达式为appName此时turbine.aggregator.clusterConfig需要配置想要监控的应用名称 - 当为default时turbine.aggregator.clusterConfig可以不写因为默认就是default - 当为metadata[‘cluster’]时假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC则需要配置同时turbine.aggregator.clusterConfig: ABC
4. 依次启动eureka服务 2个Helloworld服务 Feign服务ribbon服务和刚创建turbine服务。从eureka服务中我们可以看到 5通过Turbine服务访问HystrixDashborad http:localhost:8903/hystrix 监控流的URL填http://localhost:8903/turbine.stream, 点击monitor stream, 进入监控页面 随便刷新下feign和ribbon服务http://localhost:8902/hello和http://localhost:8901 可以看到监控页面的变化。如下图 两个服务的监控都会显示在dashboard上