diff --git a/meshcentral.js b/meshcentral.js index 82bdfd79..e9766eae 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -802,22 +802,20 @@ function CreateMeshCentralServer(config, args) { // Start collecting server stats every 5 minutes setInterval(function () { - obj.db.getStats(function (dbstats) { - var data = { - time: new Date(), - mem: process.memoryUsage(), - db: dbstats, - cpu: process.cpuUsage(), - conn: { - ca: Object.keys(obj.webserver.wsagents).length, - cu: Object.keys(obj.webserver.wssessions).length, - us: Object.keys(obj.webserver.wssessions2).length, - rs: obj.webserver.relaySessionCount - } - }; - if (obj.mpsserver != null) { data.conn.am = Object.keys(obj.mpsserver.ciraConnections).length; } - obj.db.SetServerStats(data); - }); + var data = { + time: new Date(), + mem: process.memoryUsage(), + //cpu: process.cpuUsage(), + conn: { + ca: Object.keys(obj.webserver.wsagents).length, + cu: Object.keys(obj.webserver.wssessions).length, + us: Object.keys(obj.webserver.wssessions2).length, + rs: obj.webserver.relaySessionCount + } + }; + if (obj.mpsserver != null) { data.conn.am = Object.keys(obj.mpsserver.ciraConnections).length; } + obj.db.SetServerStats(data); // Save the stats to the database + obj.DispatchEvent(['*'], obj, { action: 'servertimelinestats', data: data }); // Event the server stats }, 300000); //obj.debug(1, 'Server started'); diff --git a/package.json b/package.json index 381c5538..e6956eba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.1-e", + "version": "0.3.1-g", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default-min.handlebars b/views/default-min.handlebars index 5dcc8dfa..7ef941d7 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -1 +1 @@ - MeshCentral
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file + MeshCentral
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index 0f035572..356679ff 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -744,14 +744,13 @@
- @@ -1591,6 +1590,7 @@ masterUpdate(32); } switch (message.event.action) { + case 'servertimelinestats': { addServerTimelineStats(message.event.data); break; } case 'accountcreate': case 'accountchange': { // An account was created or changed @@ -6462,18 +6462,20 @@ var x = '', dateHeader = null; for (var i in events) { var event = events[i], time = new Date(event.time); - if (time.toLocaleDateString() != dateHeader) { - if (dateHeader != null) x += ''; - x += ''; - dateHeader = time.toLocaleDateString(); - } - var icon = 'si3'; - if (event.etype == 'user') icon = 'm2'; - if (event.etype == 'server') icon = 'si3'; + if (event.msg) { + if (time.toLocaleDateString() != dateHeader) { + if (dateHeader != null) x += '
' + time.toLocaleDateString() + '
'; + x += ''; + dateHeader = time.toLocaleDateString(); + } + var icon = 'si3'; + if (event.etype == 'user') icon = 'm2'; + if (event.etype == 'server') icon = 'si3'; - var msg = event.msg.split('(R)').join('®'); - if (event.username && event.username != userinfo.name) { msg += ': ' + event.username; } - x += ''; + var msg = event.msg.split('(R)').join('®'); + if (event.username && event.username != userinfo.name) { msg += ': ' + event.username; } + x += ''; + } } if (dateHeader != null) x += '
' + time.toLocaleDateString() + '
 ' + time.toLocaleTimeString() + ' - ' + msg + ' 
 ' + time.toLocaleTimeString() + ' - ' + msg + ' 
'; if (x == '') x = "
No Events Found

"; @@ -7259,6 +7261,7 @@ data: { labels: [], datasets: [{ label: '', backgroundColor: 'rgba(255, 99, 132, .5)', borderColor: 'rgb(255, 99, 132)', data: [], fill: true }] }, options: { responsive: true, + maintainAspectRatio: false, scales: { xAxes: [{ type: 'time', time: { tooltipFormat: 'll HH:mm' }, display: true, scaleLabel: { display: false, labelString: '' } }], yAxes: [{ display: true, scaleLabel: { display: true, labelString: '' } }] @@ -7269,6 +7272,28 @@ function refreshServerTimelineStats(stats) { meshserver.send({ action: 'servertimelinestats', hours: 24 }); } function pastDate(hours) { var t = new Date(); t.setTime(t.getTime() - (60 * 60 * 1000 * hours)); return t; } function setServerTimelineStats(stats) { serverTimelineStats = stats; updateServerTimelineStats(); } + function addServerTimelineStats(stats) { + if (serverTimelineStats == null) return; + serverTimelineStats.push(stats); + var chartType = Q('p40type').value; + if (chartType == 0) { + serverTimelineConfig.data.datasets[0].data.push({ x: stats.time, y: stats.conn.ca }); + serverTimelineConfig.data.datasets[1].data.push({ x: stats.time, y: stats.conn.cu }); + serverTimelineConfig.data.datasets[2].data.push({ x: stats.time, y: stats.conn.us }); + serverTimelineConfig.data.datasets[3].data.push({ x: stats.time, y: stats.conn.rs }); + } else if (chartType == 1) { + serverTimelineConfig.data.datasets[0].data.push({ x: stats.time, y: stats.mem.external / (1024 * 1024) }); + serverTimelineConfig.data.datasets[1].data.push({ x: stats.time, y: stats.mem.heapUsed / (1024 * 1024) }); + serverTimelineConfig.data.datasets[2].data.push({ x: stats.time, y: stats.mem.heapTotal / (1024 * 1024) }); + serverTimelineConfig.data.datasets[3].data.push({ x: stats.time, y: stats.mem.rss / (1024 * 1024) }); + } /* else if (chartType == 2) { + serverTimelineConfig.data.datasets[0].data.push({ x: stats.time, y: stats.db.meshes }); + serverTimelineConfig.data.datasets[1].data.push({ x: stats.time, y: stats.db.nodes }); + serverTimelineConfig.data.datasets[2].data.push({ x: stats.time, y: stats.db.users }); + serverTimelineConfig.data.datasets[3].data.push({ x: stats.time, y: stats.db.total }); + } */ + updateServerTimelineHours(); + } function updateServerTimelineHours() { serverTimelineConfig.options.scales.xAxes[0].time = { min: pastDate(Q('p40time').value) }; window.serverMainStats.update(); } function setupServerTimelineStats() { window.serverMainStats = new Chart(document.getElementById('serverMainStats').getContext('2d'), serverTimelineConfig); } @@ -7314,7 +7339,7 @@ data.datasets[2].data.push({ x: serverTimelineStats[i].time, y: serverTimelineStats[i].mem.heapTotal / (1024 * 1024) }); data.datasets[3].data.push({ x: serverTimelineStats[i].time, y: serverTimelineStats[i].mem.rss / (1024 * 1024) }); } - } else if (chartType == 2) { // Database + } /*else if (chartType == 2) { // Database serverTimelineConfig.options.scales.yAxes[0].scaleLabel.labelString = 'Records'; data = { labels: [pastDate(0), timeAfter], @@ -7331,7 +7356,7 @@ data.datasets[2].data.push({ x: serverTimelineStats[i].time, y: serverTimelineStats[i].db.users }); data.datasets[3].data.push({ x: serverTimelineStats[i].time, y: serverTimelineStats[i].db.total }); } - } + }*/ serverTimelineConfig.data = data; window.serverMainStats.update(); }