我正在尝试为我的java spring启动应用程序设置hystrix仪表板 . 启动应用程序后,我在控制台中获取代理打开消息但没有任何反应 .
Proxy opening connection to: http://localhost:9083/actuator/hystrix.stream
在仪表板中,它表示正在加载......并且没有显示任何内容...请参阅底部附带的图像 .
此外,当我在浏览器中点击此URL http://localhost:9083/actuator/hystrix.stream时,没有数据显示只是恒定的空ping . 喜欢
平:
平:
平:
...
我所做的代码更改是
@RequestMapping(value = "/elasticsearch/{numberOfInstances}/{name}", method = RequestMethod.GET)
public void ingestMip4DataToES(@PathVariable("numberOfInstances") int numberOfInstances,
@PathVariable("name") String name) {
if(numberOfInstances > 1) {
List<IdentifiableType> identifiableTypes = generateMultipleInstancesOfMip4Data(numberOfInstances, name);
if(!identifiableTypes.isEmpty()) {
dumpBulkMip4DataToES(identifiableTypes);
}
} else {
IdentifiableType identifiableType = generateSingleInstanceOfMip4Data(name);
if(identifiableType != null) {
dumpMip4DataToES(identifiableType);
}
}
}
@HystrixCommand(fallbackMethod = "fallbackForMip4SingleDataGeneration")
private IdentifiableType generateSingleInstanceOfMip4Data(String name) {
String url = GENERATOR_URL + name;
ResponseEntity<IdentifiableType> response = restTemplate.getForEntity(url, IdentifiableType.class);
return response.getBody();
}
private IdentifiableType fallbackForMip4SingleDataGeneration() {
logger.info("Calling fallback method for mip4 data generation as request to service failed.");
return null;
}
包含主要类别的必需注释 .
@SpringBootApplication
//@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableHystrixDashboard
public class InsaneMip4ElasticSearchApplication {
public static void main(String[] args) {
SpringApplication.run(InsaneMip4ElasticSearchApplication.class, args);
}
}
资源文件包含以下条目
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.include=hystrix.stream
management.endpoints.jmx.exposure.include=*
management.endpoint.health.show-details=ALWAYS
management.endpoint.shutdown.enabled=true
并为pom文件下面的条目
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
Hystrix仪表板如下所示
1 回答
由于我所做的配置错误,仪表板是空的 . HystrixCommand应附加到使用RequestMapping注释的方法 . 这是因为Hystrix监控api endpoints .
所以做下面的改动让事情对我有用 .
如您所见,现在@HystrixCommand注释应用于ingestMip4DataToES()方法,因为此方法具有@RequestMapping注释 . 早先将@HystrixCommand应用于generateSingleInstanceOfMip4Data()方法是不正确的 .
现在,当我打电话给http://localhost:9083/mip4/elasticsearch/1/CUnitType时,我可以在hystrix仪表板上看到该呼叫的实时监控 .
如果使用Springboot 2(2.0.2.RELEASE)进行监控,请记住通过http://host:port/hystrix访问仪表板并在URL中应用http://host:port/actuator/hystrix.stream .