use ZoneMinder::Server::CpuLoad rather than Sys:CpuLoad (#2080)

This commit is contained in:
Andrew Bauer 2018-04-17 20:09:41 -05:00 committed by Isaac Connor
parent 118115f035
commit 04cb1f9300
2 changed files with 14 additions and 3 deletions

View File

@ -107,6 +107,17 @@ sub Hostname {
return $_[0]{Hostname};
} # end sub Hostname
sub CpuLoad {
my $output = qx(uptime);
my @sysloads = split ', ', (split ': ', $output)[-1];
if (join(', ',@sysloads) =~ /(\d+\.\d+)\s*,\s+(\d+\.\d+)\s*,\s+(\d+\.\d+)\s*$/) {
return @sysloads;
}
return (undef, undef, undef);
} # end sub CpuLoad
1;
__END__
# Below is stub documentation for your module. You'd better edit it!

View File

@ -156,7 +156,7 @@ my $server_up = connect( CLIENT, $saddr );
if ( ! $server_up ) {
if ( $Config{ZM_SERVER_ID} ) {
use Sys::MemInfo qw(totalmem freemem totalswap freeswap);
use Sys::CpuLoad;
use use ZoneMinder::Server qw(CpuLoad);
if ( ! defined $dbh->do(q{UPDATE Servers SET Status=?,TotalMem=?,FreeMem=?,TotalSwap=?,FreeSwap=? WHERE Id=?}, undef,
'NotRunning', &totalmem, &freemem, &totalswap, &freeswap, $Config{ZM_SERVER_ID} ) ) {
Error("Failed Updating status of Server record to Not RUnning for Id=$Config{ZM_SERVER_ID}" . $dbh->errstr());
@ -237,7 +237,7 @@ use Socket;
use IO::Handle;
use Time::HiRes qw(usleep);
use Sys::MemInfo qw(totalmem freemem totalswap freeswap);
use Sys::CpuLoad;
use use ZoneMinder::Server qw(CpuLoad);
#use Data::Dumper;
# We count 10 of these, so total timeout is this value *10.
@ -302,7 +302,7 @@ sub run {
if ( $Config{ZM_SERVER_ID} ) {
if ( ! ( $secs_count % 60 ) ) {
$dbh = zmDbConnect() if ! $dbh->ping();
my @cpuload = Sys::CpuLoad::load();
my @cpuload = CpuLoad();
dPrint( ZoneMinder::Logger::DEBUG, 'Updating Server record' );
if ( ! defined $dbh->do(q{UPDATE Servers SET Status=?,CpuLoad=?,TotalMem=?,FreeMem=?,TotalSwap=?,FreeSwap=? WHERE Id=?}, undef,
'Running', $cpuload[0], &totalmem, &freemem, &totalswap, &freeswap, $Config{ZM_SERVER_ID} ) ) {