[icinga-checkins] icinga.org: icinga-core/r1.7: core: fix deleting too old check result files #2951

git at icinga.org git at icinga.org
Sun Aug 19 19:44:44 CEST 2012

Module: icinga-core
Branch: r1.7
Commit: e06dadccbeca2925d20de42e49582b9bc270013e
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=e06dadccbeca2925d20de42e49582b9bc270013e

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Sun Aug  5 13:24:55 2012 +0200

core: fix deleting too old check result files #2951

this is a rather common issue - the checkresult dir does not get cleaned
after the core reaps the files, and leaves files there, slowing down the
overall processing.

as the original diff describes, the initial problem are the "write the
checkresult to tmp dir, then move it to checkresult queue, and put a .ok
file there as well, telling the core checkresult reaper that files are
totally fine to be read". on frequent reloads, this will cause a lot of
"not yet finished" checks to stay within the queue, but not having the
.ok file there.

the core algorithm on checking if a file is ok, requires to loop all
files and stat() if the .ok file is there - which is normally a lot of
misses because those old checkresult files won't even be processed
anymore. and who got a manual cronjob cleaning that, when the core
should do?

refs #2951


 Changelog    |    1 +
 base/utils.c |    9 +++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/Changelog b/Changelog
index 6d30476..e02d2ef 100644
--- a/Changelog
+++ b/Changelog
@@ -19,6 +19,7 @@ FIXES
 * core: fix logical bug on icinga.cfg detection on config read #2879 - MF
 * core: fsync() files before fclose() (Andreas Ericsson) #2948 - MF
 * core: remove weird switch() statement when scanning checkresult queue (Andreas Ericsson) #2950 - MF
+* core: fix deleting too old check result files (Andreas Ericsson) #2951 - MF
 * idoutils: fix icinga mysql db creation script grants access to all dbs #2917 - MF
diff --git a/base/utils.c b/base/utils.c
index ed01f1b..5a3fe4e 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -2739,6 +2739,15 @@ int process_check_result_queue(char *dirname) {
 			/* at this point we have a regular file... */
+			/*
+			 * if the file is too old, we delete it
+			 * otherwise we will leave old files there
+			 */
+			if (stat_buf.st_mtime + max_check_result_file_age < time(NULL)) {
+				delete_check_result_file(dirfile->d_name);
+				continue;
+			}
 			/* can we find the associated ok-to-go file ? */
 			dummy = asprintf(&temp_buffer, "%s.ok", file);
 			result = stat(temp_buffer, &ok_stat_buf);

More information about the icinga-checkins mailing list