From cd43d1fa7a4f7fce1b81efdee2dc49c70595e8a5 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 19 Jul 2016 17:34:01 -0400 Subject: [PATCH 1/2] Rough in Event disk space reporting --- web/includes/Event.php | 3 +++ web/includes/functions.php | 8 +++++++ web/skins/classic/views/events.php | 38 +++++++++++++++++------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/web/includes/Event.php b/web/includes/Event.php index 5ad1c4031..71e61b7c4 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -148,5 +148,8 @@ public function getStreamSrc( $args, $querySep='&' ) { return( $streamSrc ); } // end function getStreamSrc + function DiskSpace() { + return folder_size( $this->Path() ); + } } # end class ?> diff --git a/web/includes/functions.php b/web/includes/functions.php index 2b73160db..cde212563 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -2107,4 +2107,12 @@ function getStreamHTML( $monitor, $scale=100 ) { } } // end function getStreamHTML +function folder_size($dir) { + $size = 0; + foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) { + $size += is_file($each) ? filesize($each) : folderSize($each); + } + return $size; +} // end fucntion folder_size + ?> diff --git a/web/skins/classic/views/events.php b/web/skins/classic/views/events.php index b7d707b22..4085c1a93 100644 --- a/web/skins/classic/views/events.php +++ b/web/skins/classic/views/events.php @@ -30,7 +30,7 @@ if ( !empty($_REQUEST['execute']) ) } $countSql = 'SELECT count(E.Id) AS EventCount FROM Monitors AS M INNER JOIN Events AS E ON (M.Id = E.MonitorId) WHERE'; -$eventsSql = 'SELECT E.Id,E.MonitorId,M.Name AS MonitorName,M.DefaultScale,E.Name,E.Width,E.Height,E.Cause,E.Notes,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived FROM Monitors AS M INNER JOIN Events AS E on (M.Id = E.MonitorId) WHERE'; +$eventsSql = 'SELECT E.*,M.Name AS MonitorName FROM Monitors AS M INNER JOIN Events AS E on (M.Id = E.MonitorId) WHERE'; if ( $user['MonitorIds'] ) { $user_monitor_ids = ' M.Id in ('.$user['MonitorIds'].')'; $countSql .= $user_monitor_ids; @@ -95,8 +95,10 @@ $unarchived = false; $events = array(); foreach ( dbFetchAll( $eventsSql ) as $event ) { - $events[] = $event; - $scale = max( reScale( SCALE_BASE, $event['DefaultScale'], ZM_WEB_DEFAULT_SCALE ), SCALE_BASE ); + $events[] = new Event( $event ); + + # Doesn this code do anything? + $scale = max( reScale( SCALE_BASE, $event->DefaultScale(), ZM_WEB_DEFAULT_SCALE ), SCALE_BASE ); $eventWidth = reScale( $event['Width'], $scale ); $eventHeight = reScale( $event['Height'], $scale ); if ( $maxWidth < $eventWidth ) $maxWidth = $eventWidth; @@ -183,6 +185,7 @@ foreach ( $events as $event ) + DefaultScale(), ZM_WEB_DEFAULT_SCALE ), SCALE_BASE ); ?> - - - - - - - - - - - + Id().$filterQuery.$sortQuery.'&page=1', 'zmEvent', array( 'event', reScale( $event->Width(), $scale ), reScale( $event->Height(), $scale ) ), $event->Id().($event->Archived()?'*':'') ) ?> + Id().$filterQuery.$sortQuery.'&page=1', 'zmEvent', array( 'event', reScale( $event->Width(), $event->DefaultScale(), ZM_WEB_DEFAULT_SCALE ), reScale( $event->Height(), $event->DefaultScale(), ZM_WEB_DEFAULT_SCALE ) ), validHtmlStr($event->Name()).($event->Archived()?'*':'' ) ) ?> + MonitorName() ?> + Id(), 'zmEventDetail', 'eventdetail', validHtmlStr($event->Cause()), canEdit( 'Events' ), 'title="'.htmlspecialchars($event->Notes()).'"' ) ?> + StartTime()) ) ?> + Length() ) ?> + Id(), 'zmFrames', 'frames', $event->Frames() ) ?> + Id(), 'zmFrames', 'frames', $event->AlarmFrames() ) ?> + TotScore() ?> + AvgScore() ?> + Id().'&fid=0', 'zmImage', array( 'image', reScale( $event->Width(), $scale ), reScale( $event->Height(), $scale ) ), $event->MaxScore() ) ?> + DiskSpace() ?> - ' ) ?> + Id().'&fid='.$thumbData['FrameId'], 'zmImage', array( 'image', reScale( $event->Width(), $scale ), reScale( $event->Height(), $scale ) ), ''.$thumbData['FrameId'].'/'.$event->MaxScore().'' ) ?> - disabled="disabled"/> + disabled="disabled"/> Date: Tue, 13 Dec 2016 13:34:56 -0500 Subject: [PATCH 2/2] Add a config entry to turn event disk space on/off --- scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in | 13 +++++++++++++ web/skins/classic/views/events.php | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 063630ed0..1924d3576 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -1550,6 +1550,19 @@ our @options = ( type => $types{string}, category => "web", }, + { + name => 'ZM_WEB_EVENT_DISK_SPACE', + default => '', + description => "Whether to show disk space used by each event.", + help => qqq("Adds another column to the listing of events + showing the disk space used by the event. This will impart a small + overhead as it will call du on the event directory. In practice + this overhead is fairly small but may be noticeable on IO-constrained + systems. + "), + type => $types{string}, + category => "web", + }, { name => "ZM_WEB_RESIZE_CONSOLE", default => "yes", diff --git a/web/skins/classic/views/events.php b/web/skins/classic/views/events.php index 4085c1a93..e090617d0 100644 --- a/web/skins/classic/views/events.php +++ b/web/skins/classic/views/events.php @@ -185,8 +185,10 @@ foreach ( $events as $event ) + @@ -212,8 +214,10 @@ foreach ( $events as $event ) TotScore() ?> AvgScore() ?> Id().'&fid=0', 'zmImage', array( 'image', reScale( $event->Width(), $scale ), reScale( $event->Height(), $scale ) ), $event->MaxScore() ) ?> + DiskSpace() ?>