From 1e8822797d76b6ff8dd849cc7dad52549860b39e Mon Sep 17 00:00:00 2001 From: sjanuary Date: Thu, 4 Jan 2018 13:23:15 +0000 Subject: [PATCH 1/5] Update dashboard and add summary tab --- public/graphmetrics | 2 +- public/index.html | 101 +++++++++++++++++++++++++++++++++----------- 2 files changed, 78 insertions(+), 25 deletions(-) diff --git a/public/graphmetrics b/public/graphmetrics index fa44723..b397417 160000 --- a/public/graphmetrics +++ b/public/graphmetrics @@ -1 +1 @@ -Subproject commit fa44723a1e0179ee5364ef4f9ab6ed571ce62aeb +Subproject commit b397417320ba48c6dccc49a8c3891ab5e61da1be diff --git a/public/index.html b/public/index.html index 7c4ef7a..682fc23 100755 --- a/public/index.html +++ b/public/index.html @@ -34,21 +34,47 @@
-
-
-
-
-
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
- - + - + + From 058dd0cb7d260f44a88b3810e15a4e18ced34f3e Mon Sep 17 00:00:00 2001 From: sjanuary Date: Thu, 4 Jan 2018 14:01:35 +0000 Subject: [PATCH 2/5] Add summary of CPU and memory --- .../SwiftMetricsDash/SwiftMetricsDash.swift | 29 +++++++++++++++++-- public/index.html | 19 +++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Sources/SwiftMetricsDash/SwiftMetricsDash.swift b/Sources/SwiftMetricsDash/SwiftMetricsDash.swift index f02d10c..90de361 100644 --- a/Sources/SwiftMetricsDash/SwiftMetricsDash.swift +++ b/Sources/SwiftMetricsDash/SwiftMetricsDash.swift @@ -41,6 +41,16 @@ public class SwiftMetricsDash { var service:SwiftMetricsService var createServer: Bool = false + // CPU summary data + let totalProcessCPULoad = 0.0; + let totalSystemCPULoad = 0.0; + let cpuLoadSamples = 0 + + // Memory summary data + let totalProcessMemory = 0; + let totalSystemMemory = 0; + let memorySamples = 0; + public convenience init(swiftMetricsInstance : SwiftMetrics) throws { try self.init(swiftMetricsInstance : swiftMetricsInstance , endpoint: nil) } @@ -69,7 +79,7 @@ public class SwiftMetricsDash { func startServer(router: Router) throws { router.all("/swiftmetrics-dash", middleware: StaticFileServer(path: self.SM.localSourceDirectory + "/public")) - + if self.createServer { let configMgr = ConfigurationManager().load(.environmentVariables) Kitura.addHTTPServer(onPort: configMgr.port, with: router) @@ -100,7 +110,13 @@ class SwiftMetricsService: WebSocketService { func sendCPU(cpu: CPUData) { - let cpuLine = JSON(["topic":"cpu", "payload":["time":"\(cpu.timeOfSample)","process":"\(cpu.percentUsedByApplication)","system":"\(cpu.percentUsedBySystem)"]]) + totalProcessCPULoad += cpu.percentUsedByApplication; + totalSystemCPULoad += cpu.percentUsedBySystem; + cpuLoadSamples++; + var processMean = (totalProcessCPULoad / cpuLoadSamples); + var systemMean = (totalSystemCPULoad / cpuLoadSamples); + + let cpuLine = JSON(["topic":"cpu", "payload":["time":"\(cpu.timeOfSample)","process":"\(cpu.percentUsedByApplication)","system":"\(cpu.percentUsedBySystem),"processMean":"\(processMean),"systemMean":"\(systemMean)"]]) for (_,connection) in connections { if let messageToSend = cpuLine.rawString() { @@ -112,11 +128,18 @@ class SwiftMetricsService: WebSocketService { func sendMEM(mem: MemData) { + totalProcessMemory += mem.applicationRAMUsed; + totalSystemMemory += mem.totalRAMUsed; + memorySamples++; + var processMean = (totalProcessMemory / memorySamples); + var systemMean = (totalSystemMemory / memorySamples); let memLine = JSON(["topic":"memory","payload":[ "time":"\(mem.timeOfSample)", "physical":"\(mem.applicationRAMUsed)", - "physical_used":"\(mem.totalRAMUsed)" + "physical_used":"\(mem.totalRAMUsed)", + "processMean":"\(processMean)", + "systemMean":"\(systemMean)" ]]) for (_,connection) in connections { diff --git a/public/index.html b/public/index.html index 682fc23..9447579 100755 --- a/public/index.html +++ b/public/index.html @@ -134,16 +134,13 @@ webSocketProtocol = "wss://" } var client = new WebSocket(webSocketProtocol + hostname + dashboardRoot,"swiftmetrics-dash") - let summary = {cpu:{}, gc:{}, memoryPools:{}}; + let summary = {cpu:{}, gc:{}, memory:{}}; let envTable = new TextTable('#envDiv', '#summary', localizedStrings.envTitle); let summaryTable = new TextTable('#summaryDiv', '#summary', localizedStrings.summaryTitle); let httpSummary = new HttpSummary('#httpSummaryDiv', '#summary', localizedStrings.httpSummaryTitle); httpSummary.setHttpSummaryOptions({host: hostname, filteredPath: location.origin + dashboardRoot}); - - setHttpTop5Options({host: hostname, filteredPath: location.origin + dashboardRoot}); - client.onmessage = function(message) { received = JSON.parse(message.data); topic = received.topic; @@ -157,6 +154,8 @@ break; case 'memory': updateMemData(payload); + summary.memory.systemMean = received.payload.systemMean; + summary.memory.processMean = received.payload.processMean; break; case 'env': envTable.populateTableJSON(payload); @@ -183,11 +182,23 @@ let valueStr = value.toLocaleString([],{style: 'percent', minimumSignificantDigits: 4, maximumSignificantDigits: 4}); summaryData.push({Parameter: 'Average System CPU', Value: valueStr}); } + if( summary.memory.processMean ) { + summaryData.push({Parameter: 'Average Process Memory', Value: `${summary.memory.processMean} bytes`}); + } + if( summary.memory.systemMean ) { + summaryData.push({Parameter: 'Average System Memory', Value: `${summary.memory.systemMean} bytes`}); + } summaryTable.populateTable(summaryData); } let selected_tab = "dashboard-tab" window.addEventListener('resize', resize); + // Also re-size when we change tabs in case we re-sized + // while the new tab wasn't visible. + $('.nav-tabs a').on('shown.bs.tab', function(event) { + selected_tab = event.target.id; + resize(); + }); function resize() { if (selected_tab == "dashboard-tab") { From c5604f151c900766615c6d8148dbcf44081aaa65 Mon Sep 17 00:00:00 2001 From: sjanuary Date: Thu, 4 Jan 2018 14:20:54 +0000 Subject: [PATCH 3/5] fix compile errors --- .../SwiftMetricsDash/SwiftMetricsDash.swift | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/Sources/SwiftMetricsDash/SwiftMetricsDash.swift b/Sources/SwiftMetricsDash/SwiftMetricsDash.swift index 90de361..14097be 100644 --- a/Sources/SwiftMetricsDash/SwiftMetricsDash.swift +++ b/Sources/SwiftMetricsDash/SwiftMetricsDash.swift @@ -41,16 +41,6 @@ public class SwiftMetricsDash { var service:SwiftMetricsService var createServer: Bool = false - // CPU summary data - let totalProcessCPULoad = 0.0; - let totalSystemCPULoad = 0.0; - let cpuLoadSamples = 0 - - // Memory summary data - let totalProcessMemory = 0; - let totalSystemMemory = 0; - let memorySamples = 0; - public convenience init(swiftMetricsInstance : SwiftMetrics) throws { try self.init(swiftMetricsInstance : swiftMetricsInstance , endpoint: nil) } @@ -98,6 +88,17 @@ class SwiftMetricsService: WebSocketService { let jobsQueue = DispatchQueue(label: "jobsQueue") var monitor:SwiftMonitor + // CPU summary data + var totalProcessCPULoad: Double = 0.0; + var totalSystemCPULoad: Double = 0.0; + var cpuLoadSamples: Double = 0 + + // Memory summary data + var totalProcessMemory: Int = 0; + var totalSystemMemory: Int = 0; + var memorySamples: Int = 0; + + public init(monitor: SwiftMonitor) { self.monitor = monitor @@ -110,13 +111,13 @@ class SwiftMetricsService: WebSocketService { func sendCPU(cpu: CPUData) { - totalProcessCPULoad += cpu.percentUsedByApplication; - totalSystemCPULoad += cpu.percentUsedBySystem; - cpuLoadSamples++; - var processMean = (totalProcessCPULoad / cpuLoadSamples); - var systemMean = (totalSystemCPULoad / cpuLoadSamples); + totalProcessCPULoad += Double(cpu.percentUsedByApplication); + totalSystemCPULoad += Double(cpu.percentUsedBySystem); + cpuLoadSamples += 1; + let processMean = (totalProcessCPULoad / cpuLoadSamples); + let systemMean = (totalSystemCPULoad / cpuLoadSamples); - let cpuLine = JSON(["topic":"cpu", "payload":["time":"\(cpu.timeOfSample)","process":"\(cpu.percentUsedByApplication)","system":"\(cpu.percentUsedBySystem),"processMean":"\(processMean),"systemMean":"\(systemMean)"]]) + let cpuLine = JSON(["topic":"cpu", "payload":["time":"\(cpu.timeOfSample)","process":"\(cpu.percentUsedByApplication)","system":"\(cpu.percentUsedBySystem)","processMean":"\(processMean)","systemMean":"\(systemMean)"]]) for (_,connection) in connections { if let messageToSend = cpuLine.rawString() { @@ -130,9 +131,9 @@ class SwiftMetricsService: WebSocketService { func sendMEM(mem: MemData) { totalProcessMemory += mem.applicationRAMUsed; totalSystemMemory += mem.totalRAMUsed; - memorySamples++; - var processMean = (totalProcessMemory / memorySamples); - var systemMean = (totalSystemMemory / memorySamples); + memorySamples += 1; + let processMean = (totalProcessMemory / memorySamples); + let systemMean = (totalSystemMemory / memorySamples); let memLine = JSON(["topic":"memory","payload":[ "time":"\(mem.timeOfSample)", From e655cd8f0e3fbe0a96437bf04317176a7bd6bc13 Mon Sep 17 00:00:00 2001 From: sjanuary Date: Tue, 9 Jan 2018 13:35:50 +0000 Subject: [PATCH 4/5] add extra HTTP data --- Sources/SwiftMetricsDash/SwiftMetricsDash.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftMetricsDash/SwiftMetricsDash.swift b/Sources/SwiftMetricsDash/SwiftMetricsDash.swift index 14097be..619e1d5 100644 --- a/Sources/SwiftMetricsDash/SwiftMetricsDash.swift +++ b/Sources/SwiftMetricsDash/SwiftMetricsDash.swift @@ -82,7 +82,7 @@ class SwiftMetricsService: WebSocketService { private var connections = [String: WebSocketConnection]() var httpAggregateData: HTTPAggregateData = HTTPAggregateData() - var httpURLData:[String:(totalTime:Double, numHits:Double)] = [:] + var httpURLData:[String:(totalTime:Double, numHits:Double, longestTime:Double)] = [:] let httpURLsQueue = DispatchQueue(label: "httpURLsQueue") let httpQueue = DispatchQueue(label: "httpStoreQueue") let jobsQueue = DispatchQueue(label: "jobsQueue") @@ -243,10 +243,14 @@ class SwiftMetricsService: WebSocketService { if(urlTuple != nil) { let averageResponseTime = urlTuple!.0 let hits = urlTuple!.1 + var longest = urlTuple!.2 + if (localmyhttp.duration > longest) { + longest = localmyhttp.duration + } // Recalculate the average - self.httpURLData.updateValue(((averageResponseTime * hits + localmyhttp.duration)/(hits + 1), hits + 1), forKey: localmyhttp.url) + self.httpURLData.updateValue(((averageResponseTime * hits + localmyhttp.duration)/(hits + 1), hits + 1, longest), forKey: localmyhttp.url) } else { - self.httpURLData.updateValue((localmyhttp.duration, 1), forKey: localmyhttp.url) + self.httpURLData.updateValue((localmyhttp.duration, 1, localmyhttp.duration), forKey: localmyhttp.url) } } } @@ -275,7 +279,7 @@ class SwiftMetricsService: WebSocketService { var responseData:[JSON] = [] let localCopy = self.httpURLData for (key, value) in localCopy { - let json = JSON(["url":key, "averageResponseTime": value.0]) + let json = JSON(["url":key, "averageResponseTime": value.0, "hits": value.1, "longestResponseTime": value.2]) responseData.append(json) } var messageToSend:String="" From fe2caaeca652cc3f457462e9c4ab7054d25ff98e Mon Sep 17 00:00:00 2001 From: sjanuary Date: Tue, 16 Jan 2018 14:36:32 +0000 Subject: [PATCH 5/5] update submodule --- public/graphmetrics | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/graphmetrics b/public/graphmetrics index b397417..5cbd2f6 160000 --- a/public/graphmetrics +++ b/public/graphmetrics @@ -1 +1 @@ -Subproject commit b397417320ba48c6dccc49a8c3891ab5e61da1be +Subproject commit 5cbd2f6ad0d46f548e223d36eef7ef1e3d6b1a4d