From 1506a158f42bd6db739453b7578c7d59a17a32de Mon Sep 17 00:00:00 2001
From: the-djmaze <>
Date: Fri, 17 Feb 2023 08:26:53 +0100
Subject: [PATCH] Show loadavg in Admin -> About for #971
---
dev/Settings/Admin/About.js | 22 +++--
.../app/libraries/RainLoop/ActionsAdmin.php | 87 ++++++++++---------
.../libraries/RainLoop/Config/Application.php | 6 +-
.../Views/Admin/AdminSettingsAbout.html | 17 ++++
4 files changed, 79 insertions(+), 53 deletions(-)
diff --git a/dev/Settings/Admin/About.js b/dev/Settings/Admin/About.js
index 03801fce5..52208119f 100644
--- a/dev/Settings/Admin/About.js
+++ b/dev/Settings/Admin/About.js
@@ -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 });
@@ -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);
diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php
index ac3d3f1a0..7097cf106 100644
--- a/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php
+++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php
@@ -205,40 +205,6 @@ class ActionsAdmin extends Actions
: 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
{
@@ -261,7 +227,7 @@ class ActionsAdmin extends Actions
exit;
}
- public function DoAdminUpdateInfo() : array
+ public function DoAdminInfo() : array
{
$this->IsAdminLoggined();
@@ -294,13 +260,50 @@ class ActionsAdmin extends Actions
$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
diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php
index 0bcbeabda..8de03de9c 100644
--- a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php
+++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php
@@ -19,12 +19,12 @@ class Application extends \RainLoop\Config\AbstractConfig
$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.");
}
}
diff --git a/snappymail/v/0.0.0/app/templates/Views/Admin/AdminSettingsAbout.html b/snappymail/v/0.0.0/app/templates/Views/Admin/AdminSettingsAbout.html
index 656120ba7..0dba1b4dd 100644
--- a/snappymail/v/0.0.0/app/templates/Views/Admin/AdminSettingsAbout.html
+++ b/snappymail/v/0.0.0/app/templates/Views/Admin/AdminSettingsAbout.html
@@ -51,6 +51,23 @@
+
System
+
+
+ Average load past minute |
+ |
+
+
+ Average load past 5 minutes |
+ |
+
+
+ Average load past 15 minutes |
+ |
+
+
+
+
PHP optional extensions