上一篇介绍了单例的服务监控,本章介绍对集群的监控。通过引入turbine,通过它来汇集监控信息,并将聚合后的信息提供给Hystrix Dashboard来集中展示和监控。
其工作架构图如下:
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>1.5.9.RELEASEversion>
<relativePath />
parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-dependenciesartifactId>
<version>Edgware.RELEASEversion>
<type>pomtype>
<scope>importscope>
dependency>
dependencies>
dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-turbineartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-actuatorartifactId>
dependency>
dependencies>
@SpringBootApplication
@EnableDiscoveryClient
@EnableTurbine
public class SpringCloudHystrixTurbineApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(SpringCloudHystrixTurbineApplication.class).web(true).run(args);
}
}
EnableDiscoveryClient声明是eureka client
EnableTurbine申明启用集群监控
server:
port: 8006
management:
port: 8007
spring:
application:
name: springcloud-hystrix-turbine
eureka:
client:
service-url:
defaultZone: http://peer1:8080/eureka/
instance:
lease-renewal-interval-in-seconds: 30
lease-expiration-duration-in-seconds: 90
turbine:
app-config: springcloud-hystrix-dashboard # 指定了需要收集监控信息的服务名
cluster-name-expression: new String('default') # 指定集群名称
combine-host-port: true # 设置为true,可以让同一主机上的服务通过主机名与端口号的组合来进行区分,
1.启动服务注册中心集群(springcloud-server-eureka)
2.启动服务提供者(springcloud-producer-rest)
3.启动服务消费者(springcloud-hystirx-dashboard)
4.启动服务集群监控者(springcloud-hystrix-turbine)
启动后的注册服务图如下
1.打开监控页面:http://localhost:8005/hystrix,如下图
2.再长框中输入集群监控地址:http://localhost:8006/turbine.stream,如下图
3.调用服务接口地址:http://localhost:8005/api/rest/home,即可实现监控,如下图
springcloud-server-eureka
springcloud-producer-rest
springcloud-hystirx-dashboard
springcloud-hystrix-turbine
springcloud实战之1 技术选型:dubbo还是springcloud
springcloud实战之2 服务注册与发现(eureka实现)
springcloud实战之3 高可用服务注册中心(eureka集群)
springcloud实战之5 服务消费者(ribbon)
springcloud实战之6 服务消费者(Feign)
springcloud实战之7 断路器(Hystrix)
springcloud实战之8 断路器-仪表盘-单例监控(Hystrix)