Skip to content

Commit 62a050c

Browse files
Merge pull request #20 from savitaashture/cb
Added changes to report circuitbreaker status and refactored data flushing
2 parents b6e6576 + dc17a0e commit 62a050c

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

csemonitor.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,7 @@ func NewReporter(r metrics.Registry, addr string, header http.Header, interval t
5252

5353
// Run creates a go_routine which runs continuously and capture the monitoring data
5454
func (reporter *Reporter) Run() {
55-
56-
go reporter.postData()
57-
go reporter.cleanData()
58-
59-
}
60-
61-
func (reporter *Reporter) cleanData() {
62-
ticker := time.Tick(20 * time.Second)
63-
for range ticker {
64-
hystrix.Flush()
65-
}
66-
}
67-
68-
func (reporter *Reporter) postData() {
55+
var count int
6956
ticker := time.Tick(reporter.Interval)
7057
metricsAPI := NewCseMonitorClient(reporter.Header, reporter.CseMonitorAddr, reporter.TLSConfig, "v2")
7158
IsMonitoringConnected = true
@@ -109,6 +96,14 @@ func (reporter *Reporter) postData() {
10996
}
11097
IsMonitoringConnected = true
11198
}
99+
100+
if len(monitorData.Interfaces) != 0 {
101+
count++
102+
if count == 10 {
103+
hystrix.Flush()
104+
count = 0
105+
}
106+
}
112107
}
113108
}
114109
}

monitorData.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type InterfaceInfo struct {
4747
Total int64 `json:"total"`
4848
Failure int64 `json:"failure"`
4949
ShortCircuited int64 `json:"shortCircuited"`
50-
IsCircuitBreakerOpen bool `json:"isCircuitBreakerOpen"`
50+
IsCircuitBreakerOpen bool `json:"circuitBreakerOpen"`
5151
SemaphoreRejected int64 `json:"semaphoreRejected"`
5252
ThreadPoolRejected int64 `json:"threadPoolRejected"`
5353
CountTimeout int64 `json:"countTimeout"`
@@ -90,6 +90,10 @@ func (monitorData *MonitorData) appendInterfaceInfo(name string, i interface{})
9090
interfaceInfo.successCount = metric.Count()
9191
}
9292

93+
if interfaceInfo.ShortCircuited != 0 {
94+
interfaceInfo.IsCircuitBreakerOpen = true
95+
}
96+
9397
qps := (float64(interfaceInfo.Total) * (1 - math.Exp(-5.0/60.0/1)))
9498
movingAverageFor3Precision, err := strconv.ParseFloat(fmt.Sprintf("%.3f", qps), 64)
9599
if err == nil {

0 commit comments

Comments
 (0)