用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

㐅韵味十足的    -  云代码空间

——

SpringCloud分布式微服务云架构 | 第十一篇: 断路器监控(Hystrix Dashboa

2019-12-23|373阅||

摘要:在第四篇文章断路器讲述了如何使用断路器,并简单的介绍了下Hystrix Dashboard组件,这篇文章更加详细的介绍Hystrix Dashboard。 一、Hystrix Dashboard简介 在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。

在第四篇文章断路器讲述了如何使用断路器,并简单的介绍了下Hystrix Dashboard组件,这篇文章更加详细的介绍Hystrix Dashboard。


一、Hystrix Dashboard简介
在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。了解springcloud架构可以加求求:三五三六二四七二五九,Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。


二、准备工作
本文的的来源于第一篇文章的栗子,在它的基础上进行改造。


三、开始改造service-hi
在pom的工程文件引入相应的依赖:
<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <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>
        
    </dependencies>


其中,这三个依赖是必须的,缺一不可。


在程序的入口ServiceHiApplication类,加上@EnableHystrix注解开启断路器,这个是必须的,并且需要在程序中声明断路点HystrixCommand;加上@EnableHystrixDashboard注解,开启HystrixDashboard
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@RestController
@EnableHystrix
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ServiceHiApplication {

    /**
     * 访问地址 http://localhost:8762/actuator/hystrix.stream
     * @param args
     */

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

    @Value("${server.port}")
    String port;

    @RequestMapping("/hi")
    @HystrixCommand(fallbackMethod = "hiError")
    public String home(@RequestParam(value = "name", defaultValue = "forezp") String name) {
        return "hi " + name + " ,i am from port:" + port;
    }

    public String hiError(String name) {
        return "hi,"+name+",sorry,error!";
    }

}


运行程序: 依次开启eureka-server 和service-hi.

四、Hystrix Dashboard图形展示
打开http://localhost:8762/actuator/hystrix.stream,可以看到一些具体的数据:

在这里插入图片描述打开localhost:8762/hystrix 可以看见以下界面:
在这里插入图片描述
在界面依次输入:http://localhost:8762/actuator/hystrix.stream 、2000 、miya
;点确定。


在另一个窗口输入: http://localhost:8762/hi?name=forezp


重新刷新hystrix.stream网页,你会看到良好的图形化界面:


在这里插入图片描述
顶 0踩 0收藏
文章评论
    发表评论

    个人资料

    • 昵称: 㐅韵味十足的
    • 等级: 中级程序员
    • 积分: 455
    • 代码: 0 个
    • 文章: 12 篇
    • 随想: 0 条
    • 访问: 5 次
    • 关注

    人气代码

      最新提问

        站长推荐