改进 不上报 内存 使用情况
This commit is contained in:
parent
50143f3ce4
commit
4f5acc3a04
@ -90,12 +90,10 @@ private function report(): void
|
|||||||
$this->info('正在报告此系统,请保持此命令一直运行。');
|
$this->info('正在报告此系统,请保持此命令一直运行。');
|
||||||
|
|
||||||
$cpu = $this->getCpuUsage();
|
$cpu = $this->getCpuUsage();
|
||||||
$memory = $this->getMemoryUsage();
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
Cluster::publish('system_usage', [
|
Cluster::publish('system_usage', [
|
||||||
'cpu' => $cpu,
|
'cpu' => $cpu,
|
||||||
'memory' => $memory,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
@ -108,29 +106,4 @@ private function getCpuUsage(): float
|
|||||||
$cpu = sys_getloadavg();
|
$cpu = sys_getloadavg();
|
||||||
return $cpu[0];
|
return $cpu[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getMemoryUsage(): float
|
|
||||||
{
|
|
||||||
// 检查 free 命令是否存在
|
|
||||||
if (exec('which free')) {
|
|
||||||
$free = exec('free');
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// fake free
|
|
||||||
$free = <<<EOF
|
|
||||||
total used free shared buff/cache available
|
|
||||||
Mem: 1982 334 1121 126 527 1380
|
|
||||||
Swap: 0 0 0
|
|
||||||
EOF;
|
|
||||||
}
|
|
||||||
|
|
||||||
$free = trim($free);
|
|
||||||
|
|
||||||
$free_arr = explode("\n", $free);
|
|
||||||
|
|
||||||
$mem = explode(" ", $free_arr[1]);
|
|
||||||
$mem = array_filter($mem);
|
|
||||||
$mem = array_merge($mem);
|
|
||||||
return round($mem[2] / $mem[1] * 100, 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user