Skip to content

Commit 4e4bd84

Browse files
committed
feat: replace deprecated backtick operators with shell_exec functions
1 parent 1738980 commit 4e4bd84

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/Recorders/Servers.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function detectMemoryUsing(?callable $callback): void
7272
public function record(SharedBeat $event): void
7373
{
7474
$this->throttle(15, $event, function ($event) {
75-
$server = $this->config->get('pulse.recorders.'.self::class.'.server_name');
75+
$server = $this->config->get('pulse.recorders.' . self::class . '.server_name');
7676
$slug = Str::slug($server);
7777

7878
['total' => $memoryTotal, 'used' => $memoryUsed] = $this->memory();
@@ -85,9 +85,9 @@ public function record(SharedBeat $event): void
8585
'cpu' => $cpu,
8686
'memory_used' => $memoryUsed,
8787
'memory_total' => $memoryTotal,
88-
'storage' => collect($this->config->get('pulse.recorders.'.self::class.'.directories')) // @phpstan-ignore argument.templateType, argument.templateType
89-
->filter(fn (string $directory) => ($this->pulse->rescue(fn () => disk_total_space($directory)) ?? false) !== false)
90-
->map(fn (string $directory) => [
88+
'storage' => collect($this->config->get('pulse.recorders.' . self::class . '.directories')) // @phpstan-ignore argument.templateType, argument.templateType
89+
->filter(fn(string $directory) => ($this->pulse->rescue(fn() => disk_total_space($directory)) ?? false) !== false)
90+
->map(fn(string $directory) => [
9191
'directory' => $directory,
9292
'total' => $total = intval(round(disk_total_space($directory) / 1024 / 1024)), // MB
9393
'used' => intval(round($total - (disk_free_space($directory) / 1024 / 1024))), // MB
@@ -107,11 +107,11 @@ protected function cpu(): int
107107
}
108108

109109
return match (PHP_OS_FAMILY) {
110-
'Darwin' => (int) `top -l 1 | grep -E "^CPU" | tail -1 | awk '{ print $3 + $5 }'`,
111-
'Linux' => (int) `top -bn1 | grep -E '^(%Cpu|CPU)' | awk '{ print $2 + $4 }'`,
112-
'Windows' => (int) trim(`wmic cpu get loadpercentage | more +1`),
113-
'BSD' => (int) `top -b -d 2| grep 'CPU: ' | tail -1 | awk '{print$10}' | grep -Eo '[0-9]+\.[0-9]+' | awk '{ print 100 - $1 }'`,
114-
default => throw new RuntimeException('The pulse:check command does not currently support '.PHP_OS_FAMILY),
110+
'Darwin' => (int) shell_exec("top -l 1 | grep -E \"^CPU\" | tail -1 | awk '{ print $3 + $5 }'"),
111+
'Linux' => (int) shell_exec("top -bn1 | grep -E '^(%Cpu|CPU)' | awk '{ print $2 + $4 }'"),
112+
'Windows' => (int) trim(shell_exec("wmic cpu get loadpercentage | more +1")),
113+
'BSD' => (int) shell_exec("top -b -d 2| grep 'CPU: ' | tail -1 | awk '{print$10}' | grep -Eo '[0-9]+\.[0-9]+' | awk '{ print 100 - $1 }'"),
114+
default => throw new RuntimeException('The pulse:check command does not currently support ' . PHP_OS_FAMILY),
115115
};
116116
}
117117

@@ -127,19 +127,19 @@ protected function memory(): array
127127
}
128128

129129
$memoryTotal = match (PHP_OS_FAMILY) {
130-
'Darwin' => intval(`sysctl hw.memsize | grep -Eo '[0-9]+'` / 1024 / 1024),
131-
'Linux' => intval(`cat /proc/meminfo | grep MemTotal | grep -E -o '[0-9]+'` / 1024),
132-
'Windows' => intval(((int) trim(`wmic ComputerSystem get TotalPhysicalMemory | more +1`)) / 1024 / 1024),
133-
'BSD' => intval(`sysctl hw.physmem | grep -Eo '[0-9]+'` / 1024 / 1024),
134-
default => throw new RuntimeException('The pulse:check command does not currently support '.PHP_OS_FAMILY),
130+
'Darwin' => intval(shell_exec("sysctl hw.memsize | grep -Eo '[0-9]+'") / 1024 / 1024),
131+
'Linux' => intval(shell_exec("cat /proc/meminfo | grep MemTotal | grep -E -o '[0-9]+'") / 1024),
132+
'Windows' => intval(((int) trim(shell_exec("wmic ComputerSystem get TotalPhysicalMemory | more +1"))) / 1024 / 1024),
133+
'BSD' => intval(shell_exec("sysctl hw.physmem | grep -Eo '[0-9]+'") / 1024 / 1024),
134+
default => throw new RuntimeException('The pulse:check command does not currently support ' . PHP_OS_FAMILY),
135135
};
136136

137137
$memoryUsed = match (PHP_OS_FAMILY) {
138-
'Darwin' => $memoryTotal - intval(intval(`vm_stat | grep 'Pages free' | grep -Eo '[0-9]+'`) * intval(`pagesize`) / 1024 / 1024), // MB
139-
'Linux' => $memoryTotal - intval(`cat /proc/meminfo | grep MemAvailable | grep -E -o '[0-9]+'` / 1024), // MB
140-
'Windows' => $memoryTotal - intval(((int) trim(`wmic OS get FreePhysicalMemory | more +1`)) / 1024), // MB
141-
'BSD' => intval(intval(`( sysctl vm.stats.vm.v_cache_count | grep -Eo '[0-9]+' ; sysctl vm.stats.vm.v_inactive_count | grep -Eo '[0-9]+' ; sysctl vm.stats.vm.v_active_count | grep -Eo '[0-9]+' ) | awk '{s+=$1} END {print s}'`) * intval(`pagesize`) / 1024 / 1024), // MB
142-
default => throw new RuntimeException('The pulse:check command does not currently support '.PHP_OS_FAMILY),
138+
'Darwin' => $memoryTotal - intval(intval(shell_exec("vm_stat | grep 'Pages free' | grep -Eo '[0-9]+'")) * intval(shell_exec("pagesize")) / 1024 / 1024), // MB
139+
'Linux' => $memoryTotal - intval(shell_exec("cat /proc/meminfo | grep MemAvailable | grep -E -o '[0-9]+'") / 1024), // MB
140+
'Windows' => $memoryTotal - intval(((int) trim(shell_exec("wmic OS get FreePhysicalMemory | more +1"))) / 1024), // MB
141+
'BSD' => intval(intval(shell_exec("( sysctl vm.stats.vm.v_cache_count | grep -Eo '[0-9]+' ; sysctl vm.stats.vm.v_inactive_count | grep -Eo '[0-9]+' ; sysctl vm.stats.vm.v_active_count | grep -Eo '[0-9]+' ) | awk '{s+=$1} END {print s}'")) * intval(shell_exec("pagesize")) / 1024 / 1024), // MB
142+
default => throw new RuntimeException('The pulse:check command does not currently support ' . PHP_OS_FAMILY),
143143
};
144144

145145
return [

0 commit comments

Comments
 (0)