org.springframework.cloud
spring-cloud-starter-hystrix
org.springframework.cloud
spring-cloud-starter-hystrix-dashboard
org.springframework.boot
spring-boot-starter-actuator
除此之外还需要在被监控的服务中添加以下jar包,并@EnableCircuitBreaker开启断路功能
org.springframework.cloud
spring-cloud-starter-hystrix
org.springframework.boot
spring-boot-starter-actuator
启动dashboard之后,在界面中添加http://localhost:8084/hystrix.stream,其中8084是被监控服务的端口,这样就可以在dashboard中监控服务的运行情况了,下图是监控单个服务的页面情况
上图中需要解释几个参数,这几个参数的大部分可以通过下图表现出来,这里重点说的是图中展示不全或解释不完全的。
第一、median、mean、90th、99th和99.5th,这是统计数据,这些统计数据来自metrics,可以在代码中进行如下设置:private static String getStatsStringFromMetrics(HystrixCommandMetrics metrics) {
StringBuilder m = new StringBuilder();
if (metrics != null) {
HealthCounts health = metrics.getHealthCounts();
m.append("Requests: ").append(health.getTotalRequests()).append(" ");
m.append("Errors: ").append(health.getErrorCount()).append(" (").append(health.getErrorPercentage())
.append("%) ");
m.append("Mean: ").append(metrics.getTotalTimeMean()).append(" ");
m.append("50th: ").append(metrics.getExecutionTimePercentile(50)).append(" ");
m.append("75th: ").append(metrics.getExecutionTimePercentile(75)).append(" ");
m.append("90th: ").append(metrics.getExecutionTimePercentile(90)).append(" ");
m.append("99th: ").append(metrics.getExecutionTimePercentile(99)).append(" ");
}
return m.toString();
}
一个比较好的解释是The 90th percentile tells you the value for which 90% of the data points are smaller and 10% are bigger.,意思就是1065ms以下的占99%,1065ms以上的占1%,其他同样类推
org.springframework.cloud
spring-cloud-starter-turbine
org.springframework.boot
spring-boot-starter-actuator
在主类中添加以下注解
@Configuration
@EnableAutoConfiguration
@EnableTurbine
@EnableDiscoveryClient
在turbine的配置文件中添加以下数据eureka.client.serviceUrl.defaultZone=http://localhost:1001/eureka/,之后在dashboard页面中输入http://localhost:8086/turbine.stream后,便可以对集群中的提供相同服务的数据进行监控了,下边就是监控两个服务的页面,我们可以看到host的数量是2,说明是监控了两个相同的服务,通过每秒请求的数量也可以看出host的2倍是cluster