diff options
author | Ivan Sein <ivan@struktur.de> | 2016-09-19 18:35:39 +0300 |
---|---|---|
committer | Ivan Sein <ivan@struktur.de> | 2016-09-19 19:30:50 +0300 |
commit | 6025651988914b06e9815c2ecbb0f398bae1e11a (patch) | |
tree | a4088d8896701b9e92ff5d6f6c77016dd693149c | |
parent | bb05d21c333bb07f62f6fc2d8166c0c9bc991407 (diff) |
Only update values which change frequently.
-rw-r--r-- | js/script.js | 66 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 44 | ||||
-rw-r--r-- | lib/Settings/AdminSettings.php | 48 | ||||
-rw-r--r-- | templates/settings-admin.php | 22 |
4 files changed, 76 insertions, 104 deletions
diff --git a/js/script.js b/js/script.js index 584d7c0..08dfa6e 100644 --- a/js/script.js +++ b/js/script.js @@ -32,6 +32,10 @@ var updateTimer = setInterval(updateInfo, 1000); resizeSystemCharts(); + updateActiveUsersStatistics(); + updateShareStatistics(); + setHumanReadableSizeToElement("dataBaseSize"); + setHumanReadableSizeToElement("phpUploadMaxSize"); function updateInfo() { var url = OC.generateUrl('/apps/serverinfo/update'); @@ -39,11 +43,6 @@ $.get(url).success(function (response) { updateCPUStatistics(response.system.cpuload); updateMemoryStatistics(response.system.mem_total, response.system.mem_free); - updateActiveUsersStatistics(response.activeUsers); - updateStoragesStatistics(response.storage) - updateShareStatistics(response.shares); - updatePHPStatistics(response.php); - updateDatabaseStatistics(response.database); }); } }); @@ -101,35 +100,14 @@ memoryUsageChart.addTimeSeries(memoryUsageLine, {lineWidth:1, strokeStyle:'rgb(0, 255, 0)', fillStyle:'rgba(0, 255, 0, 0.2)'}); } - $('#memFooterInfo').text(t('serverinfo', 'Total')+": "+bytesToSize(memTotalBytes)+" - "+t('serverinfo', 'Current usage')+": "+bytesToSize(memUsageBytes)); + $('#memFooterInfo').text(t('serverinfo', 'Total')+": "+OC.Util.humanFileSize(memTotalBytes)+" - "+t('serverinfo', 'Current usage')+": "+OC.Util.humanFileSize(memUsageBytes)); memoryUsageLine.append(new Date().getTime(), memUsageGB); } - /** - * human readable byte size - * - * @return human readable byte size string - */ - function bytesToSize(bytes) { - var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; - if (bytes == 0) return 'n/a'; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - if (i == 0) return bytes + ' ' + sizes[i]; - return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]; - }; - - function updateStoragesStatistics (storages) { - - var users_storages = storages.num_users, - files_storages = storages.num_files; - - $('#numUsersStorage').text(' ' + users_storages); - $('#numFilesStorage').text(' ' + files_storages); - } - - function updateShareStatistics (shares) { + function updateShareStatistics () { - var shares_data = [shares.num_shares_user, shares.num_shares_groups, shares.num_shares_link, shares.num_fed_shares_sent, shares.num_fed_shares_received], + 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; if (Math.max.apply(null, shares_data) < 10) {stepSize = 1;} @@ -182,12 +160,13 @@ sharesChart.update(); } - function updateActiveUsersStatistics (activeUsers) { + function updateActiveUsersStatistics () { - var activeusers_data = [activeUsers.last24hours, activeUsers.last1hour, activeUsers.last5minutes], + var activeUsers = $('#activeuserscanvas').data('users'), + 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"); @@ -200,7 +179,7 @@ t('serverinfo', 'Last 5 mins')], datasets: [{ label: " ", - data: activeusers_data, + data: activeUsers_data, fill: false, borderColor: ['rgba(0, 0, 255, 1)'], borderWidth: 1, @@ -233,22 +212,11 @@ } } - function updatePHPStatistics (php) { - - $('#phpVersion').text(' ' + php.version); - $('#phpMemLimit').text(' ' + bytesToSize(php.memory_limit)); - $('#phpMaxExecTime').text(' ' + php.max_execution_time); - $('#phpUploadMaxSize').text(' ' + bytesToSize(php.upload_max_filesize)); - } - - function updateDatabaseStatistics (database) { + function setHumanReadableSizeToElement (elementId) { + var maxUploadSize = parseInt($('#' + elementId).text()); - $('#databaseType').text(' ' + database.type); - $('#databaseVersion').text(' ' + database.version); - if (database.size === 'N/A') { - $('#dataBaseSize').text(' ' + database.size); - } else { - $('#dataBaseSize').text(' ' + bytesToSize(database.size)); + if ($.isNumeric(maxUploadSize)) { + $('#' + elementId).text(OC.Util.humanFileSize(maxUploadSize)); } } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 336ddf6..e5455df 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -26,11 +26,6 @@ use OCP\IRequest; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Controller; -use OCA\ServerInfo\DatabaseStatistics; -use OCA\ServerInfo\PhpStatistics; -use OCA\ServerInfo\SessionStatistics; -use OCA\ServerInfo\ShareStatistics; -use OCA\ServerInfo\StorageStatistics; use OCA\ServerInfo\SystemStatistics; use OCP\IURLGenerator; @@ -39,50 +34,20 @@ class PageController extends Controller { /** @var SystemStatistics */ private $systemStatistics; - /** @var StorageStatistics */ - private $storageStatistics; - - /** @var PhpStatistics */ - private $phpStatistics; - - /** @var DatabaseStatistics */ - private $databaseStatistics; - - /** @var ShareStatistics */ - private $shareStatistics; - - /** @var SessionStatistics */ - private $sessionStatistics; - /** * ApiController constructor. * * @param string $appName * @param IRequest $request * @param SystemStatistics $systemStatistics - * @param StorageStatistics $storageStatistics - * @param PhpStatistics $phpStatistics - * @param DatabaseStatistics $databaseStatistics - * @param ShareStatistics $shareStatistics - * @param SessionStatistics $sessionStatistics */ public function __construct($appName, IRequest $request, - SystemStatistics $systemStatistics, - StorageStatistics $storageStatistics, - PhpStatistics $phpStatistics, - DatabaseStatistics $databaseStatistics, - ShareStatistics $shareStatistics, - SessionStatistics $sessionStatistics + SystemStatistics $systemStatistics ) { parent::__construct($appName, $request); $this->systemStatistics = $systemStatistics; - $this->storageStatistics = $storageStatistics; - $this->phpStatistics = $phpStatistics; - $this->databaseStatistics = $databaseStatistics; - $this->shareStatistics = $shareStatistics; - $this->sessionStatistics = $sessionStatistics; } /** @@ -93,12 +58,7 @@ class PageController extends Controller { public function update() { $data = [ - 'system' => $this->systemStatistics->getSystemStatistics(), - 'storage' => $this->storageStatistics->getStorageStatistics(), - 'shares' => $this->shareStatistics->getShareStatistics(), - 'php' => $this->phpStatistics->getPhpStatistics(), - 'database' => $this->databaseStatistics->getDatabaseStatistics(), - 'activeUsers' => $this->sessionStatistics->getSessionStatistics() + 'system' => $this->systemStatistics->getSystemStatistics() ]; return new JSONResponse($data); diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php index 3a774a6..110a777 100644 --- a/lib/Settings/AdminSettings.php +++ b/lib/Settings/AdminSettings.php @@ -27,6 +27,11 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IL10N; use OCP\IURLGenerator; use OCP\Settings\ISettings; +use OCA\ServerInfo\DatabaseStatistics; +use OCA\ServerInfo\PhpStatistics; +use OCA\ServerInfo\SessionStatistics; +use OCA\ServerInfo\ShareStatistics; +use OCA\ServerInfo\StorageStatistics; class AdminSettings implements ISettings { @@ -37,15 +42,47 @@ class AdminSettings implements ISettings { /** @var IURLGenerator */ private $urlGenerator; + /** @var StorageStatistics */ + private $storageStatistics; + + /** @var PhpStatistics */ + private $phpStatistics; + + /** @var DatabaseStatistics */ + private $databaseStatistics; + + /** @var ShareStatistics */ + private $shareStatistics; + + /** @var SessionStatistics */ + private $sessionStatistics; + /** * Admin constructor. * * @param IL10N $l * @param IURLGenerator $urlGenerator + * @param StorageStatistics $storageStatistics + * @param PhpStatistics $phpStatistics + * @param DatabaseStatistics $databaseStatistics + * @param ShareStatistics $shareStatistics + * @param SessionStatistics $sessionStatistics */ - public function __construct(IL10N $l, IURLGenerator $urlGenerator) { + public function __construct(IL10N $l, + IURLGenerator $urlGenerator, + StorageStatistics $storageStatistics, + PhpStatistics $phpStatistics, + DatabaseStatistics $databaseStatistics, + ShareStatistics $shareStatistics, + SessionStatistics $sessionStatistics + ) { $this->l = $l; $this->urlGenerator = $urlGenerator; + $this->storageStatistics = $storageStatistics; + $this->phpStatistics = $phpStatistics; + $this->databaseStatistics = $databaseStatistics; + $this->shareStatistics = $shareStatistics; + $this->sessionStatistics = $sessionStatistics; } /** @@ -53,7 +90,14 @@ class AdminSettings implements ISettings { */ public function getForm() { $monitoringEndPoint = $this->urlGenerator->getAbsoluteURL('ocs/v2.php/apps/serverinfo/api/v1/info'); - $params = ['ocs' => $monitoringEndPoint]; + $params = [ + 'ocs' => $monitoringEndPoint, + 'storage' => $this->storageStatistics->getStorageStatistics(), + 'shares' => $this->shareStatistics->getShareStatistics(), + 'php' => $this->phpStatistics->getPhpStatistics(), + 'database' => $this->databaseStatistics->getDatabaseStatistics(), + 'activeUsers' => $this->sessionStatistics->getSessionStatistics() + ]; return new TemplateResponse('serverinfo', 'settings-admin', $params); } diff --git a/templates/settings-admin.php b/templates/settings-admin.php index 1ccb29b..b6b352e 100644 --- a/templates/settings-admin.php +++ b/templates/settings-admin.php @@ -40,30 +40,30 @@ style('serverinfo', 'style'); <div class="section" id="activeUsersSection"> <h2><?php p($l->t('Active users'));?></h2> <br> - <canvas class="barchart" id="activeuserscanvas"></canvas> + <canvas data-users="<?php p(json_encode($_['activeUsers'])) ?>" class="barchart" id="activeuserscanvas"></canvas> </div> <div class="section" id="sharesSection"> <h2><?php p($l->t('Shares'));?></h2> <br> - <canvas class="barchart" id="sharecanvas"></canvas> + <canvas data-shares="<?php p(json_encode($_['shares'])) ?>" class="barchart" id="sharecanvas"></canvas> </div> <div class="section" id="storageSection"> <h2><?php p($l->t('Storage'));?></h2> - <p><?php p($l->t('Users:'));?><em id="numUsersStorage"> -- </em></p> - <p><?php p($l->t('Files:'));?><em id="numFilesStorage"> -- </em></p> + <p><?php p($l->t('Users:'));?> <em id="numUsersStorage"><?php p($_['storage']['num_users']);?></em></p> + <p><?php p($l->t('Files:'));?> <em id="numFilesStorage"><?php p($_['storage']['num_files']);?></em></p> </div> <div class="section" id="phpSection"> <h2><?php p($l->t('PHP'));?></h2> - <p><?php p($l->t('Version:'));?><em id="phpVersion"> -- </em></p> - <p><?php p($l->t('Memory Limit:'));?><em id="phpMemLimit"> -- </em></p> - <p><?php p($l->t('Max Execution Time:'));?><em id="phpMaxExecTime"> -- </em></p> - <p><?php p($l->t('Upload max size:'));?><em id="phpUploadMaxSize"> -- </em></p> + <p><?php p($l->t('Version:'));?> <em id="phpVersion"><?php p($_['php']['version']);?></em></p> + <p><?php p($l->t('Memory Limit:'));?> <em id="phpMemLimit"><?php p($_['php']['memory_limit']);?></em></p> + <p><?php p($l->t('Max Execution Time:'));?> <em id="phpMaxExecTime"><?php p($_['php']['max_execution_time']);?></em></p> + <p><?php p($l->t('Upload max size:'));?> <em id="phpUploadMaxSize"><?php p($_['php']['upload_max_filesize']);?></em></p> </div> <div class="section" id="databaseSection"> <h2><?php p($l->t('Database'));?></h2> - <p><?php p($l->t('Type:'));?><em id="databaseType"> -- </em></p> - <p><?php p($l->t('Version:'));?><em id="databaseVersion"> -- </em></p> - <p><?php p($l->t('Size:'));?><em id="dataBaseSize"> -- </em></p> + <p><?php p($l->t('Type:'));?> <em id="databaseType"><?php p($_['database']['type']);?></em></p> + <p><?php p($l->t('Version:'));?> <em id="databaseVersion"><?php p($_['database']['version']);?></em></p> + <p><?php p($l->t('Size:'));?> <em id="dataBaseSize"><?php p($_['database']['size']);?></em></p> </div> <div class="section" id="ocsEndPoint"> |