Change grep to match at beginning of line. The grep can show in the process list and so give us a broken result. Add debugging when we don't get a value.

pull/3779/head
Isaac Connor 2023-10-23 17:05:15 -04:00
parent ab979c8f42
commit 7596cdcde3
1 changed files with 6 additions and 1 deletions

View File

@ -61,9 +61,14 @@ while (!$zm_terminate) {
}
# Get CPU utilization percentages
my ($user_utilization, $system_utilization) = split(/ /, `top -b -n 1 | grep "Cpu(s)" | awk '{print \$2, \$4}'`);
my $top_output = `top -b -n 1 | grep "^%Cpu(s)" | awk '{print \$2, \$4}'`;
my ($user_utilization, $system_utilization) = split(/ /, $top_output);
$user_utilization =~ s/[^\d\.]//g;
$system_utilization =~ s/[^\d\.]//g;
if (!$user_utilization) {
Warning("Failed getting user_utilization from $top_output");
$user_utilization = 0;
}
zmDbDo('INSERT INTO Server_Stats (ServerId, TimeStamp, CpuLoad, CpuUserPercent, CpuSystemPercent, TotalMem, FreeMem, TotalSwap, FreeSwap) VALUES (?,NOW(),?,?,?,?,?,?,?)',
$Config{ZM_SERVER_ID},