Merge pull request #111 from ceshihao/fix_panic_in_metrics

Fix panic in metrics
v4
Vinllen Chen 5 years ago committed by GitHub
commit 868449ac7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/redis-shake/metric/metric.go

@ -3,6 +3,7 @@ package metric
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"math"
"strconv" "strconv"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -42,7 +43,7 @@ func (p *Percent) Get(returnString bool) interface{} {
if returnString { if returnString {
return "null" return "null"
} else { } else {
return int64(^uint64(0) >> 1) // int64_max return math.MaxFloat64
} }
} else { } else {
dividend := atomic.LoadUint64(&p.Dividend) dividend := atomic.LoadUint64(&p.Dividend)
@ -225,7 +226,10 @@ func (m *Metric) GetAvgDelay() interface{} {
} }
func (m *Metric) GetAvgDelayFloat64() float64 { func (m *Metric) GetAvgDelayFloat64() float64 {
return float64(m.AvgDelay.Get(false).(int64)) if avgDelay, ok := m.AvgDelay.Get(false).(float64); ok {
return avgDelay
}
return math.MaxFloat64
} }
func (m *Metric) AddNetworkFlow(dbSyncerID int, val uint64) { func (m *Metric) AddNetworkFlow(dbSyncerID int, val uint64) {

Loading…
Cancel
Save