Spring Cloud 2-Hystrix DashBoard儀表盤(五)
阿新 • • 發佈:2019-01-01
max gist nac baseline clust metrics prev web spl
Spring Cloud Hystrix DashBoard
儀表盤
儀表盤
監控頁面
監控頁面
- 1.監控系統配置
- pom.xml
- application.yml
- Application.java
- 2.被監控服務配置
- pom.xml
- application.yml
- 3.集群監控配置
- pom.xml
- application.xml
- Application.java
Hystrix DashBoard 監控儀表盤用來監測請求訪問量
1.監控系統配置
pom.xml
<!-- dashboard 客戶端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
application.yml
spring:
application:
name: hystrix-dashboard
server:
port: 8010
Application.java
@EnableHystrixDashboard
@SpringBootApplication
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
@EnableHystrixDashboard
開啟儀表盤功能
訪問: http://localhost:8010/hystrix
儀表盤
2.被監控服務配置
pom.xml
<!-- 系統健康監控工具 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
每個需要被監控的項目都要加,且是使用熔斷機制的項目
application.yml
spring:
application:
name: hystrix-client
server:
port: 8091
feign:
hystrix:
enabled: true
management:
endpoints:
web:
exposure:
include: "*" # 暴露endpoints節點 2.x版本需要手動開啟
management.endpoints
管理端點, 2.x版本需要手動開啟
監控頁面輸入: http://localhost:8091/actuator/hystrix.stream
儀表盤
訪問被監聽的服務可以看到
監控頁面
或者被監控的項目
采用如下配置
@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;
}
監控頁面輸入: http://localhost:8091/hystrix.stream 進行監控
3.集群監控配置
創建spring-boot項目並添加依賴
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
application.xml
spring:
application:
name: turbine-client
server:
port: 8020
turbine:
app-config: hystrix-client
aggregator:
cluster-config: default
cluster-name-expression: new String("default")
combine-host-port: true
app-config
被監控集群的服務名稱
Application.java
@EnableTurbine
@SpringBootApplication
public class TurbineClientApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineClientApplication.class, args);
}
}
監控頁面輸入: http://localhost:8020/turbine.stream
監控頁面
Spring Cloud 2-Hystrix DashBoard儀表盤(五)