Add CpuUserPercent and CpuSystemPercent to ServerStats

pull/3669/head
Isaac Connor 2023-03-01 14:08:09 -05:00
parent fa9a0e45b7
commit e08ec34e51
1 changed files with 9 additions and 2 deletions

View File

@ -59,8 +59,15 @@ while (!$zm_terminate) {
'Running', $cpuload[0], &totalmem, &freemem, &totalswap, &freeswap, $Config{ZM_SERVER_ID} ) ) {
Error("Failed Updating status of Server record for Id=$Config{ZM_SERVER_ID} :".$dbh->errstr());
}
if ( ! defined $dbh->do('INSERT INTO Server_Stats (ServerId, TimeStamp, CpuLoad, TotalMem, FreeMem, TotalSwap, FreeSwap) VALUES (?,NOW(),?,?,?,?,?)', undef,
$Config{ZM_SERVER_ID}, $cpuload[0], &totalmem, &freemem, &totalswap, &freeswap, $Config{ZM_SERVER_ID} ) ) {
# Get CPU utilization percentages
my ($user_utilization, $system_utilization) = split(/ /, `top -b -n 1 | grep "Cpu(s)" | awk '{print \$2, \$4}'`);
if ( ! defined $dbh->do('INSERT INTO Server_Stats (ServerId, TimeStamp, CpuLoad, CpuUserPercent, CpuSystemPercent, TotalMem, FreeMem, TotalSwap, FreeSwap) VALUES (?,NOW(),?,?,?,?,?,?,?)', undef,
$Config{ZM_SERVER_ID},
$cpuload[0], $user_utilization, $system_utilization,
&totalmem, &freemem, &totalswap, &freeswap, ) ) {
Error("Failed Inserting status of Server record for Id=$Config{ZM_SERVER_ID} :".$dbh->errstr());
}
my $rows = zmDbDo('DELETE FROM `Server_Stats` WHERE `TimeStamp` < now() - interval 1 DAY LIMIT 100');