-
Notifications
You must be signed in to change notification settings - Fork 65
Added apps updates monitoring #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8714f21
Added apps updates monitoring, closes #86
patschi 3d85e15
Add enabled apps for monitoring endpoint as well
patschi 13ef75a
Rework: Retrieve installed apps using IAppManager
patschi ac34662
Merge branch 'master' into add-apps-monitoring
patschi 0d409df
Stealthy fixed indent
patschi 817bc41
Some phpdoc fixes
patschi 13e5bd2
Merge branch 'master' into add-apps-monitoring
patschi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,25 +24,38 @@ | |
|
|
||
| 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 appFetcher */ | ||
| private $appFetcher; | ||
| /** @var appManager */ | ||
|
||
| private $appManager; | ||
|
|
||
| /** | ||
| * SystemStatistics constructor. | ||
| * | ||
| * @param IConfig $config | ||
| * @param IConfig $config | ||
| * @param IAppManager $appManager | ||
| */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the doc block, just duplicating the method signature anyway. |
||
| 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 [ | ||
|
|
@@ -60,7 +73,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() | ||
| ]; | ||
| } | ||
|
|
||
|
|
@@ -80,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]; | ||
|
|
@@ -130,4 +144,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; | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppFetcher