SpringCloud(三):监控中心 hystrix turbine
1.介绍
Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。但是只使用Hystrix Dashboard的话, 你只能看到单个应用内的服务信息, 这明显不够. 我们需要一个工具能让我们汇总系统内多个服务的数据并显示到Hystrix Dashboard上, 这个工具就是Turbine.
在基础服务工程里面创建一个模块用来创建一个监控中心
首先在pom.xml maven引入依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
</dependencies>
接着创建一个启动程序
@SpringBootApplication
@Controller
@EnableHystrixDashboard
public class HystrixApplication {
@RequestMapping("/")
public String home() {
return “forward:/hystrix”;
}
public static void main(String[] args) {
SpringApplication.run(HystrixApplication.class, args);
}
}
这里使用了注解 @EnableHystrixDashboard启动断路器仪表盘的功能
然后在应用的配置文件application.yml中增加如下配置
server:
port: 7979
endpoints:
restart:
enabled: true
shutdown:
enabled: true
logging:
level:
ROOT: INFO
org.springframework.web: DEBUG
启动这个项目 访问 http://localhost:7979/
输入这个服务的地址 http://localhost:8091/hystrix.stream
Turbine
在复杂的分布式系统中,相同服务的节点经常需要部署上百甚至上千个,很多时候,运维人员希望能够把相同服务的节点状态以一个整体集群的形式展现出来,这样可以更好的把握整个系统的状态。 为此,Netflix提供了一个开源项目(Turbine)来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。
pom.xml 中引入配置文件
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
</dependencies>
启动程序
@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
@EnableZipkinServer
public class ZipkinServerApplication {
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder(ZipkinServerApplication.class).web(true).run(args);
}
}
这个程序与上面的监控中心的启动程序类似 只多了2个注解 一个使用了eurekaz的服务发现功能 和使用一个turbine聚合监控的功能
在配置文件中配置 application.yml
server:
port: 8989
management:
port: 8991
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
non-secure-port: ${PORT:8989}
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
turbine:
appConfig: catologapi,catologweb,catologwap
aggregator:
clusterConfig: default
clusterNameExpression: new String(“default”)
bootstrap.yml配置文件
spring:
application:
name: turbine
cloud:
config:
uri: http://localhost:8888
rabbitmq:
addresses: amqp://47.98.133.78:5672
username: guest
password: guest
启动程序启动成功访问页面
查看下配置中心