Module: check_mk
Branch: master
Commit: 47d3e7f87fbcdc1e9e4e502d8e158fd57cbb0213
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=47d3e7f87fbcdc…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Tue Apr 16 14:24:51 2019 +0200
7401 FIX diskstat: Clean up old item states
The diskstat checks now clean up counter information that is outdated
by a factor of 10 or higher compared to the youngest counter, to avoid
growing item state files.
Change-Id: I70d0e5bb891a39e9ca74a31b10e29c8edf4dea18
---
.werks/7401 | 11 +++++++++++
checks/diskstat | 1 +
checks/diskstat.include | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/.werks/7401 b/.werks/7401
new file mode 100644
index 0000000..046fac1
--- /dev/null
+++ b/.werks/7401
@@ -0,0 +1,11 @@
+Title: diskstat: Clean up old item states
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1555417362
+Class: fix
+
+The diskstat checks now clean up counter information that is more
+than ten times older than the youngest one to avoid growing up the item state.
diff --git a/checks/diskstat b/checks/diskstat
index c286c68..0b5bd46 100644
--- a/checks/diskstat
+++ b/checks/diskstat
@@ -114,6 +114,7 @@
# Consideration for debugging purposes:
# Due to check_info['diskstat']['extra_sections']:
["multipath"])
# each info list is prefixed with '<node_name>'.
+@with_unused_counter_removal("diskstat")
def parse_diskstat(info):
timestamp_str, proc_diskstat, name_info = diskstat_extract_name_info(info)
# limit diskstat to first elements before actual parsing
diff --git a/checks/diskstat.include b/checks/diskstat.include
index c6ba358..2d8935c 100644
--- a/checks/diskstat.include
+++ b/checks/diskstat.include
@@ -46,6 +46,42 @@ diskstat_inventory = []
diskstat_diskless_pattern = re.compile("x?[shv]d[a-z]*[0-9]+")
+def with_unused_counter_removal(plugin_name):
+ '''Return decorator to clean up unused counters
+
+ The decorated parse function will clean up all couters for that plugin which are
more
+ than ten times older than the youngest one to avoid growing up the item state.
+ '''
+
+ def is_plugin_counter_with_age(ident, value):
+ if not isinstance(value, tuple):
+ return False
+ if isinstance(ident, tuple):
+ return ident[0] == plugin_name
+ elif hasattr(ident, "startswith"):
+ return ident.startswith('%s.' % plugin_name)
+ return False
+
+ def decorator(parse_function):
+ def wrapped_parse_function(info):
+ this_time = time.time()
+
+ age_counters = [(this_time - value[0], ident)
+ for (ident, value) in get_all_item_states().iteritems()
+ if is_plugin_counter_with_age(ident, value)]
+
+ if age_counters:
+ age_limit = 10 * min(age_counters)[0]
+ counters_to_delete = [ident for (age, ident) in age_counters if age >=
age_limit]
+ clear_item_states_by_full_keys(counters_to_delete)
+
+ return parse_function(info)
+
+ return wrapped_parse_function
+
+ return decorator
+
+
def inventory_diskstat_generic(parsed):
# Skip over on empty data
if not parsed: