Hi
I think it should be possible to do in another way too (not via filters):
there can be situations when
1) the program should keep as much data as it can (simple example: a roberry had a place and it was noticed only after, say, several weeks)
2) you estimated the place several days of record shoudl consume and adjust a fiter to suit it, but some unexpected heavy traffic had place and your deamons are shutted
So, I suggest it'd be nice if some code's added to zmfilter.pl monitoring for amount of disk space and deleting as much as needed events in case of low disk space(another variable to hold in configure?)
Best regards, Alexander
back to deleting events on low disk space
addon
here's a code that seems to be working (to be inserted into while (1) in zmfilter.pl):
#low disk space part
use constant ZM_DISKLOWLIMIT => 100; #in Mbs
use integer;
my $bindf='/bin/df';
my $partition='/'; #FIXME: to be set elsewhere
my $dfree=0;
my $st=0;
while ($st == 0) {
open (DF,"$bindf $partition |") or die("Can't execute: $bindf\n");
$_=<DF>;$_=<DF>;
my @tab=split /\s+/;
$dfree=$tab[3]/1024;print "space free on $partition: ${dfree}Mb\n" if (VERBOSE);
close(DF);
if ($dfree<ZM_DISKLOWLIMIT) {
my $sql="select Id, MonitorId from Events order by Id limit 1";
my $sth=$dbh->prepare_cached($sql) or die ("Can't prepare '$sql': ".$dbh->errstr());
my $res=$sth->execute() or die("Can't execute: ".$sth->errstr());
my ($event_id,$monitor_id)=$sth->fetchrow_array();if (!defined($event_id)) {
print "warning: low disk space, yet nothing to delete!\n";
$st=1;
} else {
print "id to delete: $event_id (on monitor $monitor_id)\n" if (VERBOSE);
$sth->finish();
$sql="select Name from Monitors where Id = $monitor_id";
$sth=$dbh->prepare_cached($sql) or die ("Can't prepare '$sql': ".$dbh->errstr());
$res=$sth->execute() or die("Can't execute: ".$sth->errstr());
my $row=$sth->fetchrow_hashref();
my $monitor_name=$row->{Name};
$sth->finish();
print "Deleting $event_id due to disk space runnig low\n";
my $cmd="/bin/rm -rf ".EVENT_PATH."/$monitor_name/$event_id";
qx($cmd);
$sql="delete from Events where Id = $event_id";
$sth=$dbh->prepare_cached($sql) or die ("Can't prepare '$sql': ".$dbh->errstr());
$res=$sth->execute() or die("Can't execute: ".$sth->errstr());
$sth->finish();
}
#zmaudit.pl is to clean up datebase stuff
} else {$st=1;}
}
#
#low disk space part
use constant ZM_DISKLOWLIMIT => 100; #in Mbs
use integer;
my $bindf='/bin/df';
my $partition='/'; #FIXME: to be set elsewhere
my $dfree=0;
my $st=0;
while ($st == 0) {
open (DF,"$bindf $partition |") or die("Can't execute: $bindf\n");
$_=<DF>;$_=<DF>;
my @tab=split /\s+/;
$dfree=$tab[3]/1024;print "space free on $partition: ${dfree}Mb\n" if (VERBOSE);
close(DF);
if ($dfree<ZM_DISKLOWLIMIT) {
my $sql="select Id, MonitorId from Events order by Id limit 1";
my $sth=$dbh->prepare_cached($sql) or die ("Can't prepare '$sql': ".$dbh->errstr());
my $res=$sth->execute() or die("Can't execute: ".$sth->errstr());
my ($event_id,$monitor_id)=$sth->fetchrow_array();if (!defined($event_id)) {
print "warning: low disk space, yet nothing to delete!\n";
$st=1;
} else {
print "id to delete: $event_id (on monitor $monitor_id)\n" if (VERBOSE);
$sth->finish();
$sql="select Name from Monitors where Id = $monitor_id";
$sth=$dbh->prepare_cached($sql) or die ("Can't prepare '$sql': ".$dbh->errstr());
$res=$sth->execute() or die("Can't execute: ".$sth->errstr());
my $row=$sth->fetchrow_hashref();
my $monitor_name=$row->{Name};
$sth->finish();
print "Deleting $event_id due to disk space runnig low\n";
my $cmd="/bin/rm -rf ".EVENT_PATH."/$monitor_name/$event_id";
qx($cmd);
$sql="delete from Events where Id = $event_id";
$sth=$dbh->prepare_cached($sql) or die ("Can't prepare '$sql': ".$dbh->errstr());
$res=$sth->execute() or die("Can't execute: ".$sth->errstr());
$sth->finish();
}
#zmaudit.pl is to clean up datebase stuff
} else {$st=1;}
}
#
- zoneminder
- Site Admin
- Posts: 5215
- Joined: Wed Jul 09, 2003 2:07 pm
- Location: Bristol, UK
- Contact:
Re: back to deleting events on low disk space
Hi Borodin,
Thanks for suggesting this. I'll try and put something along these lines into the next release.
Cheers,
Phil
Thanks for suggesting this. I'll try and put something along these lines into the next release.
Cheers,
Phil
Re: back to deleting events on low disk space
Hi Phil,
this is the feature I still missing in current version 1.17.2.
It would be great to possibility of automatically deletion the oldest event (or maybe some time range - x days?) on low disk space.
Best regards,
Pavel
this is the feature I still missing in current version 1.17.2.
It would be great to possibility of automatically deletion the oldest event (or maybe some time range - x days?) on low disk space.
Best regards,
Pavel
- victor_diago
- Posts: 245
- Joined: Wed Jan 21, 2004 2:44 pm
- Location: Brazil, sao paulo
- Contact:
Re: back to deleting events on low disk space
I have made an autoclean.sh script that check (via crond) if the free space of the disk is under X MB and , if it is, it enter the directories and delete all the events of the oldest day, in every monitor...
this should help... i have sent it to the general discussion forum, at the title "new autoclean script for events"
i am using it a lot :)
this should help... i have sent it to the general discussion forum, at the title "new autoclean script for events"
i am using it a lot :)
-
- Posts: 15
- Joined: Wed Mar 17, 2004 7:49 am
- Location: Italy
back to deleting events on low disk space
i test this script.
I add the text in zmfilter.pl but this is the error:
zmfilter.pl
syntax error at /usr/local/bin/zmfilter.pl line 216, near "=;"
syntax error at /usr/local/bin/zmfilter.pl line 216, near "=;"
syntax error at /usr/local/bin/zmfilter.pl line 221, near "$dfree my "
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 221.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 222.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 222.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 230.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 231.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 231.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 240.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 241.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 241.
syntax error at /usr/local/bin/zmfilter.pl line 247, near "} else"
/usr/local/bin/zmfilter.pl has too many errors.
I add the text in zmfilter.pl but this is the error:
zmfilter.pl
syntax error at /usr/local/bin/zmfilter.pl line 216, near "=;"
syntax error at /usr/local/bin/zmfilter.pl line 216, near "=;"
syntax error at /usr/local/bin/zmfilter.pl line 221, near "$dfree my "
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 221.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 222.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 222.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 230.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 231.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 231.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 240.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 241.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 241.
syntax error at /usr/local/bin/zmfilter.pl line 247, near "} else"
/usr/local/bin/zmfilter.pl has too many errors.