fix counter type compute func

This commit is contained in:
Ulric Qin 2020-03-29 08:08:43 +08:00
parent 3d8d6c6886
commit bf2a4b9ef5
3 changed files with 11 additions and 5 deletions

View File

@ -16,7 +16,7 @@ sys:
mountPoint: [] mountPoint: []
mountIgnorePrefix: mountIgnorePrefix:
- /var/lib - /var/lib
ignoreMetrics: ignoreMetrics:
- cpu.core.idle - cpu.core.idle
- cpu.core.util - cpu.core.util

View File

@ -56,7 +56,7 @@ func (h *History) clean() {
defer h.Unlock() defer h.Unlock()
now := time.Now().Unix() now := time.Now().Unix()
for key, item := range h.Data { for key, item := range h.Data {
if now-item.Timestamp > 2*item.Step { if now-item.Timestamp > 10*item.Step {
delete(h.Data, key) delete(h.Data, key)
} }
} }

View File

@ -96,17 +96,23 @@ func Push(metricItems []*dataobj.MetricValue) error {
func CounterToGauge(item *dataobj.MetricValue) error { func CounterToGauge(item *dataobj.MetricValue) error {
key := item.PK() key := item.PK()
old, exists := cache.MetricHistory.Get(key) old, exists := cache.MetricHistory.Get(key)
cache.MetricHistory.Set(key, *item)
if !exists { if !exists {
cache.MetricHistory.Set(key, *item)
return fmt.Errorf("not found old item:%v", item) return fmt.Errorf("not found old item:%v", item)
} }
cache.MetricHistory.Set(key, *item)
if old.Value > item.Value { if old.Value > item.Value {
return fmt.Errorf("item:%v old value:%v greater than new value:%v", item, old.Value, item.Value) return fmt.Errorf("item:%v old value:%v greater than new value:%v", item, old.Value, item.Value)
} }
item.ValueUntyped = item.Value - old.Value
if old.Timestamp > item.Timestamp {
return fmt.Errorf("item:%v old timestamp:%v greater than new timestamp:%v", item, old.Timestamp, item.Timestamp)
}
item.ValueUntyped = (item.Value - old.Value) / float64(item.Timestamp-old.Timestamp)
item.CounterType = dataobj.GAUGE item.CounterType = dataobj.GAUGE
return nil return nil
} }