この記事では、SpringCloud戦闘(8)である - サーキットブレーカーのモニタリング(Hystrixダッシュボード)、最初の記事に集中する、ポータルをクリックしてください。
SpringCloud戦闘(7) - サービスリンクトレース(春クラウドスルース)
我々は以前zipkin導入します。本論文では、Hystrixダッシュボードを監視回路ブレーカを説明しています。
A、Hystrixダッシュボードプロフィール
主情報Hystrixの指標のリアルタイム監視のために使用されるHystrixダッシュボード、。Hystrixダッシュボードフィードバックによるリアルタイムの情報は、私たちはすぐにシステムの問題を特定するのに役立ちます。
第二に、仕事の準備
サービス-HI上記に基づいて変革プロジェクト。
第三に、Hystrix-ダッシュボードを統合
3.1 Mavenの依存性
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
追加のダッシュボードには、既存のプロジェクトに依存しています。
3.2起動クラス(EurekaClientApplication)
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableHystrix
@EnableCircuitBreaker
@EnableHystrixDashboard
@RestController
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run( EurekaClientApplication.class, args);
}
@Value("${server.port}")
String port;
@RequestMapping("/hi")
public String hi(@RequestParam(value = "name", defaultValue = "forezp") String name) {
return "hi " + name + " ,i am from port:" + port;
}
@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}
既存のプロジェクトでの追加は、ノート、オープンダッシュボードコンポーネントを@EnableHystrixDashboard、次に起動アクセス HTTP:// localhostを:8762 / hystrix、次のように示します:
シングルノードHystrixモニタリング訪問 のhttp:// hystrixアプリ:ポート / hystrix.stream
クラスタの監視を訪問し ます。http://タービンホスト名:ポート / turbine.stream
私たちは、私たちが訪れるようにのみ、単一のノードを構築するためにここにいる HTTP:// hystrixアプリ:ポート/ hystrix.stream、示すように:
此时停止service-lucy实例,然后我们访问 http://localhost:8762/hiLucy?name=zzx,如图所示:
此时我们成功监测到service-lucy服务异常。
四、Turbine集群监控
单节点Dashboard意义不大,因为我们的模块可能会有很多很多,此时我们需要Dashboard搭建集群监控。
重新新建spirngboot工程,取名为:service-turbine。
4.1 maven依赖
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>com.oal.microservice</groupId>
<artifactId>openAiLab</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.oal.microservice</groupId>
<artifactId>service-turbine</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>service-turbine</name>
<description>turbine</description>
<dependencies>
<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.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</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-netflix-turbine</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4.2 启动类
@SpringBootApplication
@EnableEurekaClient
@EnableHystrix
@EnableHystrixDashboard
@EnableCircuitBreaker
@EnableTurbine
public class ServiceTurbineApplication {
public static void main(String[] args) {
SpringApplication.run( ServiceTurbineApplication.class, args);
}
}
4.3 配置文件(application.yml)
eureka:
client:
serviceUrl:
defaultZone: http://eureka-serve-01:8761/eureka/
server:
port: 8766
spring:
application:
name: service-turbine
management:
endpoints:
web:
exposure:
include: "*"
cors:
allowed-origins: "*"
allowed-methods: "*"
turbine:
app-config: service-feign,service-hi
aggregator:
clusterConfig: default
clusterNameExpression: new String("default")
combine-host: true
instanceUrlSuffix:
default: hystrix.stream
service-turbine端口配置为8766,我们通过turbine.app-config指定需要整合的Dashboard所在服务名,整合多个Dashboard服务用逗号分隔。
4.4 改造service-fegin工程
service-feign改造同service-hi,引入Dashboard依赖并增加@EnableHystrixDashboard注解就可以了。
4.5 演示Dashboard整合
启动上述三个服务(service-feign、service-hi、service-turbine),然后访问 http://localhost:8766/hystrix(service-turbine),如图所示:
我们通过访问集群的方式连接它(http://turbine-hostname:port/turbine.stream ),访问 http://localhost:8766/turbine.stream,如图所示:
此时我们成功整合service-feign和service-hi的两块Dashboard。
断路器监控与集群监控搭建完成。