mirror of
https://github.com/friendica/friendica
synced 2025-01-09 23:24:42 +00:00
Merge pull request #12891 from annando/system-variables
More reliable system variables
This commit is contained in:
commit
bcec7306a5
2 changed files with 34 additions and 32 deletions
|
@ -445,34 +445,28 @@ class System
|
||||||
*/
|
*/
|
||||||
public static function getLoadAvg(bool $get_processes = true): array
|
public static function getLoadAvg(bool $get_processes = true): array
|
||||||
{
|
{
|
||||||
if ($get_processes && @is_readable('/proc/loadavg')) {
|
|
||||||
$content = @file_get_contents('/proc/loadavg');
|
|
||||||
if (empty($content)) {
|
|
||||||
$content = shell_exec('uptime | sed "s/.*averages*: //" | sed "s/,//g"');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($content) || !preg_match("#([.\d]+)\s([.\d]+)\s([.\d]+)\s(\d+)/(\d+)#", $content, $matches)) {
|
|
||||||
$load_arr = sys_getloadavg();
|
$load_arr = sys_getloadavg();
|
||||||
if (empty($load_arr)) {
|
if (empty($load_arr)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return [
|
|
||||||
|
$load = [
|
||||||
'average1' => $load_arr[0],
|
'average1' => $load_arr[0],
|
||||||
'average5' => $load_arr[1],
|
'average5' => $load_arr[1],
|
||||||
'average15' => $load_arr[2],
|
'average15' => $load_arr[2],
|
||||||
'runnable' => 0,
|
'runnable' => 0,
|
||||||
'scheduled' => 0
|
'scheduled' => 0
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($get_processes && @is_readable('/proc/loadavg')) {
|
||||||
|
$content = @file_get_contents('/proc/loadavg');
|
||||||
|
if (!empty($content) && preg_match("#([.\d]+)\s([.\d]+)\s([.\d]+)\s(\d+)/(\d+)#", $content, $matches)) {
|
||||||
|
$load['runnable'] = (float)$matches[4];
|
||||||
|
$load['scheduled'] = (float)$matches[5];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return $load;
|
||||||
'average1' => (float)$matches[1],
|
|
||||||
'average5' => (float)$matches[2],
|
|
||||||
'average15' => (float)$matches[3],
|
|
||||||
'runnable' => (float)$matches[4],
|
|
||||||
'scheduled' => (float)$matches[5]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -662,16 +662,24 @@ class Worker
|
||||||
DBA::close($r);
|
DBA::close($r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$stamp = (float)microtime(true);
|
||||||
|
$used = 0;
|
||||||
|
$sleep = 0;
|
||||||
|
$data = DBA::p("SHOW PROCESSLIST");
|
||||||
|
while ($row = DBA::fetch($data)) {
|
||||||
|
if ($row['Command'] != 'Sleep') {
|
||||||
|
++$used;
|
||||||
|
} else {
|
||||||
|
++$sleep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DBA::close($data);
|
||||||
|
self::$db_duration += (microtime(true) - $stamp);
|
||||||
|
|
||||||
// If $max is set we will use the processlist to determine the current number of connections
|
// If $max is set we will use the processlist to determine the current number of connections
|
||||||
// The processlist only shows entries of the current user
|
// The processlist only shows entries of the current user
|
||||||
if ($max != 0) {
|
if ($max != 0) {
|
||||||
$stamp = (float)microtime(true);
|
Logger::info('Connection usage (user values)', ['working' => $used, 'sleeping' => $sleep, 'max' => $max]);
|
||||||
$r = DBA::p('SHOW PROCESSLIST');
|
|
||||||
self::$db_duration += (microtime(true) - $stamp);
|
|
||||||
$used = DBA::numRows($r);
|
|
||||||
DBA::close($r);
|
|
||||||
|
|
||||||
Logger::info('Connection usage (user values)', ['usage' => $used, 'max' => $max]);
|
|
||||||
|
|
||||||
$level = ($used / $max) * 100;
|
$level = ($used / $max) * 100;
|
||||||
|
|
||||||
|
@ -695,11 +703,11 @@ class Worker
|
||||||
if (!DBA::isResult($r)) {
|
if (!DBA::isResult($r)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$used = intval($r['Value']);
|
$used = max($used, intval($r['Value'])) - $sleep;
|
||||||
if ($used == 0) {
|
if ($used == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Logger::info('Connection usage (system values)', ['used' => $used, 'max' => $max]);
|
Logger::info('Connection usage (system values)', ['working' => $used, 'sleeping' => $sleep, 'max' => $max]);
|
||||||
|
|
||||||
$level = $used / $max * 100;
|
$level = $used / $max * 100;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue