Spring

Command Metric Stream에 연결할 수 없습니다. Hystrix 대시보드 문제

기록만이살길 2022. 12. 8. 23:15
반응형

Command Metric Stream에 연결할 수 없습니다. Hystrix 대시보드 문제

1. 질문(문제점):

이 질문을 게시하기 전에 다음과 같은 수많은 링크를 살펴 보았습니다. Spring Cloud를 사용 하여 Hystrix 대시보드용 Command Metric Stream에 연결할 수 없음 및 Spring Cloud + Hystrix + Turbine의 Command Metric Stream에 연결할 수 없음 - MIME 유형("텍스트/일반") 그것은 "텍스트/이벤트 스트림" 등이 아니지만 여전히 작동하지 않습니다.

Spring Boot V2.2.2.RELEASE를 사용하고 있습니다.

2020-01-14 22:52:23.805  INFO 8436 --- [io-8080-exec-10] ashboardConfiguration$ProxyStreamServlet : 

Proxy opening connection to: http://localhost:8000/hystrix.stream


2020-01-14 22:52:23.806  INFO 8436 --- [nio-8080-exec-2] ashboardConfiguration$ProxyStreamServlet : 

Proxy opening connection to: http://localhost:8000/hystrix.stream


2020-01-14 22:52:24.442  WARN 8436 --- [io-8080-exec-10] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8000/hystrix.stream : 404 : HTTP/1.1 404 
2020-01-14 22:52:24.442  WARN 8436 --- [nio-8080-exec-2] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8000/hystrix.stream : 404 : HTTP/1.1 404 
2020-01-14 22:52:37.391  INFO 8436 --- [nio-8080-exec-8] ashboardConfiguration$ProxyStreamServlet : 

Proxy opening connection to: http://localhost:8080/hystrix.stream


2020-01-14 22:52:37.397  INFO 8436 --- [nio-8080-exec-9] ashboardConfiguration$ProxyStreamServlet : 

Proxy opening connection to: http://localhost:8080/hystrix.stream


2020-01-14 22:52:37.488  WARN 8436 --- [nio-8080-exec-8] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8080/hystrix.stream : 404 : HTTP/1.1 404 
2020-01-14 22:52:37.488  WARN 8436 --- [nio-8080-exec-9] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8080/hystrix.stream : 404 : HTTP/1.1 404 

여기에 이미지 설명 입력

hystrix 대시보드::

HystrixDashboardApplication.java

@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardApplication.class, args);
    }
}

bootstrap.properties

management.endpoints.web.exposure.include=hystrix.stream
management.endpoints.web.base-path=/
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka

pom.xml

<?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 https://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.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring-boot-jdbcBatchUpdate</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>hystrix-dashboard</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR1</spring-cloud.version>
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </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>

날씨 앱::

WeatherService.java

@Service
public class WeatherService {
    @Inject
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod="unknown")
    public String getWeather() {
        return restTemplate.getForEntity("http://weather-service/weather", String.class).getBody();
    }

    public String unknown() {
        System.out.println("~~~~~~~~~");
        return "unknown";
    }
}

WeatherAppApplication.java

@EnableDiscoveryClient
@EnableCircuitBreaker
@RestController
@SpringBootApplication
public class WeatherAppApplication {
    @Inject
    private WeatherService weatherService;

    public static void main(String[] args) {
        SpringApplication.run(WeatherAppApplication.class, args);
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @GetMapping(value = "/current/weather")
    public String getWeather() {
        return "The current weather is " + weatherService.getWeather();
    }
}

application.properties

server.port=8000
spring.application.name=weather-app
eureka.client.service-url.defaultZone=http://localhost:8761/eureka

날씨 서비스::

application.properties

server.port=9000
spring.application.name=weather-service
eureka.client.service-url.defaultZone=http://localhost:8761/eureka

WeatherServiceApplication.java

@RestController
@EnableDiscoveryClient
@SpringBootApplication
public class WeatherServiceApplication {

    private String[] weather = new String[] {"sunny", "cloudy", "rainy", "windy"};

    public static void main(String[] args) {
        SpringApplication.run(WeatherServiceApplication.class, args);
    }

    @GetMapping(value="/weather")
    public String getWeather() {
        int rand = ThreadLocalRandom.current().nextInt(0, 4);
        return weather[rand];
    }
}

여기에 이미지 설명 입력

소스 코드: https://github.com/javaHelper/spring-cloud-cordinating-services/tree/master/Protecting-Systems-with-Circuit-Breakers

2. 해결방안:

대시보드 프로젝트 에서 이것을 속성에 추가하십시오.

hystrix:
  dashboard:
    proxy-stream-allow-list: "*"

그리고 weather-app 에서 이것을 추가하십시오

management:
  endpoints:
    web:
      exposure:
        include: "*"

그런 다음 http://localhost:8080/hystrix를 열고 http://localhost:8000/actuator/hystrix.stream을 추가합니다.

https://github.com/adetiamarhadi/spring-cloud-hystrix-dashboard.git https://github.com/adetiamarhadi/spring-cloud-hystrix-weather-app.git

반응형