Fix "top" command parsing on FreeBSD (tested in FreeBSD 13.5 jail, running 1.38.1).

This commit is contained in:
Daniel Caujolle-Bert
2026-04-08 15:28:41 +02:00
parent 6882619c9c
commit 7a39b2d750

View File

@@ -24,6 +24,7 @@ package ZoneMinder::Server;
use 5.006;
use strict;
use warnings;
use Config;
require ZoneMinder::Base;
require ZoneMinder::Config;
@@ -127,7 +128,13 @@ sub CpuUsage {
} else {
# Get CPU utilization percentages
my $top_output = `top -b -n 1 | grep -i "^%Cpu(s)" | awk '{print \$2, \$4, \$6, \$8}'`;
my $top_output = '';
## FreeBSD
if (@Config{qw(uname)} == 'freebsd') {
$top_output = `top -b -n 1 | grep "^CPU" | sed 's/%//g' | awk '{print \$2, \$6, \$4, \$10}'`;
} else {
$top_output = `top -b -n 1 | grep -i "^%Cpu(s)" | awk '{print \$2, \$4, \$6, \$8}'`;
}
my ($user, $system, $nice, $idle) = split(/ /, $top_output);
$user =~ s/[^\d\.]//g;
$system =~ s/[^\d\.]//g;