Skip to content

Commit

Permalink
Show loadavg in Admin -> About for #971
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Feb 17, 2023
1 parent 5b536f8 commit 1506a15
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 53 deletions.
22 changes: 14 additions & 8 deletions dev/Settings/Admin/About.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class AdminSettingsAbout /*extends AbstractViewSettings*/ {
coreWarning: false,
coreVersion: '',
coreVersionCompare: -2,
load1: 0,
load5: 0,
load15: 0,
errorDesc: ''
});
this.coreChecking = ko.observable(false).extend({ throttle: 100 });
Expand Down Expand Up @@ -51,18 +54,21 @@ export class AdminSettingsAbout /*extends AbstractViewSettings*/ {
}

onBuild() {
Remote.request('AdminPHPExtensions', (iError, data) => iError || this.phpextensions(data.Result));

// beforeShow() {
this.coreChecking(true);
Remote.request('AdminUpdateInfo', (iError, data) => {
Remote.request('AdminInfo', (iError, data) => {
this.coreChecking(false);
if (!iError && data?.Result) {
data = data?.Result;
if (!iError && data) {
this.load1(data.system.load?.[0]);
this.load5(data.system.load?.[1]);
this.load15(data.system.load?.[2]);
this.phpextensions(data.php);
this.coreReal(true);
this.coreUpdatable(!!data.Result.updatable);
this.coreWarning(!!data.Result.warning);
this.coreVersion(data.Result.version || '');
this.coreVersionCompare(data.Result.versionCompare);
this.coreUpdatable(!!data.core.updatable);
this.coreWarning(!!data.core.warning);
this.coreVersion(data.core.version || '');
this.coreVersionCompare(data.core.versionCompare);
} else {
this.coreReal(false);
this.coreWarning(false);
Expand Down
87 changes: 45 additions & 42 deletions snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,40 +205,6 @@ public function DoAdminPasswordUpdate() : array
: false);
}

public function DoAdminPHPExtensions() : array
{
$aResult = [
[
'name' => 'PHP ' . PHP_VERSION,
'loaded' => true,
'version' => PHP_VERSION
],
[
'name' => 'PHP 64bit',
'loaded' => PHP_INT_SIZE == 8,
'version' => PHP_INT_SIZE
]
];
foreach (['APCu', 'cURL','GnuPG','GD','Gmagick','Imagick','iconv','intl','LDAP','OpenSSL','pdo_mysql','pdo_pgsql','pdo_sqlite','redis','Sodium','Tidy','uuid','XXTEA','Zip'] as $name) {
$aResult[] = [
'name' => ('OpenSSL' === $name && \defined('OPENSSL_VERSION_TEXT')) ? OPENSSL_VERSION_TEXT : $name,
'loaded' => \extension_loaded(\strtolower($name)),
'version' => \phpversion($name)
];
}
$aResult[] = [
'name' => 'Fileinfo',
'loaded' => \class_exists('finfo'),
'version' => \phpversion('fileinfo')
];
$aResult[] = [
'name' => 'Phar',
'loaded' => \class_exists('PharData'),
'version' => \phpversion('phar')
];
return $this->DefaultResponse($aResult);
}

// /?admin/Backup
public function DoAdminBackup() : void
{
Expand All @@ -261,7 +227,7 @@ public function DoAdminBackup() : void
exit;
}

public function DoAdminUpdateInfo() : array
public function DoAdminInfo() : array
{
$this->IsAdminLoggined();

Expand Down Expand Up @@ -294,13 +260,50 @@ public function DoAdminUpdateInfo() : array
$aWarnings[] = 'Can not edit: ' . APP_INDEX_ROOT_PATH . 'index.php';
}

return $this->DefaultResponse(array(
'updatable' => \SnappyMail\Repository::canUpdateCore(),
'warning' => $bShowWarning,
'version' => $sVersion,
'versionCompare' => \version_compare(APP_VERSION, $sVersion),
'warnings' => $aWarnings
));
$aResult = [
'system' => [
'load' => \is_callable('sys_getloadavg') ? \sys_getloadavg() : null
],
'core' => [
'updatable' => \SnappyMail\Repository::canUpdateCore(),
'warning' => $bShowWarning,
'version' => $sVersion,
'versionCompare' => \version_compare(APP_VERSION, $sVersion),
'warnings' => $aWarnings
],
'php' => [
[
'name' => 'PHP ' . PHP_VERSION,
'loaded' => true,
'version' => PHP_VERSION
],
[
'name' => 'PHP 64bit',
'loaded' => PHP_INT_SIZE == 8,
'version' => PHP_INT_SIZE
]
]
];

foreach (['APCu', 'cURL','GnuPG','GD','Gmagick','Imagick','iconv','intl','LDAP','OpenSSL','pdo_mysql','pdo_pgsql','pdo_sqlite','redis','Sodium','Tidy','uuid','XXTEA','Zip'] as $name) {
$aResult['php'][] = [
'name' => ('OpenSSL' === $name && \defined('OPENSSL_VERSION_TEXT')) ? OPENSSL_VERSION_TEXT : $name,
'loaded' => \extension_loaded(\strtolower($name)),
'version' => \phpversion($name)
];
}
$aResult['php'][] = [
'name' => 'Fileinfo',
'loaded' => \class_exists('finfo'),
'version' => \phpversion('fileinfo')
];
$aResult['php'][] = [
'name' => 'Phar',
'loaded' => \class_exists('PharData'),
'version' => \phpversion('phar')
];

return $this->DefaultResponse($aResult);
}

public function DoAdminUpgradeCore() : array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public function Load() : bool
$bResult = parent::Load();

$max = \floatval($this->Get('security', 'max_sys_getloadavg', 0));
if ($max && \function_exists('sys_getloadavg')) {
if ($max && \is_callable('sys_getloadavg')) {
$load = \sys_getloadavg();
if ($load && $load[0] > $max) {
\header('HTTP/1.1 503 Service Unavailable');
\header('HTTP/1.1 503 Service Unavailable', true, 503);
\header('Retry-After: 120');
exit('Mailserver too busy. Please try again later.');
exit("Mailserver too busy ({$load[0]}). Please try again later.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ <h4 style="color: #aaa; font-weight: normal;" data-i18n="TAB_ABOUT/LABEL_TAG_HIN
</div>
</div>

<h3>System</h3>
<table class="table table-hover table-bordered"><tbody>
<tr>
<td>Average load past minute</td>
<td data-bind="text: load1"></td>
</tr>
<tr>
<td>Average load past 5 minutes</td>
<td data-bind="text: load5"></td>
</tr>
<tr>
<td>Average load past 15 minutes</td>
<td data-bind="text: load15"></td>
</tr>
</tbody>
</table>

<h3>PHP optional extensions</h3>
<table class="table table-hover table-bordered"><thead><tr>
<th>Extension</th>
Expand Down

0 comments on commit 1506a15

Please sign in to comment.