From 8dcc91493811196735d4b734e069b817d9b0f32e Mon Sep 17 00:00:00 2001 From: Andreas Perhab Date: Mon, 30 May 2022 10:24:21 +0200 Subject: [PATCH] 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. --- plugins/disk/du-2 | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/plugins/disk/du-2 b/plugins/disk/du-2 index e2689a5b..f76ab778 100755 --- a/plugins/disk/du-2 +++ b/plugins/disk/du-2 @@ -8,6 +8,7 @@ =head1 AUTHOR AND COPYRIGHT Copyright 2011-2014 Luc Didry + Copyright 2022 Andreas Perhab, WT-IO-IT GmbH =head1 HOWTO CONFIGURE AND USE : @@ -160,15 +161,21 @@ sub cache_is_too_old { sub du_not_running { if (-e $LOCKFILE) { - my ($time) = `cat $TIMEFILE`; - chomp $time; - if ( (time - $time) > ($ENV{interval}*60*60) ) { - # The cache is really old (60xinterval) => Maybe the lockfile wasn't properly deleted. - # Let's delete it. - system("rm $LOCKFILE;"); - return 1; + if (-e $TIMEFILE) { + my ($time) = `cat $TIMEFILE`; + chomp $time; + if ( (time - $time) > ($ENV{interval}*60*60) ) { + # The cache is really old (60xinterval) => Maybe the lockfile wasn't properly deleted. + # Let's delete it. + unlink($LOCKFILE); + return 1; + } else { + return 0; + } } 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 { return 1;