diff --git a/src/views/system.html b/src/views/system.html index 8fb89e9a5..8c3de60f2 100644 --- a/src/views/system.html +++ b/src/views/system.html @@ -9,7 +9,23 @@ - + + + Megabyte + + + {{ 'system.systemMemory.graphSubtext' | tr }} + + + + + + {{ 'system.cpuUsage.graphTitle' | tr }} + + + + + @@ -43,29 +59,14 @@ - - - Megabyte RAM ({{ memory.memory | prettyByteSize }}) + Swap ({{ memory.swap | prettyByteSize }}) - - - {{ 'system.systemMemory.graphSubtext' | tr }} - - - - - - {{ 'system.cpuUsage.graphTitle' | tr }} - - - - - + {{ period | trKeyFromPeriod | tr }} {{ 6 | trKeyFromPeriod | tr }} + {{ 12 | trKeyFromPeriod | tr }} {{ 24 | trKeyFromPeriod | tr }} {{ 24*7 | trKeyFromPeriod | tr }} {{ 24*30 | trKeyFromPeriod | tr }} diff --git a/src/views/system.js b/src/views/system.js index 164359fac..d53a44fc4 100644 --- a/src/views/system.js +++ b/src/views/system.js @@ -76,84 +76,100 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati } }); - // both in minutes + // in minutes var timePeriod = $scope.period * 60; - var timeBucketSize = $scope.period > 24 ? (6*60) : 5; - function fillGraph(canvasId, data, appsData, label, chartPropertyName, max, valueDivider) { - // translate the data from bytes to MB - var datapoints = data.datapoints.map(function (d) { return parseInt((d[0] / valueDivider).toFixed(2)); }); - var labels = datapoints.map(function (d, index) { - var dateTime = new Date(Date.now() - ((timePeriod - (index * timeBucketSize)) * 60 *1000)); + // keep in sync with graphs.js + var timeBucketSizeMinutes = timePeriod > (24 * 60) ? (6*60) : 5; + var steps = Math.floor(timePeriod/timeBucketSizeMinutes); - if ($scope.period > 24) { - return dateTime.toLocaleDateString(); - } else { - return dateTime.toLocaleTimeString(); - } - }); + var labels = new Array(steps).fill(0); + labels = labels.map(function (v, index) { + var dateTime = new Date(Date.now() - ((timePeriod - (index * timeBucketSizeMinutes)) * 60 * 1000)); - var datasets = [{ - label: label, - backgroundColor: '#82C4F844', - borderColor: '#2196F3', - borderWidth: 1, - radius: 0, - data: datapoints - }]; + if ($scope.period > 24) { + return dateTime.toLocaleDateString(); + } else { + return dateTime.toLocaleTimeString(); + } + }); - Object.keys(appsData).forEach(function (appId) { - var data = appsData[appId].memory; - if (!data.datapoints.some(function (p) { return p[0] > 1024*1024*1024; })) return; + var borderColors = [ '#2196F3', '#FF6384' ]; + var backgroundColors = [ '#82C4F844', '#FF63844F' ]; + + function fillGraph(canvasId, contents, chartPropertyName, divisor, max) { + if (!contents || !contents[0]) return; // no data available yet + + var datasets = []; + + contents.forEach(function (content, index) { + + // fill holes with previous value + var cur = 0; + content.data.datapoints.forEach(function (d) { + if (d[0] === null) d[0] = cur; + else cur = d[0]; + }); + + var datapoints = Array(steps).map(function () { return '0'; }); + + // walk backwards and fill up the datapoints + content.data.datapoints.reverse().forEach(function (d, index) { + datapoints[datapoints.length-1-index] = (d[0] / divisor).toFixed(2); + // return parseInt((d[0] / divisor).toFixed(2)); + }); datasets.push({ - label: Client.getInstalledAppsByAppId()[appId].fqdn, - fill: false, - borderColor: getRandomColor(), + label: content.label, + backgroundColor: backgroundColors[index], + borderColor: borderColors[index], borderWidth: 1, radius: 0, - data: data.datapoints.map(function (d) { return parseInt((d[0] / valueDivider).toFixed(2)); }) + data: datapoints, + cubicInterpolationMode: 'monotone', + tension: 0.4 }); }); - var chartData = { + var graphData = { labels: labels, datasets: datasets }; var options = { + responsive: true, maintainAspectRatio: true, aspectRatio: 2.5, - legend: { - display: false + plugins: { + legend: { + display: false + } }, - tooltips: { - intersect: false + interaction: { + intersect: false, + mode: 'index', }, scales: { - xAxes: [{ - ticks: { - autoSkipPadding: 20, - } - }], - yAxes: [{ - ticks: { - min: 0, - max: max, - beginAtZero: true - } - }] + x: { + ticks: { autoSkipPadding: 50, maxRotation: 0 } + }, + y: { + min: 0, + beginAtZero: true + } } }; + if (max) options.scales.y.max = max; + var ctx = $(canvasId).get(0).getContext('2d'); if ($scope[chartPropertyName]) $scope[chartPropertyName].destroy(); - $scope[chartPropertyName] = new Chart(ctx, { type: 'line', data: chartData, options: options }); + $scope[chartPropertyName] = new Chart(ctx, { type: 'line', data: graphData, options: options }); } - fillGraph('#graphsCPUChart', result.cpu, {}, 'CPU Usage', 'cpuChart', 100, 1); - fillGraph('#graphsSystemMemoryChart', result.memory, result.apps, 'Memory', 'memoryChart', Number.parseInt(($scope.memory.memory + $scope.memory.swap) / 1024 / 1024), 1024 * 1024); + fillGraph('#graphsCPUChart', [{ data: result.cpu, label: 'CPU' }], 'cpuChart', 100, 1); + fillGraph('#graphsSystemMemoryChart', [{ data: result.memory, label: 'Memory' }], 'memoryChart', 1024 * 1024, Number.parseInt($scope.memory.memory / 1024 / 1024)); $scope.busy = false; });