Skip to content

Commit

Permalink
fix munin plugins
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
warner committed Jun 17, 2018
1 parent 32f2760 commit c3aa82d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
8 changes: 4 additions & 4 deletions misc/munin/wormhole_active
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions misc/munin/wormhole_errors
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 4 additions & 3 deletions misc/munin/wormhole_event_rate
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]))
Expand Down
8 changes: 4 additions & 4 deletions misc/munin/wormhole_events
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
8 changes: 4 additions & 4 deletions misc/munin/wormhole_events_alltime
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit c3aa82d

Please sign in to comment.