From c3aa82d2919c0bc5ae85b51ca6eb071615b73e9a Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 17 Jun 2018 14:10:21 -0700 Subject: [PATCH] fix munin plugins They were emitting badly-formated output under python3 (the DB fetchone() call returns a length-one tuple, so it needed a [0]). Also, the is-updated check was too impatient: the new server only writes updated output data once every 10 minutes, but the plugins were assuming anything more than 5 minutes old meant the server was dead. --- misc/munin/wormhole_active | 8 ++++---- misc/munin/wormhole_errors | 12 ++++++------ misc/munin/wormhole_event_rate | 7 ++++--- misc/munin/wormhole_events | 8 ++++---- misc/munin/wormhole_events_alltime | 8 ++++---- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/misc/munin/wormhole_active b/misc/munin/wormhole_active index 3f5c207..36ffe5e 100755 --- a/misc/munin/wormhole_active +++ b/misc/munin/wormhole_active @@ -40,12 +40,12 @@ channel_db = sqlite3.connect(channeldbfile) MINUTE = 60.0 updated,rebooted = usage_db.execute("SELECT `updated`,`rebooted` FROM `current`").fetchone() -if time.time() > updated + 5*MINUTE: +if time.time() > updated + 11*MINUTE: sys.exit(1) # expired -nameplates = channel_db.execute("SELECT COUNT() FROM `nameplates`").fetchone() -mailboxes = channel_db.execute("SELECT COUNT() FROM `mailboxes`").fetchone() -messages = channel_db.execute("SELECT COUNT() FROM `messages`").fetchone() +nameplates = channel_db.execute("SELECT COUNT() FROM `nameplates`").fetchone()[0] +mailboxes = channel_db.execute("SELECT COUNT() FROM `mailboxes`").fetchone()[0] +messages = channel_db.execute("SELECT COUNT() FROM `messages`").fetchone()[0] print("nameplates.value", nameplates) print("mailboxes.value", mailboxes) diff --git a/misc/munin/wormhole_errors b/misc/munin/wormhole_errors index 6b72d95..beeb7de 100755 --- a/misc/munin/wormhole_errors +++ b/misc/munin/wormhole_errors @@ -35,17 +35,17 @@ usage_db = sqlite3.connect(usagedbfile) MINUTE = 60.0 updated,rebooted = usage_db.execute("SELECT `updated`,`rebooted` FROM `current`").fetchone() -if time.time() > updated + 5*MINUTE: +if time.time() > updated + 11*MINUTE: sys.exit(1) # expired -r1 = usage_db.execute("SELECT COUNT() FROM `nameplates`").fetchone() +r1 = usage_db.execute("SELECT COUNT() FROM `nameplates`").fetchone()[0] r2 = usage_db.execute("SELECT COUNT() FROM `nameplates`" - " WHERE `result` = `happy`?").fetchone() + " WHERE `result` = 'happy'").fetchone()[0] print("nameplates.value", (r1 - r2)) -r1 = usage_db.execute("SELECT COUNT() FROM `mailboxes`").fetchone() +r1 = usage_db.execute("SELECT COUNT() FROM `mailboxes`").fetchone()[0] r2 = usage_db.execute("SELECT COUNT() FROM `mailboxes`" - " WHERE `result` = `happy`?").fetchone() + " WHERE `result` = 'happy'").fetchone()[0] print("mailboxes.value", (r1 - r2)) r = usage_db.execute("SELECT COUNT() FROM `mailboxes`" - " WHERE `result` = `scary`?").fetchone() + " WHERE `result` = 'scary'").fetchone()[0] print("mailboxes_scary.value", r) diff --git a/misc/munin/wormhole_event_rate b/misc/munin/wormhole_event_rate index d748183..b74ef28 100755 --- a/misc/munin/wormhole_event_rate +++ b/misc/munin/wormhole_event_rate @@ -8,7 +8,8 @@ env.usagedb /path/to/your/wormhole/server/usage.sqlite """ from __future__ import print_function -import os, sys, time, sqlite3, defaultdict +import os, sys, time, sqlite3 +from collections import defaultdict CONFIG = """\ graph_title Magic-Wormhole Server Events @@ -44,13 +45,13 @@ usage_db = sqlite3.connect(usagedbfile) MINUTE = 60.0 updated,rebooted = usage_db.execute("SELECT `updated`,`rebooted` FROM `current`").fetchone() -if time.time() > updated + 5*MINUTE: +if time.time() > updated + 11*MINUTE: sys.exit(1) # expired atm = defaultdict(int) for mood in ["happy", "scary", "lonely", "errory", "pruney", "crowded"]: atm[mood] = usage_db.execute("SELECT COUNT() FROM `mailboxes`" - " WHERE `result` = ?", (mood,)).fetchone() + " WHERE `result` = ?", (mood,)).fetchone()[0] print("happy.value", atm["happy"]) print("incomplete.value", (atm["pruney"] + atm["lonely"])) diff --git a/misc/munin/wormhole_events b/misc/munin/wormhole_events index 5c9b099..e1c4c06 100755 --- a/misc/munin/wormhole_events +++ b/misc/munin/wormhole_events @@ -45,7 +45,7 @@ usage_db = sqlite3.connect(usagedbfile) MINUTE = 60.0 updated,rebooted,blur = usage_db.execute( "SELECT `updated`,`rebooted`,`blur_time` FROM `current`").fetchone() -if time.time() > updated + 5*MINUTE: +if time.time() > updated + 11*MINUTE: sys.exit(1) # expired if blur is not None: rebooted = blur * (rebooted // blur) @@ -60,8 +60,8 @@ if blur is not None: for mood in ["happy", "scary", "lonely", "errory", "pruney", "crowded"]: r = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `started` >= ?" " AND `result` = ?", - (rebooted, mood)).fetchone() - print("%s.value", r) + (rebooted, mood)).fetchone()[0] + print("%s.value" % mood, r) r = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `started` >= ?", - (rebooted,)).fetchone() + (rebooted,)).fetchone()[0] print("total.value", r) diff --git a/misc/munin/wormhole_events_alltime b/misc/munin/wormhole_events_alltime index c2d1d7c..4a56e80 100755 --- a/misc/munin/wormhole_events_alltime +++ b/misc/munin/wormhole_events_alltime @@ -44,12 +44,12 @@ usage_db = sqlite3.connect(usagedbfile) MINUTE = 60.0 updated,rebooted = usage_db.execute("SELECT `updated`,`rebooted` FROM `current`").fetchone() -if time.time() > updated + 5*MINUTE: +if time.time() > updated + 11*MINUTE: sys.exit(1) # expired for mood in ["happy", "scary", "lonely", "errory", "pruney", "crowded"]: r = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `result` = ?", - (mood,)).fetchone() - print("%s.value", r) -r = usage_db.execute("SELECT COUNT() FROM `mailboxes`").fetchone() + (mood,)).fetchone()[0] + print("%s.value" % mood, r) +r = usage_db.execute("SELECT COUNT() FROM `mailboxes`").fetchone()[0] print("total.value", r)