Module: check_mk
Branch: master
Commit: 623d68297097be2df33fb436978971d5ac8ea41c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=623d68297097be…
Author: Florian Kromer <fk(a)mathias-kettner.de>
Date: Fri Apr 26 14:48:45 2019 +0200
postgres_stats: refactoring 5
Change-Id: Ie321efc4fb4552ddc6c7855ad793a2c145e8eeab
---
checks/postgres_stats | 10 ++++++---
.../checks/generictests/datasets/postgres_stats.py | 24 ++++++++++++++--------
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/checks/postgres_stats b/checks/postgres_stats
index 4382522..b4903b2 100644
--- a/checks/postgres_stats
+++ b/checks/postgres_stats
@@ -36,6 +36,10 @@
# postgres;pg_catalog;pg_authid;-1;-1
# postgres;pg_catalog;pg_attribute;-1;-1
+factory_settings["postgres_stats_default_levels"] = {
+ "never_analyze_vacuum": (0, float('inf')),
+}
+
def inventory_postgres_stats(parsed):
for db in parsed:
@@ -53,8 +57,7 @@ def _check_never_checked(item, text, never_checked, params, now):
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
+ yield 0, infotext
last_ts = get_item_state(key)
if last_ts is None:
@@ -63,7 +66,7 @@ def _check_never_checked(item, text, never_checked, params, now):
yield check_levels(
now - last_ts,
None,
- levels,
+ params.get("never_analyze_vacuum"),
human_readable_func=get_age_human_readable,
infoname='Unhandled tables for',
)
@@ -122,5 +125,6 @@ check_info['postgres_stats'] = {
"inventory_function": inventory_postgres_stats,
"service_description": "PostgreSQL %s",
"group": "postgres_maintenance",
+ "default_levels_variable": "postgres_stats_default_levels",
"includes": ["postgres.include"],
}
diff --git a/tests/unit/checks/generictests/datasets/postgres_stats.py
b/tests/unit/checks/generictests/datasets/postgres_stats.py
index 647eed2..0367d79 100644
--- a/tests/unit/checks/generictests/datasets/postgres_stats.py
+++ b/tests/unit/checks/generictests/datasets/postgres_stats.py
@@ -35,26 +35,32 @@ checks = {
'': [
(u'ANALYZE adwebconnect', {'never_analyze_vacuum': (1000, 1100)},
[
(0, u'Table: auftrag', []),
- (0, 'Time since last vacuum: 674 d', []),
- (0, '2 tables were never analyzed: anrede/auftrag_mediadaten', []),
+ (0, u'Time since last vacuum: 674 d', []),
+ (0, u'2 tables were never analyzed: anrede/auftrag_mediadaten', []),
(2, u'Unhandled tables for: 20 m (warn/crit at 16 m/18 m)', []),
]),
- (u'ANALYZE adwebconnect', {}, [
+ (u'ANALYZE adwebconnect', {"never_analyze_vacuum": (0,
float('inf'))}, [
(0, u'Table: auftrag', []),
- (0, 'Time since last vacuum: 674 d', []),
- (1, u'2 tables were never analyzed: anrede/auftrag_mediadaten', []),
+ (0, u'Time since last vacuum: 674 d', []),
+ (0, u'2 tables were never analyzed: anrede/auftrag_mediadaten', []),
+ (1, u'Unhandled tables for: 20 m (warn/crit at 0.00 s/inf y)', []),
+ ]),
+ (u'ANALYZE adwebconnect', {'never_analyze_vacuum': None}, [
+ (0, u'Table: auftrag', []),
+ (0, u'Time since last vacuum: 674 d', []),
+ (0, u'2 tables were never analyzed: anrede/auftrag_mediadaten', []),
(0, u'Unhandled tables for: 20 m', []),
]),
(u'ANALYZE postgres', {}, [
- (0, 'No never checked tables', []),
+ (0, u'No never checked tables', []),
]),
(u'VACUUM adwebconnect', {}, [
(0, u'Table: auftrag', []),
- (0, 'Time since last vacuum: 674 d', []),
- (1, '2 tables were never vacuumed: anrede/auftrag_mediadaten', []),
+ (0, u'Time since last vacuum: 674 d', []),
+ (0, u'2 tables were never vacuumed: anrede/auftrag_mediadaten', []),
(0, u'Unhandled tables for: 20 m', []),
]),
(u'VACUUM postgres', {}, [
- (0, 'No never checked tables', []),
+ (0, u'No never checked tables', []),
]),
]}