Skip to content

Commit

Permalink
Merge pull request #616 from laravel/revert-589-stats-pr
Browse files Browse the repository at this point in the history
Revert "[3.0] Display worker CPU and memory utilization in supervisor list"
  • Loading branch information
driesvints authored Jun 14, 2019
2 parents ccb4036 + fb9df5b commit 2b14e64
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 42 deletions.
4 changes: 0 additions & 4 deletions resources/js/screens/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@
<tr>
<th>Supervisor</th>
<th>Processes</th>
<th>CPU Threads</th>
<th>Memory</th>
<th>Queues</th>
<th class="text-right">Balancing</th>
</tr>
Expand All @@ -311,8 +309,6 @@
<tr v-for="supervisor in worker.supervisors">
<td>{{ superVisorDisplayName(supervisor.name, worker.name) }}</td>
<td>{{ countProcesses(supervisor.processes) }}</td>
<td>{{ supervisor.cpu }}</td>
<td>{{ supervisor.mem }}%</td>
<td>{{ supervisor.options.queue.replace(/,/g, ', ') }}</td>
<td class="text-right">
({{ supervisor.options.balance.charAt(0).toUpperCase() + supervisor.options.balance.slice(1) }})
Expand Down
7 changes: 1 addition & 6 deletions src/Repositories/RedisSupervisorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function get(array $names)
{
$records = $this->connection()->pipeline(function ($pipe) use ($names) {
foreach ($names as $name) {
$pipe->hmget('supervisor:'.$name, ['name', 'master', 'pid', 'status', 'processes', 'options', 'cpu', 'mem']);
$pipe->hmget('supervisor:'.$name, ['name', 'master', 'pid', 'status', 'processes', 'options']);
}
});

Expand All @@ -85,8 +85,6 @@ public function get(array $names)
'status' => $record[3],
'processes' => json_decode($record[4], true),
'options' => json_decode($record[5], true),
'cpu' => $record[6],
'mem' => $record[7],
];
})->filter()->all();
}
Expand Down Expand Up @@ -116,7 +114,6 @@ public function update(Supervisor $supervisor)
})->toJson();

$this->connection()->pipeline(function ($pipe) use ($supervisor, $processes) {
$workerStats = $supervisor->workerStats();
$pipe->hmset(
'supervisor:'.$supervisor->name, [
'name' => $supervisor->name,
Expand All @@ -125,8 +122,6 @@ public function update(Supervisor $supervisor)
'status' => $supervisor->working ? 'running' : 'paused',
'processes' => $processes,
'options' => $supervisor->options->toJson(),
'cpu' => number_format($workerStats->sum('cpu'), 2),
'mem' => round($workerStats->sum('mem')),
]
);

Expand Down
10 changes: 0 additions & 10 deletions src/Supervisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,16 +406,6 @@ public function totalProcessCount()
return $this->processPools->sum->totalProcessCount();
}

/**
* Get CPU and memory usage for the active workers by asking the OS.
*
* @return \Illuminate\Support\Collection
*/
public function workerStats()
{
return app(SystemProcessCounter::class)->getWorkerStats($this->name);
}

/**
* Get the total active process count by asking the OS.
*
Expand Down
27 changes: 5 additions & 22 deletions src/SystemProcessCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,6 @@ 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.
*
Expand All @@ -42,6 +21,10 @@ public function getWorkerStats($name)
*/
public function get($name)
{
return $this->getWorkerStats($name)->count();
$process = Process::fromShellCommandline('exec ps aux | grep '.static::$command, null, ['COLUMNS' => '2000']);

$process->run();

return substr_count($process->getOutput(), 'supervisor='.$name);
}
}

0 comments on commit 2b14e64

Please sign in to comment.