-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
60 lines (53 loc) · 2.06 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package httpclient
import (
"github.com/fighthorse/redisAdmin/component/conf"
"github.com/mitchellh/mapstructure"
"github.com/prometheus/client_golang/prometheus"
)
var (
remoteCallErrorCount = prometheus.NewCounterVec(
prometheus.CounterOpts{Name: "remote_call_error_count", Help: "remote call error count"},
[]string{"url", "status"})
circuitBreakerCount = prometheus.NewCounterVec(
prometheus.CounterOpts{Name: "circuit_breaker_count", Help: "circuit breaker count"},
[]string{"url"})
remoteCallRequestCount = prometheus.NewCounterVec(
prometheus.CounterOpts{Name: "app_remote_call_request_totals", Help: "http remote call request count"},
[]string{"name", "url"})
remoteCallCodeErrorCount = prometheus.NewCounterVec(
prometheus.CounterOpts{Name: "app_remote_call_api_code_err", Help: "http remote call api code request err count"},
[]string{"service", "url", "code", "msg"})
httpGobreakGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{Name: "circuit_breaker_details", Help: "http circuit breaker details"},
[]string{"url"})
)
type HttpServer struct {
SelfServiceName string `yaml:"self_service_name"`
CloseBreaker bool `yaml:"close_breaker"`
BreakerCfg map[string]interface{} `yaml:"breaker_cfg"`
ChildServer map[string]interface{} `yaml:"child_server"`
}
func init() {
prometheus.MustRegister(remoteCallErrorCount)
prometheus.MustRegister(circuitBreakerCount)
prometheus.MustRegister(remoteCallRequestCount)
prometheus.MustRegister(remoteCallCodeErrorCount)
prometheus.MustRegister(httpGobreakGauge)
}
func Init(cfg conf.HttpServer) {
InitSelfService(cfg.SelfServiceName, cfg.CloseBreaker)
}
// selfName 本身服务名称
// closeBreaker 子服务熔断开启 默认开启 ,true 关闭
func InitSelfService(selfName string, closeBreaker bool) {
selfServerName = selfName
isDisableCircuitBreaker = closeBreaker
}
func InitChildService(cfg []map[string]interface{}) {
for _, v := range cfg {
item := &Server{}
if err := mapstructure.Decode(v, item); err == nil {
childServer[item.Name] = item
}
}
}