diff options
author | Simon Rettberg | 2020-10-20 09:46:25 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-10-20 09:46:25 +0200 |
commit | c3eaacb8ab3dea485d842f89aa055e241b73ce8b (patch) | |
tree | 651c074563246c1ec193de9b33b80cb8556fb6a3 /modules-available/systemstatus/inc/systemstatus.inc.php | |
parent | [locationinfo] real fix of bootstrap switches (diff) | |
download | slx-admin-c3eaacb8ab3dea485d842f89aa055e241b73ce8b.tar.gz slx-admin-c3eaacb8ab3dea485d842f89aa055e241b73ce8b.tar.xz slx-admin-c3eaacb8ab3dea485d842f89aa055e241b73ce8b.zip |
[systemstatus] Add main-warning hook for low disk space
Diffstat (limited to 'modules-available/systemstatus/inc/systemstatus.inc.php')
-rw-r--r-- | modules-available/systemstatus/inc/systemstatus.inc.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/modules-available/systemstatus/inc/systemstatus.inc.php b/modules-available/systemstatus/inc/systemstatus.inc.php new file mode 100644 index 00000000..4413af5f --- /dev/null +++ b/modules-available/systemstatus/inc/systemstatus.inc.php @@ -0,0 +1,53 @@ +<?php + +class SystemStatus +{ + + /** + * Collect status about the disk and vmstore. + * The *Usage vars are filled with arrays with keys mountPoint, fileSystem, + * usedPercent, sizeKb, freeKb. + * @param array|false $systemUsage + * @param array|false $storeUsage + * @param string|false $currentSource What's currently mounted as vmstore + * @param string|false $wantedSource What should be mounted as vmstore (false if nothing configured) + * @return bool false if querying fs data from taskmanager failed + */ + public static function diskStat(&$systemUsage, &$storeUsage, &$currentSource = false, &$wantedSource = false) + { + $task = Taskmanager::submit('DiskStat'); + if ($task === false) + return false; + $task = Taskmanager::waitComplete($task, 3000); + + if (!isset($task['data']['list']) || empty($task['data']['list'])) + return false; + $wantedSource = Property::getVmStoreUrl(); + $currentSource = false; + $storeUsage = false; + $systemUsage = false; + if ($wantedSource === '<local>') { + $storePoint = '/'; + } else { + $storePoint = CONFIG_VMSTORE_DIR; + } + // Collect free space information + foreach ($task['data']['list'] as $entry) { + // StorePoint is either the atual directory of the vmstore, or / if we use internal storage + if ($entry['mountPoint'] === $storePoint) { + $storeUsage = $entry; + } + // Always report free space on system disk + if ($entry['mountPoint'] === '/') { + $systemUsage = $entry; + } + // Record what's mounted at destination, regardless of config, to indicate something is wrong + if (($currentSource === false && $wantedSource === '<local>' && $entry['mountPoint'] === '/') + || $entry['mountPoint'] === CONFIG_VMSTORE_DIR) { + $currentSource = $entry['fileSystem']; + } + } + return true; + } + +}
\ No newline at end of file |