Skip to content

Commit

Permalink
Add BSD to Servers Recorder (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-hortelan authored Jan 15, 2024
1 parent 10a2697 commit 4d27cbb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Recorders/Servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,23 @@ public function record(SharedBeat $event): void
'Darwin' => intval(`sysctl hw.memsize | grep -Eo '[0-9]+'` / 1024 / 1024),
'Linux' => intval(`cat /proc/meminfo | grep MemTotal | grep -E -o '[0-9]+'` / 1024),
'Windows' => intval(((int) trim(`wmic ComputerSystem get TotalPhysicalMemory | more +1`)) / 1024 / 1024),
'BSD' => intval(`sysctl hw.physmem | grep -Eo '[0-9]+'` / 1024 / 1024),
default => throw new RuntimeException('The pulse:check command does not currently support '.PHP_OS_FAMILY),
};

$memoryUsed = match (PHP_OS_FAMILY) {
'Darwin' => $memoryTotal - intval(intval(`vm_stat | grep 'Pages free' | grep -Eo '[0-9]+'`) * intval(`pagesize`) / 1024 / 1024), // MB
'Linux' => $memoryTotal - intval(`cat /proc/meminfo | grep MemAvailable | grep -E -o '[0-9]+'` / 1024), // MB
'Windows' => $memoryTotal - intval(((int) trim(`wmic OS get FreePhysicalMemory | more +1`)) / 1024), // MB
'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
default => throw new RuntimeException('The pulse:check command does not currently support '.PHP_OS_FAMILY),
};

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

Expand Down

0 comments on commit 4d27cbb

Please sign in to comment.