From 8714f21303ea5cd3cb14f44152f4579958e77c88 Mon Sep 17 00:00:00 2001 From: Patrik Kernstock Date: Sun, 11 Jun 2017 14:52:28 +0200 Subject: [PATCH 1/5] Added apps updates monitoring, closes #86 Signed-off-by: Patrik Kernstock --- lib/SystemStatistics.php | 49 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index 28966ded..5d31c19c 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -24,25 +24,34 @@ use OC\Files\View; use OCP\IConfig; +use OC\App\AppStore\Fetcher\AppFetcher; class SystemStatistics { /** @var IConfig */ private $config; - /** @var View view on data/ */ private $view; + /** @var appFetcher */ + private $appFetcher; /** * SystemStatistics constructor. * * @param IConfig $config + * @param AppFetcher $appFetcher */ - public function __construct(IConfig $config) { + public function __construct(IConfig $config, AppFetcher $appFetcher) { $this->config = $config; $this->view = new View(); + $this->appFetcher = $appFetcher; } + /** + * Get statistics about the system + * + * @return array with with of data + */ public function getSystemStatistics() { $memoryUsage = $this->getMemoryUsage(); return [ @@ -58,7 +67,8 @@ public function getSystemStatistics() { 'freespace' => $this->view->free_space(), 'cpuload' => sys_getloadavg(), 'mem_total' => $memoryUsage['mem_total'], - 'mem_free' => $memoryUsage['mem_free'] + 'mem_free' => $memoryUsage['mem_free'], + 'apps' => $this->getAppsInfo(), ]; } @@ -99,4 +109,37 @@ protected function getMemoryUsage() { ]; } + /** + * Get some info about installed apps, including available updates. + * + * @return array data about apps + */ + protected function getAppsInfo() { + + // sekeleton about the data we return back + $info = [ + 'num_installed' => 0, + 'num_updates_available' => 0, + 'app_updates' => [], + ]; + + // load all apps + $appClass = new \OC_App(); + $apps = $appClass->listAllApps(); + // check each app + foreach($apps as $key => $app) { + $info['num_installed']++; + + // check if there is any new version available for that specific app + $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); + if ($newVersion) { + // new version available, count up and tell which version. + $info['num_updates_available']++; + $info['app_updates'][$app['id']] = $newVersion; + } + } + + return $info; + } + } From 3d85e156b05edee3aac1c5b9d585a3823fbc0ab9 Mon Sep 17 00:00:00 2001 From: Patrik Kernstock Date: Wed, 14 Jun 2017 03:26:12 +0200 Subject: [PATCH 2/5] Add enabled apps for monitoring endpoint as well Signed-off-by: Patrik Kernstock --- lib/SystemStatistics.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index 5d31c19c..0d421d10 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -24,6 +24,7 @@ use OC\Files\View; use OCP\IConfig; +use \OC_App; use OC\App\AppStore\Fetcher\AppFetcher; class SystemStatistics { @@ -119,16 +120,20 @@ protected function getAppsInfo() { // sekeleton about the data we return back $info = [ 'num_installed' => 0, + 'num_enabled' => 0, 'num_updates_available' => 0, 'app_updates' => [], ]; // load all apps - $appClass = new \OC_App(); - $apps = $appClass->listAllApps(); - // check each app + $apps = (new OC_App())->listAllApps(); foreach($apps as $key => $app) { + // count installed apps $info['num_installed']++; + // count activated apps + if ($app['active']) { + $info['num_enabled']++; + } // check if there is any new version available for that specific app $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); From 13ef75a29e9d323ddd4a80eb5d3d2b46ac20cb3f Mon Sep 17 00:00:00 2001 From: Patrik Kernstock Date: Wed, 5 Jul 2017 22:51:16 +0200 Subject: [PATCH 3/5] Rework: Retrieve installed apps using IAppManager Removing 'num_enabled' key temporary as the new IAppManager-way seems not to provide any reliable way to tell all activated (or even the count) apps. May follow later. Signed-off-by: Patrik Kernstock --- lib/SystemStatistics.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index 0d421d10..dbcb26c5 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -24,7 +24,7 @@ use OC\Files\View; use OCP\IConfig; -use \OC_App; +use OCP\App\IAppManager; use OC\App\AppStore\Fetcher\AppFetcher; class SystemStatistics { @@ -35,16 +35,19 @@ class SystemStatistics { private $view; /** @var appFetcher */ private $appFetcher; + /** @var appManager */ + private $appManager; /** * SystemStatistics constructor. * - * @param IConfig $config - * @param AppFetcher $appFetcher + * @param IConfig $config + * @param IAppManager $appManager */ - public function __construct(IConfig $config, AppFetcher $appFetcher) { + public function __construct(IConfig $config, IAppManager $appManager, AppFetcher $appFetcher) { $this->config = $config; $this->view = new View(); + $this->appManager = $appManager; $this->appFetcher = $appFetcher; } @@ -120,27 +123,22 @@ protected function getAppsInfo() { // sekeleton about the data we return back $info = [ 'num_installed' => 0, - 'num_enabled' => 0, 'num_updates_available' => 0, 'app_updates' => [], ]; // load all apps - $apps = (new OC_App())->listAllApps(); - foreach($apps as $key => $app) { - // count installed apps - $info['num_installed']++; - // count activated apps - if ($app['active']) { - $info['num_enabled']++; - } + $apps = $this->appManager->getInstalledApps(); + $info['num_installed'] = count($apps); + // iteriate through all installed apps. + foreach($apps as $app) { // check if there is any new version available for that specific app - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); + $newVersion = \OC\Installer::isUpdateAvailable($app, $this->appFetcher); if ($newVersion) { // new version available, count up and tell which version. $info['num_updates_available']++; - $info['app_updates'][$app['id']] = $newVersion; + $info['app_updates'][$app] = $newVersion; } } From 0d409df40b133268c1e33f28f31c6cc77d41ce9c Mon Sep 17 00:00:00 2001 From: Patrik Kernstock Date: Wed, 18 Jul 2018 22:19:27 +0200 Subject: [PATCH 4/5] Stealthy fixed indent Signed-off-by: Patrik Kernstock --- lib/SystemStatistics.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index 1e3f34b2..1777913d 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -74,7 +74,7 @@ public function getSystemStatistics() { 'mem_free' => $memoryUsage['mem_free'], 'swap_total' => $memoryUsage['swap_total'], 'swap_free' => $memoryUsage['swap_free'], - 'apps' => $this->getAppsInfo() + 'apps' => $this->getAppsInfo() ]; } @@ -94,7 +94,7 @@ protected function getMemoryUsage() { //Read Swap usage: exec("/usr/sbin/swapinfo",$return,$status); if ($status===0 && count($return) > 1) { - $line = preg_split("/[\s]+/", $return[1]); + $line = preg_split("/[\s]+/", $return[1]); if(count($line) > 3) { $swapTotal = (int) $line[3]; $swapFree = $swapTotal- (int) $line[2]; From 817bc4116780ff5c4fed67197598fb6a3fa75a32 Mon Sep 17 00:00:00 2001 From: Patrik Kernstock Date: Fri, 24 Aug 2018 00:50:20 +0200 Subject: [PATCH 5/5] Some phpdoc fixes Signed-off-by: Patrik Kernstock --- lib/SystemStatistics.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index 1777913d..c10e454e 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -33,16 +33,17 @@ class SystemStatistics { private $config; /** @var View view on data/ */ private $view; - /** @var appFetcher */ - private $appFetcher; - /** @var appManager */ + /** @var IAppManager */ private $appManager; + /** @var AppFetcher */ + private $appFetcher; /** * SystemStatistics constructor. * * @param IConfig $config * @param IAppManager $appManager + * @param AppFetcher $appFetcher */ public function __construct(IConfig $config, IAppManager $appManager, AppFetcher $appFetcher) { $this->config = $config;