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.
parent
ab979c8f42
commit
7596cdcde3
|
@ -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},
|
||||
|
|
Loading…
Reference in New Issue