熔断监控Hystrix-Dashboard
1.Hystrix-Dashboard监控单个服务
1.1 pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除嵌入式tomcat插件 -->
<exclusions>
<exclusion>
<groupId> org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!--注意:这里必须要添加,否则各种依赖有问题-->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>1.2 application.yml
server:
port: 8004
spring:
application:
name: Cloud-Hystrix-Dashboard
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:5555/eureka/
register-with-eureka: true
fetch-registry: true
feign:
hystrix:
enabled: true
management:
endpoints:
web:
exposure:
include: hystrix.stream1.3 main启动方法
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class HystrixDashboardRun {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardRun.class, args);
}
}1.4 remote远程调用
1.4.1 HelloRemote
@FeignClient(fallback=HelloRemoteHystrix.class,name="producer")
public interface HelloRemote {
@RequestMapping("/hello")
public String testHello(@RequestParam(value="param") String param);
}1.4.2 HelloRemoteHystrix
@Component
public class HelloRemoteHystrix implements HelloRemote{
public String testHello(String param) {
// TODO Auto-generated method stub
return "hello "+param+", this message send failed";
}
}1.5 Controller
@RestController
public class TestHello {
@Autowired
HelloRemote helloRemote;
@RequestMapping("/testController/{param}")
public String getHello(@PathVariable("param") String param){
return helloRemote.testHello(param);
}
}1.6 调试说明
启动工程后访问 http://127.0.0.1:8004/hystrix

访问输入:http://127.0.0.1:8004/hystrix.stream
同时浏览器访问:http://127.0.0.1:8004/hystrix.stream 也可以看到数据。
监控可以查看到下面数据:

2.Turbine监控多个服务(后续需要再研究)
文章标题:熔断监控Hystrix-Dashboard
发布时间:2019-11-13, 15:58:13
最后更新:2019-11-13, 15:58:13