1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

du-2: fix resource consumption when first running the plugin

when installing / first running the plugin, it can take longer than
one munin-update call to create the $TIMEFILE. so until it is created
we assume the $LOCKFILE is not too old yet and let the first run finish
before we spawn additional processes.
This commit is contained in:
Andreas Perhab 2022-05-30 10:24:21 +02:00 committed by Lars Kruse
parent a620b1a507
commit 8dcc914938

View file

@ -8,6 +8,7 @@
=head1 AUTHOR AND COPYRIGHT =head1 AUTHOR AND COPYRIGHT
Copyright 2011-2014 Luc Didry <luc AT didry.org> Copyright 2011-2014 Luc Didry <luc AT didry.org>
Copyright 2022 Andreas Perhab, WT-IO-IT GmbH <a.perhab@wtioit.at>
=head1 HOWTO CONFIGURE AND USE : =head1 HOWTO CONFIGURE AND USE :
@ -160,15 +161,21 @@ sub cache_is_too_old {
sub du_not_running { sub du_not_running {
if (-e $LOCKFILE) { if (-e $LOCKFILE) {
my ($time) = `cat $TIMEFILE`; if (-e $TIMEFILE) {
chomp $time; my ($time) = `cat $TIMEFILE`;
if ( (time - $time) > ($ENV{interval}*60*60) ) { chomp $time;
# The cache is really old (60xinterval) => Maybe the lockfile wasn't properly deleted. if ( (time - $time) > ($ENV{interval}*60*60) ) {
# Let's delete it. # The cache is really old (60xinterval) => Maybe the lockfile wasn't properly deleted.
system("rm $LOCKFILE;"); # Let's delete it.
return 1; unlink($LOCKFILE);
return 1;
} else {
return 0;
}
} else { } else {
return 0; # when $TIMEFILE is not yet created (first run is not yet finished), $LOCKFILE is honoured
# to prevent spawning multiple resource intensive processes
return 0;
} }
} else { } else {
return 1; return 1;