Add TM2 cache capacity to GUI

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

Branch: refs/heads/master
Commit: edb7e63387a1536756e041358a4e272c6e3b626d
Parents: fb42fb6
Author: Robert Butts <robert.o.bu...@gmail.com>
Authored: Wed Jan 18 08:45:20 2017 -0700
Committer: David Neuman <david.neuma...@gmail.com>
Committed: Mon Jan 23 12:10:59 2017 -0700

----------------------------------------------------------------------
 .../traffic_monitor/manager/datarequest.go      | 21 +++++++++++++++-----
 .../traffic_monitor/static/index.html           |  5 ++++-
 2 files changed, 20 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/edb7e633/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
----------------------------------------------------------------------
diff --git 
a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go 
b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
index e4a35ed..c4385f3 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
@@ -77,6 +77,7 @@ type CacheStatus struct {
        // HealthSpanMilliseconds is the length of time between completing the 
most recent two health queries. This can be used as a rough gauge of the 
end-to-end query processing time.
        HealthSpanMilliseconds *int64   `json:"health_span_ms,omitempty"`
        BandwidthKbps          *float64 `json:"bandwidth_kbps,omitempty"`
+       BandwidthCapacityKbps  *float64 
`json:"bandwidth_capacity_kbps,omitempty"`
        ConnectionCount        *int64   `json:"connection_count,omitempty"`
 }
 
@@ -656,8 +657,8 @@ func srvAPIVersion(staticAppData StaticAppData) []byte {
 func srvAPITrafficOpsURI(opsConfig OpsConfigThreadsafe) []byte {
        return []byte(opsConfig.Get().Url)
 }
-func srvAPICacheStates(toData todata.TODataThreadsafe, statInfoHistory 
threadsafe.ResultInfoHistory, statResultHistory threadsafe.ResultStatHistory, 
healthHistory threadsafe.ResultHistory, lastHealthDurations 
DurationMapThreadsafe, localStates peer.CRStatesThreadsafe, lastStats 
threadsafe.LastStats, localCacheStatus threadsafe.CacheAvailableStatus) 
([]byte, error) {
-       return json.Marshal(createCacheStatuses(toData.Get().ServerTypes, 
statInfoHistory.Get(), statResultHistory.Get(), healthHistory.Get(), 
lastHealthDurations.Get(), localStates.Get().Caches, lastStats.Get(), 
localCacheStatus))
+func srvAPICacheStates(toData todata.TODataThreadsafe, statInfoHistory 
threadsafe.ResultInfoHistory, statResultHistory threadsafe.ResultStatHistory, 
healthHistory threadsafe.ResultHistory, lastHealthDurations 
DurationMapThreadsafe, localStates peer.CRStatesThreadsafe, lastStats 
threadsafe.LastStats, localCacheStatus threadsafe.CacheAvailableStatus, 
statMaxKbpses threadsafe.CacheKbpses) ([]byte, error) {
+       return json.Marshal(createCacheStatuses(toData.Get().ServerTypes, 
statInfoHistory.Get(), statResultHistory.Get(), healthHistory.Get(), 
lastHealthDurations.Get(), localStates.Get().Caches, lastStats.Get(), 
localCacheStatus, statMaxKbpses))
 }
 
 func srvAPIBandwidthKbps(toData todata.TODataThreadsafe, lastStats 
threadsafe.LastStats) []byte {
@@ -779,7 +780,7 @@ func MakeDispatchMap(
                        return srvAPITrafficOpsURI(opsConfig)
                }, ContentTypeJSON)),
                "/api/cache-statuses": wrap(WrapErr(errorCount, func() ([]byte, 
error) {
-                       return srvAPICacheStates(toData, statInfoHistory, 
statResultHistory, healthHistory, lastHealthDurations, localStates, lastStats, 
localCacheStatus)
+                       return srvAPICacheStates(toData, statInfoHistory, 
statResultHistory, healthHistory, lastHealthDurations, localStates, lastStats, 
localCacheStatus, statMaxKbpses)
                }, ContentTypeJSON)),
                "/api/bandwidth-kbps": wrap(WrapBytes(func() []byte {
                        return srvAPIBandwidthKbps(toData, lastStats)
@@ -897,10 +898,12 @@ func createCacheStatuses(
        cacheStates map[enum.CacheName]peer.IsAvailable,
        lastStats ds.LastStats,
        localCacheStatusThreadsafe threadsafe.CacheAvailableStatus,
+       statMaxKbpses threadsafe.CacheKbpses,
 ) map[enum.CacheName]CacheStatus {
        conns := createCacheConnections(statResultHistory)
        statii := map[enum.CacheName]CacheStatus{}
        localCacheStatus := localCacheStatusThreadsafe.Get()
+       maxKbpses := statMaxKbpses.Get()
 
        for cacheName, cacheType := range cacheTypes {
                infoHistory, ok := statInfoHistory[cacheName]
@@ -944,14 +947,21 @@ func createCacheStatuses(
                }
 
                var kbps *float64
-               lastStat, ok := lastStats.Caches[cacheName]
-               if !ok {
+               if lastStat, ok := lastStats.Caches[cacheName]; !ok {
                        log.Warnf("cache not in last kbps cache %s\n", 
cacheName)
                } else {
                        kbpsVal := lastStat.Bytes.PerSec / 
float64(ds.BytesPerKilobit)
                        kbps = &kbpsVal
                }
 
+               var maxKbps *float64
+               if v, ok := maxKbpses[cacheName]; !ok {
+                       log.Warnf("cache not in max kbps cache %s\n", cacheName)
+               } else {
+                       fv := float64(v)
+                       maxKbps = &fv
+               }
+
                var connections *int64
                connectionsVal, ok := conns[cacheName]
                if !ok {
@@ -989,6 +999,7 @@ func createCacheStatuses(
                        StatSpanMilliseconds:   &statSpan,
                        HealthSpanMilliseconds: &healthSpan,
                        BandwidthKbps:          kbps,
+                       BandwidthCapacityKbps:  maxKbps,
                        ConnectionCount:        connections,
                        Status:                 status,
                }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/edb7e633/traffic_monitor/experimental/traffic_monitor/static/index.html
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/static/index.html 
b/traffic_monitor/experimental/traffic_monitor/static/index.html
index be9129f..b3d6227 100644
--- a/traffic_monitor/experimental/traffic_monitor/static/index.html
+++ b/traffic_monitor/experimental/traffic_monitor/static/index.html
@@ -321,7 +321,10 @@ under the License.
                                                 
document.getElementById("cache-states-" + server + "-stat-span").textContent = 
jdata[server].stat_span_ms;
                                         }
                                         if 
(jdata[server].hasOwnProperty("bandwidth_kbps")) {
-                                                
document.getElementById("cache-states-" + server + "-bandwidth").textContent = 
(jdata[server].bandwidth_kbps / kilobitsInMegabit).toFixed(2);
+                                                var kbps = 
(jdata[server].bandwidth_kbps / kilobitsInMegabit).toFixed(2);
+                                                var max = 
numberStrWithCommas((jdata[server].bandwidth_capacity_kbps / 
kilobitsInMegabit).toFixed(0));
+                                                
document.getElementById("cache-states-" + server + "-bandwidth").textContent = 
'' + kbps + ' / ' + max;
+
                                         } else {
                                                 
document.getElementById("cache-states-" + server + "-bandwidth").textContent = 
"N/A";
                                         }

Reply via email to