This commit is contained in:
2019-05-22 03:47:20 +00:00
parent 34ee987b03
commit e65fff3ac0
34 changed files with 1725 additions and 1532 deletions
+22 -5
View File
@@ -13,6 +13,27 @@ class SystemProcessCounter
*/
public static $command = 'horizon:work';
/**
* Get CPU and memory usage for each Horizon workers for a given supervisor.
*
* @param string $name
* @return \Illuminate\Support\Collection
*/
public function getWorkerStats($name)
{
$process = Process::fromShellCommandline('exec ps axo %cpu,%mem,command | grep '.static::$command.' | grep "supervisor='.$name.'" | grep -v "exec ps axo"', null, ['COLUMNS' => '2000']);
$process->run();
$rows = explode("\n", $process->getOutput());
return collect($rows)->filter()->map(function ($rows) {
$row = collect(explode(' ', $rows))->filter()->take(2);
return ['cpu' => $row->first() / 100, 'mem' => $row->last()];
});
}
/**
* Get the number of Horizon workers for a given supervisor.
*
@@ -21,10 +42,6 @@ class SystemProcessCounter
*/
public function get($name)
{
$process = Process::fromShellCommandline('exec ps aux | grep '.static::$command, null, ['COLUMNS' => '2000']);
$process->run();
return substr_count($process->getOutput(), 'supervisor='.$name);
return $this->getWorkerStats($name)->count();
}
}