Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions lib/SystemStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,39 @@

use OC\Files\View;
use OCP\IConfig;
use OCP\App\IAppManager;
use OC\App\AppStore\Fetcher\AppFetcher;

class SystemStatistics {

/** @var IConfig */
private $config;

/** @var View view on data/ */
private $view;
/** @var IAppManager */
private $appManager;
/** @var AppFetcher */
private $appFetcher;

/**
* SystemStatistics constructor.
*
* @param IConfig $config
* @param IConfig $config
* @param IAppManager $appManager
* @param AppFetcher $appFetcher
*/
public function __construct(IConfig $config) {
public function __construct(IConfig $config, IAppManager $appManager, AppFetcher $appFetcher) {
$this->config = $config;
$this->view = new View();
$this->appManager = $appManager;
$this->appFetcher = $appFetcher;
}

/**
* Get statistics about the system
*
* @return array with with of data
*/
public function getSystemStatistics() {
$memoryUsage = $this->getMemoryUsage();
return [
Expand All @@ -60,7 +74,8 @@ public function getSystemStatistics() {
'mem_total' => $memoryUsage['mem_total'],
'mem_free' => $memoryUsage['mem_free'],
'swap_total' => $memoryUsage['swap_total'],
'swap_free' => $memoryUsage['swap_free']
'swap_free' => $memoryUsage['swap_free'],
'apps' => $this->getAppsInfo()
];
}

Expand All @@ -80,7 +95,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];
Expand Down Expand Up @@ -130,4 +145,36 @@ 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
$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, $this->appFetcher);
if ($newVersion) {
// new version available, count up and tell which version.
$info['num_updates_available']++;
$info['app_updates'][$app] = $newVersion;
}
}

return $info;
}

}