Spring cloud hystrix + dashboard 实现监控

Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。但是只使用Hystrix Dashboard的话, 你只能看到单个应用内的服务信息, 这明显不够. 我们需要一个工具能让我们汇总系统内多个服务的数据并显示到Hystrix Dashboard上, 这个工具就是Turbine.

 

Turbine

一:build.gradle 引入jar

dependencies {
    compile "org.springframework.cloud:spring-cloud-starter-hystrix",
            "org.springframework.cloud:spring-cloud-starter-hystrix-dashboard",
            "org.springframework.boot:spring-boot-starter-actuator",
            "org.springframework.cloud:spring-cloud-starter-turbine"
}

二:修改启动类 添加@EnableHystrixDashboard  @EnableTurbine 激活对Turbine的支持

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class DemoturbineApplication {

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

}

三:修改application.properties配置文件

spring.application.name=hystrix-dashboard-turbine
server.port=9111

turbine.appConfig=node1,node2
turbine.aggregator.clusterConfig= default
turbine.clusterNameExpression= new String("default")

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

四 启动项目

顺序分别为 eureka , consume , turbine 启动成功

0bb7e38fbdb8e2ebccb3f9fd6d42ccca94d.jpg

五改造原来consume项目 

修改build.gradle 文件

dependencies {
    compile "org.springframework.cloud:spring-cloud-starter-feign",
            "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client",
            "org.springframework.boot:spring-boot-devtools",
            "org.springframework.boot:spring-boot-starter-test",
            "org.springframework.cloud:spring-cloud-starter-hystrix",
            "org.springframework.cloud:spring-cloud-starter-hystrix-dashboard",
            "org.springframework.boot:spring-boot-starter-actuator"
}

六 修改配置文件

spring.application.name=node1
server.port=9221
#熔断器生效
feign.hystrix.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
spring.application.name=node2
server.port=9222
#熔断器生效
feign.hystrix.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

 

七:修改启动类

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ConsumeApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumeApplication.class, args);
    }
}

八:修改原来得Remote,HelloRemoteHystrix, Controller

@FeignClient(name= "spring-cloud-producer2" ,fallback = HelloRemoteHystrix.class)
public interface HelloRemote {
    @RequestMapping(value = "/hello")
    String hello2(@RequestParam(value = "name") String name);

    @RequestMapping(value = "/hello1")
    String hello1(@RequestParam(value = "name") String name);
}

启动项目 顺序分别为 eureka,node1,node2, turbine 

6537448ca7bc31b0c1f9e5a1b15d5b6176b.jpg

服务中心都已注册 

访问hystrix 在浏览器输入 http://localhost:9111/hystrix

e34d18ffa4ac1dc79cddb1f641185a4eb5a.jpg

接下来监控,两个节点集群使用第一个地址,可根据名字来监控具体得项目,单个项目使用第三个地址,我们使用第一个地址 

3815d0a7caf60bb01780f1b822d924e045b.jpg

返回结果

000cf855e4fc93f32c6edde315fb492bb04.jpg

转载于:https://my.oschina.net/cpy/blog/3003214

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值