diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-11-13 17:05:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 17:05:10 +0300 |
commit | 9e6b60768498206e80d4f603c49777da62883d3d (patch) | |
tree | 42c31f6ca8774f111861b9baa37207fea39e15bf | |
parent | 54f746cb107dcf1565d740720d17785bf0587cbf (diff) | |
parent | 2a3b31b2dc626ac4eed86f7a2c40e1e6c70c9f6d (diff) |
Merge pull request #105 from Noodlesalat/masterv13.0.0beta1
Splitted swap and memory graph into two different graphs
-rw-r--r-- | js/script.js | 48 | ||||
-rw-r--r-- | lib/SystemStatistics.php | 12 | ||||
-rw-r--r-- | templates/settings-admin.php | 3 |
3 files changed, 42 insertions, 21 deletions
diff --git a/js/script.js b/js/script.js index e2e947b..d9b3519 100644 --- a/js/script.js +++ b/js/script.js @@ -22,6 +22,7 @@ var memoryUsageChart, memoryUsageLine, + swapUsageLine, cpuLoadChart, cpuLoadLine, activeusersChart, @@ -43,7 +44,7 @@ $.get(url).success(function (response) { updateCPUStatistics(response.system.cpuload); - updateMemoryStatistics(response.system.mem_total, response.system.mem_free); + updateMemoryStatistics(response.system.mem_total, response.system.mem_free, response.system.swap_total, response.system.swap_free); }); } }); @@ -70,12 +71,12 @@ cpuLoadLine = new TimeSeries(); cpuLoadChart.addTimeSeries(cpuLoadLine, {lineWidth:1, strokeStyle:'rgb(0, 0, 255)', fillStyle:'rgba(0, 0, 255, 0.2)'}); } - + $('#cpuFooterInfo').text(t('serverinfo', 'Load average')+": "+cpu1+" ("+t('serverinfo', 'Last minute')+")"); cpuLoadLine.append(new Date().getTime(), cpu1); } - function updateMemoryStatistics (memTotal, memFree) { + function updateMemoryStatistics (memTotal, memFree, swapTotal, swapFree) { if (memTotal === 'N/A' || memFree === 'N/A') { $('#memFooterInfo').text(t('serverinfo', 'Memory info not available')); $('#memorycanvas').addClass('hidden'); @@ -87,31 +88,46 @@ memTotalGB = memTotal / (1024 * 1024), memUsageGB = (memTotal - memFree) / (1024 * 1024); + var swapTotalBytes = swapTotal * 1024, + swapUsageBytes = (swapTotal - swapFree) * 1024, + swapTotalGB = swapTotal / (1024 * 1024), + swapUsageGB = (swapTotal - swapFree) / (1024 * 1024); + + if (memTotalGB > swapTotalGB) { + var maxValueOfChart = memTotalGB; + } else { + var maxValueOfChart = swapTotalGB; + } + if (typeof memoryUsageChart === 'undefined') { memoryUsageChart = new SmoothieChart( { - millisPerPixel:250, - maxValue:memTotalGB, - minValue:0, + millisPerPixel:250, + maxValue:maxValueOfChart, + minValue:0, grid:{fillStyle:'rgba(0,0,0,0.03)',strokeStyle:'transparent'}, labels:{fillStyle:'rgba(0,0,0,0.4)', fontSize:12} }); memoryUsageChart.streamTo(document.getElementById("memorycanvas"), 1000/*delay*/); memoryUsageLine = new TimeSeries(); memoryUsageChart.addTimeSeries(memoryUsageLine, {lineWidth:1, strokeStyle:'rgb(0, 255, 0)', fillStyle:'rgba(0, 255, 0, 0.2)'}); + swapUsageLine = new TimeSeries(); + memoryUsageChart.addTimeSeries(swapUsageLine, {lineWidth:1, strokeStyle:'rgb(255, 0, 0)', fillStyle:'rgba(255, 0, 0, 0.2)'}); } $('#memFooterInfo').text(t('serverinfo', 'Total')+": "+OC.Util.humanFileSize(memTotalBytes)+" - "+t('serverinfo', 'Current usage')+": "+OC.Util.humanFileSize(memUsageBytes)); memoryUsageLine.append(new Date().getTime(), memUsageGB); + $('#swapFooterInfo').text("SWAP "+t('serverinfo', 'Total')+": "+OC.Util.humanFileSize(swapTotalBytes)+" - "+t('serverinfo', 'Current usage')+": "+OC.Util.humanFileSize(swapUsageBytes)); + swapUsageLine.append(new Date().getTime(), swapUsageGB); } function updateShareStatistics () { var shares = $('#sharecanvas').data('shares'), shares_data = [shares.num_shares_user, shares.num_shares_groups, shares.num_shares_link, shares.num_fed_shares_sent, shares.num_fed_shares_received], - stepSize = 0; + stepSize = 0; - if (Math.max.apply(null, shares_data) < 10) {stepSize = 1;} + if (Math.max.apply(null, shares_data) < 10) {stepSize = 1;} if (typeof sharesChart === 'undefined') { var ctx = document.getElementById("sharecanvas"); @@ -119,10 +135,10 @@ sharesChart = new Chart(ctx, { type: 'bar', data: { - labels: [t('serverinfo', 'Users'), - t('serverinfo', 'Groups'), - t('serverinfo', 'Links'), - t('serverinfo', 'Federated sent'), + labels: [t('serverinfo', 'Users'), + t('serverinfo', 'Groups'), + t('serverinfo', 'Links'), + t('serverinfo', 'Federated sent'), t('serverinfo', 'Federated received')], datasets: [{ label: " ", @@ -167,7 +183,7 @@ activeUsers_data = [activeUsers.last24hours, activeUsers.last1hour, activeUsers.last5minutes], stepSize = 0; - if (Math.max.apply(null, activeUsers_data) < 10) {stepSize = 1;} + if (Math.max.apply(null, activeUsers_data) < 10) {stepSize = 1;} if (typeof activeusersChart === 'undefined') { var ctx = document.getElementById("activeuserscanvas"); @@ -175,8 +191,8 @@ activeusersChart = new Chart(ctx, { type: 'line', data: { - labels: [t('serverinfo', 'Last 24 hours'), - t('serverinfo', 'Last 1 hour'), + labels: [t('serverinfo', 'Last 24 hours'), + t('serverinfo', 'Last 1 hour'), t('serverinfo', 'Last 5 mins')], datasets: [{ label: " ", @@ -234,7 +250,7 @@ cpuloadcanvas.width = newWidth; cpuloadcanvas.height = newHeight; - + mem_canvas.width = newWidth; mem_canvas.height = newHeight; } diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index ca0aa07..d9cd669 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -58,7 +58,9 @@ class SystemStatistics { 'freespace' => $this->view->free_space(), 'cpuload' => sys_getloadavg(), 'mem_total' => $memoryUsage['mem_total'], - 'mem_free' => $memoryUsage['mem_free'] + 'mem_free' => $memoryUsage['mem_free'], + 'swap_total' => $memoryUsage['swap_total'], + 'swap_free' => $memoryUsage['swap_free'] ]; } @@ -88,7 +90,7 @@ class SystemStatistics { } // check if determining memoryUsage failed if ($memoryUsage === false) { - return ['mem_free' => 'N/A', 'mem_total' => 'N/A']; + return ['mem_free' => 'N/A', 'mem_total' => 'N/A', 'swap_free' => 'N/A', 'swap_total' => 'N/A']; } $array = explode(PHP_EOL, $memoryUsage); // the last value is a empty string after explode, skip it @@ -107,8 +109,10 @@ class SystemStatistics { } return [ - 'mem_free' => (int)$available + (int)$data['SwapFree'], - 'mem_total' => (int)$data['MemTotal'] + (int)$data['SwapTotal'] + 'mem_free' => (int)$available, + 'mem_total' => (int)$data['MemTotal'], + 'swap_free' => (int)$data['SwapFree'], + 'swap_total' => (int)$data['SwapTotal'] ]; } diff --git a/templates/settings-admin.php b/templates/settings-admin.php index a6e7514..abef20b 100644 --- a/templates/settings-admin.php +++ b/templates/settings-admin.php @@ -35,7 +35,8 @@ style('serverinfo', 'style'); <div class="section" id="memorySection"> <h2><?php p($l->t('Memory usage'));?></h2> <canvas id="memorycanvas" width="600" height="150"></canvas> - <p><em id="memFooterInfo"></em></p> + <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QYBDCANxB9ROQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAUSURBVBjTY2T4z4AHMDEwjEpjAgBALQETBkU7DgAAAABJRU5ErkJggg==" alt="RAM color" /> <em id="memFooterInfo"></em></p> + <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QYBDB0ds0AJ4wAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAASSURBVBjTY/zPgA8wMYxKYwEAQSwBE2ViEDMAAAAASUVORK5CYII=" alt="SWAP color" /> <em id="swapFooterInfo"></em></p> </div> <div class="section" id="activeUsersSection"> <h2><?php p($l->t('Active users'));?></h2> |