Don't calc DiskSpace if it is already defined
This commit is contained in:
parent
9d6b417b60
commit
485567349d
|
@ -79,7 +79,8 @@ my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=?' : 'S
|
|||
my $sth = $dbh->prepare_cached( $sql )
|
||||
or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
|
||||
my $eventcounts_sql = q`UPDATE Monitors SET
|
||||
my $eventcounts_sql = q`
|
||||
UPDATE Monitors SET
|
||||
TotalEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id),
|
||||
TotalEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND DiskSpace IS NOT NULL),
|
||||
HourEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB( NOW(), INTERVAL 1 hour) ),
|
||||
|
@ -97,10 +98,10 @@ TotalEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id),
|
|||
my $eventcounts_sth = $dbh->prepare_cached( $eventcounts_sql );
|
||||
|
||||
while( 1 ) {
|
||||
my $now = time();
|
||||
my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID} : () )
|
||||
or Fatal( "Can't execute: ".$sth->errstr() );
|
||||
while( my $monitor = $sth->fetchrow_hashref() ) {
|
||||
my $now = time();
|
||||
next if $monitor->{Function} eq 'None';
|
||||
my $restart = 0;
|
||||
if ( zmMemVerify( $monitor ) ) {
|
||||
|
@ -192,6 +193,8 @@ while( 1 ) {
|
|||
} # end if check analysis daemon
|
||||
# Prevent open handles building up if we have connect to shared memory
|
||||
zmMemInvalidate( $monitor ); # Close our file handle to the zmc process we are about to end
|
||||
|
||||
|
||||
$eventcounts_sth->execute( $$monitor{Id} ) or Error( "Can't execute: ".$eventcounts_sth->errstr() );
|
||||
|
||||
} # end foreach monitor
|
||||
|
@ -199,10 +202,12 @@ while( 1 ) {
|
|||
|
||||
my $diskspace_sql = 'UPDATE Storage SET DiskSpace =(SELECT SUM(DiskSpace) FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL)';
|
||||
my $diskspace_sth = $dbh->prepare_cached( $diskspace_sql )
|
||||
or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
or Fatal( "Can't prepare '$diskspace_sql': ".$dbh->errstr() );
|
||||
foreach my $Storage ( ZoneMinder::Storage->find() ) {
|
||||
Error("Updating disk space for $$Storage{Name}");
|
||||
Debug("Updating disk space for $$Storage{Name} was $$Storage{DiskSpace}");
|
||||
$diskspace_sth->execute( $$Storage{Id} ) or Error( "Can't execute: ".$diskspace_sth->errstr() );
|
||||
$Storage->load();
|
||||
Debug("Updated disk space for $$Storage{Name} to $$Storage{DiskSpace}");
|
||||
}
|
||||
$diskspace_sth->finish();
|
||||
sleep( $Config{ZM_WATCH_CHECK_INTERVAL} );
|
||||
|
|
|
@ -110,8 +110,9 @@ class Storage {
|
|||
}
|
||||
public function disk_used_space() {
|
||||
# This isn't a function like this in php, so we have to add up the space used in each event.
|
||||
if ( ! array_key_exists( 'disk_used_space', $this ) ) {
|
||||
$used = 0;
|
||||
if ( ! array_key_exists( 'DiskSpace', $this ) ) {
|
||||
$used = $this->{'DiskSpace'};
|
||||
if ( ! $used ) {
|
||||
if ( $this->{'Type'} == 's3fs' ) {
|
||||
$used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()) );
|
||||
|
||||
|
@ -123,10 +124,11 @@ class Storage {
|
|||
$path = $this->Path();
|
||||
$used = disk_total_space( $path ) - disk_free_space( $path );;
|
||||
}
|
||||
$this->{'disk_used_space'} = $used;
|
||||
} # end if
|
||||
$this->{'DiskSpace'} = $used;
|
||||
}
|
||||
|
||||
return $this->{'disk_used_space'};
|
||||
return $this->{'DiskSpace'};
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue