Skip to content

Commit b6e6576

Browse files
Merge pull request #17 from asifdxtreme/master
Fix failure rate bug
2 parents ae3e8c2 + 964b513 commit b6e6576

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

monitorData.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type InterfaceInfo struct {
5151
SemaphoreRejected int64 `json:"semaphoreRejected"`
5252
ThreadPoolRejected int64 `json:"threadPoolRejected"`
5353
CountTimeout int64 `json:"countTimeout"`
54-
FailureRate int64 `json:"failureRate"`
54+
FailureRate float64 `json:"failureRate"`
5555
successCount int64
5656
}
5757

@@ -82,7 +82,7 @@ func (monitorData *MonitorData) appendInterfaceInfo(name string, i interface{})
8282
switch getEventType(name) {
8383
case "attempts":
8484
interfaceInfo.Total = metric.Count()
85-
case "failures":
85+
case "errors":
8686
interfaceInfo.Failure = metric.Count()
8787
case "shortCircuits":
8888
interfaceInfo.ShortCircuited = metric.Count()
@@ -122,7 +122,12 @@ func (monitorData *MonitorData) appendInterfaceInfo(name string, i interface{})
122122
if totalErrorCount == 0 {
123123
interfaceInfo.FailureRate = 0
124124
} else {
125-
interfaceInfo.FailureRate = totalErrorCount / interfaceInfo.Total
125+
failureRate, errr := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(totalErrorCount)/float64(interfaceInfo.Total)), 64)
126+
if errr == nil {
127+
interfaceInfo.FailureRate = failureRate
128+
} else {
129+
interfaceInfo.FailureRate = 0
130+
}
126131
}
127132
}
128133
}

0 commit comments

Comments
 (0)