Module: check_mk
Branch: master
Commit: 71eb19e36d41589559a2def415cd7419baa19ecc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=71eb19e36d4158…
Author: Florian Kromer <fk(a)mathias-kettner.de>
Date: Fri Apr 26 11:26:00 2019 +0200
postgres_stats: refactoring 4
Change-Id: Id4c27bff9d1371dbccf82ef68ad50777b725e8a7
---
checks/postgres_stats | 54 +++++++++++++++++++++++++++------------------------
1 file changed, 29 insertions(+), 25 deletions(-)
diff --git a/checks/postgres_stats b/checks/postgres_stats
index 9104f85..4382522 100644
--- a/checks/postgres_stats
+++ b/checks/postgres_stats
@@ -43,6 +43,32 @@ def inventory_postgres_stats(parsed):
yield "ANALYZE %s" % db, {}
+def _check_never_checked(item, text, never_checked, params, now):
+ key = "postgres_stats.%s" % item
+ if not never_checked:
+ set_item_state(key, now)
+ yield 0, "No never checked tables"
+ return
+
+ count = len(never_checked)
+ infotext = "%d tables were never %s: %s%s" % (count, text,
"/".join(never_checked[:5]),
+ " (first 5 shown)" if count
> 5 else "")
+ levels = params.get("never_analyze_vacuum")
+ yield int(levels is None), infotext
+
+ last_ts = get_item_state(key)
+ if last_ts is None:
+ set_item_state(key, now)
+ return
+ yield check_levels(
+ now - last_ts,
+ None,
+ levels,
+ human_readable_func=get_age_human_readable,
+ infoname='Unhandled tables for',
+ )
+
+
def check_postgres_stats(item, params, parsed):
item_type, database = item.split(" ", 1)
@@ -78,7 +104,7 @@ def check_postgres_stats(item, params, parsed):
now = time.time()
if oldest_element:
yield 0, "Table: %s" % oldest_element["tname"]
- oldest_age = time.time() - int(oldest_element[stats_field])
+ oldest_age = now - int(oldest_element[stats_field])
yield check_levels(
oldest_age,
None,
@@ -86,30 +112,8 @@ def check_postgres_stats(item, params, parsed):
human_readable_func=get_age_human_readable,
infoname='Time since last vacuum')
- key = "postgres_stats.%s" % item
- if not never_checked:
- set_item_state(key, now)
- yield 0, "No never checked tables"
- return
-
- count = len(never_checked)
- levels = params.get("never_analyze_vacuum")
- infotext = "%d tables were never %s: %s%s" % (count, text,
"/".join(never_checked[:5]),
- " (first 5 shown)" if count
> 5 else "")
-
- yield int(levels is None), infotext
-
- last_ts = get_item_state(key)
- if last_ts is None:
- set_item_state(key, now)
- return
- yield check_levels(
- now - last_ts,
- None,
- levels,
- human_readable_func=get_age_human_readable,
- infoname='Unhandled tables for',
- )
+ for subresult in _check_never_checked(item, text, never_checked, params, now):
+ yield subresult
check_info['postgres_stats'] = {