前言
本次使用的版本号是springcloud(Greenwich.SR2) springboot(2.1.6.RELEASE)
hystrix dashboard
单节点监控(
一、创建监控页面
1、引入GAV依赖pom文件
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.tool.dashboard</groupId>
<artifactId>sys-tool-hystrix-dashboard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sys-tool-hystrix-dashboard</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2、application.properties
server.port=10010
spring.application.name=sys-tool-dashboard
3、启动类头配置
@SpringBootApplication
@EnableHystrixDashboard
4、启动
5、访问
http://localhost:10010/hystrix
6、效果
![](https://img.haomeiwen.com/i12616589/4754e7379fd43e2b.png)
创建监控方
1、引入gav
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
application.properties
server.port=10011
spring.application.name=company-info-test
#开启所有监控断点,也可以单独打开hystrix.stream
#management.endpoints.web.exposure.include=hystrix.stream
# health,info,env......
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
3、使组件生效,在启动类种配置生效注解
//(exclude={DataSourceAutoConfiguration.class})去除自动连接数据库的配置,原因是父文件中引入了JPA
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@EnableCircuitBreaker
4,编写controller接口以及使用hystrix做容错
接口
@RestController
@RequestMapping("info-test")
public class TestDashBoard {
@Autowired
private StoreIntegration storeIntegration;
@GetMapping("dashboard")
public Object testDashBoard() {
return storeIntegration.getStores();
}
}
hystrix容错
@Component
public class StoreIntegration {
@HystrixCommand(fallbackMethod = "defaultStores")
public Object getStores() {
return "success";
//do stuff that might fail
}
public Object defaultStores() {
return "error";
/* something useful */
}
}
5、启动测试
路径
http://localhost:10011/actuator/hystrix.stream
效果
![](https://img.haomeiwen.com/i12616589/d1f42e003348feb0.png)
看到的是ping,没有效果
然后访问接口
http://localhost:10011/info-test/dashboard
然后进入http://localhost:10011/actuator/hystrix.stream
页面
![](https://img.haomeiwen.com/i12616589/454e72b1ed8dee70.png)
6、进入监控页面(输入地址进行监控)
![](https://img.haomeiwen.com/i12616589/ad633a512c479232.png)
监控效果
![](https://img.haomeiwen.com/i12616589/d2f7213b79f19631.png)
再次访问接口,查看监控效果
访问(不断刷新)
http://localhost:10011/info-test/dashboard
监控页面
![](https://img.haomeiwen.com/i12616589/4e8431176672ece6.png)
网友评论