From 2e47fc7f2c045b71ca13a7de6cfa9d076f0e8406 Mon Sep 17 00:00:00 2001 From: Sian January Date: Thu, 5 Oct 2017 15:16:32 +0100 Subject: [PATCH] HTTPS data in graphs (#118) * New https data now in graphs * Update submodule --- lib/appmetrics-dash.js | 56 ++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +-- public/graphmetrics | 2 +- public/index.html | 10 ++++++-- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/lib/appmetrics-dash.js b/lib/appmetrics-dash.js index e812dff..28bbc64 100644 --- a/lib/appmetrics-dash.js +++ b/lib/appmetrics-dash.js @@ -26,6 +26,8 @@ var latestGCEvent; var latestLoopEvent; var aggregateHttpEvent; var aggregateHttpOutboundEvent; +var aggregateHttpsEvent; +var aggregateHttpsOutboundEvent; var aggregateProbeEvents = []; // Used for top 5 response times var httpURLData = {}; @@ -313,6 +315,34 @@ exports.monitor = function(options) { }); + monitoring.on('https', function(data) { + if (!aggregateHttpsEvent) { + aggregateHttpsEvent = {}; + aggregateHttpsEvent.total = 1; + aggregateHttpsEvent.average = data.duration; + aggregateHttpsEvent.longest = data.duration; + aggregateHttpsEvent.time = data.time; + aggregateHttpsEvent.url = data.url; + } else { + aggregateHttpsEvent.total = aggregateHttpsEvent.total + 1; + aggregateHttpsEvent.average = (aggregateHttpsEvent.average * (aggregateHttpsEvent.total - 1) + data.duration) / aggregateHttpsEvent.total; + if (data.duration > aggregateHttpsEvent.longest) { + aggregateHttpsEvent.longest = data.duration; + aggregateHttpsEvent.url = data.url; + } + } + + if (httpURLData.hasOwnProperty(data.url)) { + var urlData = httpURLData[data.url]; + // Recalculate the average + urlData.duration = (urlData.duration * urlData.hits + data.duration) / (urlData.hits + 1); + urlData.hits = urlData.hits + 1; + } else { + httpURLData[data.url] = {duration: data.duration, hits: 1}; + } + + }); + monitoring.on('http-outbound', function(data) { if (!aggregateHttpOutboundEvent) { aggregateHttpOutboundEvent = {}; @@ -331,6 +361,24 @@ exports.monitor = function(options) { } }); + monitoring.on('https-outbound', function(data) { + if (!aggregateHttpsOutboundEvent) { + aggregateHttpsOutboundEvent = {}; + aggregateHttpsOutboundEvent.total = 1; + aggregateHttpsOutboundEvent.average = data.duration; + aggregateHttpsOutboundEvent.longest = data.duration; + aggregateHttpsOutboundEvent.time = data.time; + aggregateHttpsOutboundEvent.url = data.url; + } else { + aggregateHttpsOutboundEvent.total = aggregateHttpsOutboundEvent.total + 1; + aggregateHttpsOutboundEvent.average = (aggregateHttpsOutboundEvent.average * (aggregateHttpsOutboundEvent.total - 1) + data.duration) / aggregateHttpsOutboundEvent.total; + if (data.duration > aggregateHttpsOutboundEvent.longest) { + aggregateHttpsOutboundEvent.longest = data.duration; + aggregateHttpsOutboundEvent.url = data.url; + } + } + }); + monitoring.on('mongo', function(data) { addProbeEvent('MongoDB', data); }); @@ -399,6 +447,10 @@ function emitData() { io.emit('http', JSON.stringify(aggregateHttpEvent)); aggregateHttpEvent = null; } + if (aggregateHttpsEvent) { + io.emit('https', JSON.stringify(aggregateHttpsEvent)); + aggregateHttpsEvent = null; + } if (latestGCEvent) { io.emit('gc', JSON.stringify(latestGCEvent)); latestGCEvent = null; @@ -407,6 +459,10 @@ function emitData() { io.emit('http-outbound', JSON.stringify(aggregateHttpOutboundEvent)); aggregateHttpOutboundEvent = null; } + if (aggregateHttpsOutboundEvent) { + io.emit('https-outbound', JSON.stringify(aggregateHttpsOutboundEvent)); + aggregateHttpsOutboundEvent = null; + } if (aggregateProbeEvents.length > 0) { io.emit('probe-events', JSON.stringify(aggregateProbeEvents)); aggregateProbeEvents = []; diff --git a/package.json b/package.json index b7231ca..85b4526 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "appmetrics-dash", - "version": "3.3.3", + "version": "3.3.4", "description": "Embedded monitoring dashboard for Node.js applications.", "main": "index.js", "dependencies": { - "appmetrics": "^3.0.1", + "appmetrics": "^3.1.0", "debug": "^2.6.0", "express": "^4.14.1", "express-basic-auth": "^1.0.1", diff --git a/public/graphmetrics b/public/graphmetrics index fa44723..cb4889e 160000 --- a/public/graphmetrics +++ b/public/graphmetrics @@ -1 +1 @@ -Subproject commit fa44723a1e0179ee5364ef4f9ab6ed571ce62aeb +Subproject commit cb4889e58c853cad729ab1039a8c1cfe0697abd3 diff --git a/public/index.html b/public/index.html index 5d0a3d8..ca8ecb7 100644 --- a/public/index.html +++ b/public/index.html @@ -168,10 +168,10 @@ - + - + @@ -200,6 +200,12 @@ socket.on('http', function(data) { updateHttpData(data); }); + socket.on('https-outbound', function(data) { + updateHttpsOBData(data); + }); + socket.on('https', function(data) { + updateHttpsData(data); + }); setHttpTop5Options({host: hostname, filteredPath: dashboardRoot}); socket.on('http-urls', function(data) { updateURLData(data);