Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master 639d0d5c0 -> ed57bd124


Fix TM2 PerSec stats to only compute new results


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/94ab4bd6
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/94ab4bd6
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/94ab4bd6

Branch: refs/heads/master
Commit: 94ab4bd6ef98e81bb20234275b1b160e35d53435
Parents: 639d0d5
Author: Robert Butts <robert.o.bu...@gmail.com>
Authored: Wed Feb 1 09:37:35 2017 -0700
Committer: Dave Neuman <neu...@apache.org>
Committed: Wed Feb 1 12:31:13 2017 -0700

----------------------------------------------------------------------
 .../traffic_monitor/deliveryservice/stat.go     | 22 +++++++++++---------
 1 file changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/94ab4bd6/traffic_monitor_golang/traffic_monitor/deliveryservice/stat.go
----------------------------------------------------------------------
diff --git a/traffic_monitor_golang/traffic_monitor/deliveryservice/stat.go 
b/traffic_monitor_golang/traffic_monitor/deliveryservice/stat.go
index 9efd2c9..f6d83f9 100644
--- a/traffic_monitor_golang/traffic_monitor/deliveryservice/stat.go
+++ b/traffic_monitor_golang/traffic_monitor/deliveryservice/stat.go
@@ -133,8 +133,8 @@ func newLastDSStat() dsdata.LastDSStat {
 const BytesPerKilobit = 125
 
 func addLastStat(lastData dsdata.LastStatData, newStat int64, newStatTime 
time.Time) (dsdata.LastStatData, error) {
-       if newStat == lastData.Stat {
-               return lastData, nil
+       if lastData.Time == newStatTime {
+               return lastData, nil // TODO fix callers to not pass the same 
stat twice
        }
 
        if newStat < lastData.Stat {
@@ -204,7 +204,7 @@ func addLastDSStatTotals(lastStat dsdata.LastDSStat, 
cachesReporting map[enum.Ca
 }
 
 // addDSPerSecStats calculates and adds the per-second delivery service stats 
to both the Stats and LastStats structures, and returns the augmented 
structures.
-func addDSPerSecStats(dsName enum.DeliveryServiceName, stat dsdata.Stat, 
lastStats dsdata.LastStats, dsStats dsdata.Stats, dsStatsTime time.Time, 
serverCachegroups map[enum.CacheName]enum.CacheGroupName, serverTypes 
map[enum.CacheName]enum.CacheType, mc to.TrafficMonitorConfigMap, events 
health.ThreadsafeEvents) (dsdata.Stats, dsdata.LastStats) {
+func addDSPerSecStats(dsName enum.DeliveryServiceName, stat dsdata.Stat, 
lastStats dsdata.LastStats, dsStats dsdata.Stats, serverCachegroups 
map[enum.CacheName]enum.CacheGroupName, serverTypes 
map[enum.CacheName]enum.CacheType, mc to.TrafficMonitorConfigMap, events 
health.ThreadsafeEvents, precomputed map[enum.CacheName]cache.PrecomputedData) 
(dsdata.Stats, dsdata.LastStats) {
        err := error(nil)
        lastStat, lastStatExists := lastStats.DeliveryServices[dsName]
        if !lastStatExists {
@@ -212,10 +212,12 @@ func addDSPerSecStats(dsName enum.DeliveryServiceName, 
stat dsdata.Stat, lastSta
        }
 
        for cacheName, cacheStats := range stat.Caches {
-               lastStat.Caches[cacheName], err = 
addLastStats(lastStat.Caches[cacheName], cacheStats, dsStatsTime)
-               if err != nil {
-                       log.Warnf("%v adding kbps for cache %v: %v", dsName, 
cacheName, err)
-                       continue
+               if _, ok := precomputed[cacheName]; ok {
+                       lastStat.Caches[cacheName], err = 
addLastStats(lastStat.Caches[cacheName], cacheStats, 
precomputed[cacheName].Time)
+                       if err != nil {
+                               log.Warnf("%v adding kbps for cache %v: %v", 
dsName, cacheName, err)
+                               continue
+                       }
                }
                cacheStats.Kbps.Value = lastStat.Caches[cacheName].Bytes.PerSec 
/ BytesPerKilobit
                stat.Caches[cacheName] = cacheStats
@@ -275,9 +277,9 @@ func addCachePerSecStats(cacheName enum.CacheName, 
precomputed cache.Precomputed
 // we set the (new - old) / lastChangedTime as the KBPS, and update the 
recorded LastChangedTime and LastChangedValue
 //
 // TODO handle ATS byte rolling (when the `out_bytes` overflows back to 0)
-func addPerSecStats(precomputed map[enum.CacheName]cache.PrecomputedData, 
dsStats dsdata.Stats, lastStats dsdata.LastStats, dsStatsTime time.Time, 
serverCachegroups map[enum.CacheName]enum.CacheGroupName, serverTypes 
map[enum.CacheName]enum.CacheType, mc to.TrafficMonitorConfigMap, events 
health.ThreadsafeEvents) (dsdata.Stats, dsdata.LastStats) {
+func addPerSecStats(precomputed map[enum.CacheName]cache.PrecomputedData, 
dsStats dsdata.Stats, lastStats dsdata.LastStats, serverCachegroups 
map[enum.CacheName]enum.CacheGroupName, serverTypes 
map[enum.CacheName]enum.CacheType, mc to.TrafficMonitorConfigMap, events 
health.ThreadsafeEvents) (dsdata.Stats, dsdata.LastStats) {
        for dsName, stat := range dsStats.DeliveryService {
-               dsStats, lastStats = addDSPerSecStats(dsName, stat, lastStats, 
dsStats, dsStatsTime, serverCachegroups, serverTypes, mc, events)
+               dsStats, lastStats = addDSPerSecStats(dsName, stat, lastStats, 
dsStats, serverCachegroups, serverTypes, mc, events, precomputed)
        }
        for cacheName, precomputedData := range precomputed {
                lastStats = addCachePerSecStats(cacheName, precomputedData, 
lastStats)
@@ -338,7 +340,7 @@ func CreateStats(precomputed 
map[enum.CacheName]cache.PrecomputedData, toData to
                }
        }
 
-       perSecStats, lastStats := addPerSecStats(precomputed, dsStats, 
lastStats, now, toData.ServerCachegroups, toData.ServerTypes, mc, events)
+       perSecStats, lastStats := addPerSecStats(precomputed, dsStats, 
lastStats, toData.ServerCachegroups, toData.ServerTypes, mc, events)
        log.Infof("CreateStats took %v\n", time.Since(start))
        perSecStats.Time = time.Now()
        return perSecStats, lastStats, nil

Reply via email to