hystrix 仪表板不加载

Posted

技术标签:

【中文标题】hystrix 仪表板不加载【英文标题】:hystrix dashboard doesnt load 【发布时间】:2020-09-05 10:47:06 【问题描述】:

我可以看到 hystrix 仪表板:http://localhost:8081/hystrix 我也看到我的电路中断和后备方法也有效 但是我在 http://localhost:8081/actuator/hystrix.stream 上看不到我的应用程序数据 当我查看 /actuator/conditions 时,我看到 Hystrix 出现以下错误

"HystrixAutoConfiguration.HystrixServletAutoConfiguration": 
                    "notMatched": [
                        
                            "condition": "OnClassCondition",
                            "message": "@ConditionalOnClass did not find required class 'com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet'"
                        
                    ],
                    "matched": []
                

代码 pom.xml

Spring Boot parent version : 2.2.6.RELEASE
Spring Cloud version : Hoxton.SR3
<dependencies>
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
   </dependency>
   <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
   </dependency>
</dependencies>

application.properties

management.endpoints.web.exposure.include = hystrix.stream, conditions

主应用程序

@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
@EnableHystrixDashboard
@EnableHystrix
public class MovieCatalogServiceApplication 

CatalogRestController

@RestController
@RequestMapping("/catalog")
public class CatalogRestController 

    @Autowired
    MovieInfoService movieInfo;

    @Autowired
    UserRatingsService userRatingInfo;


    @RequestMapping("/userId")
    public List<Catalog> getCatalogsByUserId(@PathVariable("userId") int userId)

        UserRatings ratings = userRatingInfo.getUserRating(userId);


        return ratings.getUserRatings().stream().map(oneOfRatings -> 
            return movieInfo.getCatalog(oneOfRatings);
            ).collect(Collectors.toList());

    


用户评分服务

@Service
public class UserRatingsService 

    @Autowired
    private WebClient webClient;

    @HystrixCommand(fallbackMethod="getFallbackUserRating")
    public UserRatings getUserRating(int userId) 
        return webClient
                .get()
                .uri("http://user-rated-movies-service/ratingsdata/users/"+ userId)
                .retrieve()
                .bodyToMono(UserRatings.class)
                .block();
    
    public UserRatings getFallbackUserRating(int userId) 
        UserRatings userRatings = new UserRatings();
        userRatings.setUserRatings(Arrays.asList(
                new Rating("0", "fallback method of user rating", 0)
                ));

        return userRatings;
    

【问题讨论】:

【参考方案1】:

您的 Hixtrix 端口是 8081,因此您需要使用该 8081 端口上的端点来进行指标工作。

例如

API-GATEWAY where Hystrix is used on port: 8081
USER-SERVICE port: 9001

问题:

API-GATEWAY - http://localhost:8081/acturator/hystrix.stream
USER-SERVICE save user - http://localhost:9001/user/ 

解决方案:

API-GATEWAY - http://localhost:8081/acturator/hystrix.stream
USER-SERVICE save user - http://localhost:8081/user/ 

指标现在运行良好,Hystrix Dashboard 可以正常运行。

【讨论】:

以上是关于hystrix 仪表板不加载的主要内容,如果未能解决你的问题,请参考以下文章

Hystrix仪表板主页加载jquery失败

Hystrix 不显示仪表板

Spring Cloud Hystrix 仪表板不与 OAuth 一起使用

在 PCF 上部署 Spring Boot 的 Hystrix 仪表板不显示指标

如何在仪表板中查看 Hystrix 指标的天数以进行监控

无法在 Hystrix 仪表板上查看 Hystrix 报告