The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
sophos

基于 gobreaker 与 prometheus 实现类似 hystrix 的熔断机制

  •  1
     
  •   sophos · Jul 29, 2017 · 2206 views
    This topic created in 3220 days ago, the information mentioned may be changed or developed.

    一直想引入 hystrix 实现熔断机制,无奈 hystrix 稍微过重,且无法对接 prometheus,而我们目前的监控系统技术栈用到了 prometheus。

    于是尝试基于 gobreaker 与 prometheus 实现了类似 hystrix 的熔断机制。

    譬如我们调用 github 的 api,可以这样:

    // func Do(name string, run runFunc, fall fallbackFunc) error
    
    err := gobreak.Do("github", func() error {
    		// call github api
    	}, nil)
    

    同时,通过 prometheus 暴露出的 metrics 接口,可以实现相关指标的监控,从而画出类似 hystrix-dashboard 的监控图,并加上告警。

    链接如下: https://github.com/hnlq715/gobreak

    希望有用 :)

    5 replies    2017-08-02 11:13:04 +08:00
    TangMonk
        1
    TangMonk  
       Jul 29, 2017 via Android
    熔断机制是什么,过载保护吗
    sophos
        2
    sophos  
    OP
       Jul 29, 2017 via iPhone   ❤️ 1
    @TangMonk 针对多个外部接口如第三方 api 或 redis 等出现异常的场景,可以考虑引入熔断机制,避免因异常导致大量请求拥堵,甚至系统雪崩的问题
    cheetah
        3
    cheetah  
       Jul 29, 2017
    看来做到一定程度都是需要 Circuit Breaker 的呀
    sophos
        4
    sophos  
    OP
       Jul 30, 2017
    @cheetah 嗯,高并发系统必备 :-)
    sophos
        5
    sophos  
    OP
       Aug 2, 2017
    README 更新~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2204 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 00:38 · PVG 08:38 · LAX 17:38 · JFK 20:38
    ♥ Do have faith in what you're doing.