#! /usr/bin/env python """ Use the following in /etc/munin/plugin-conf.d/wormhole : [wormhole_*] env.usagedb /path/to/your/wormhole/server/usage.sqlite """ from __future__ import print_function import os, sys, time, sqlite3 CONFIG = """\ graph_title Magic-Wormhole Mailbox Events (since reboot) graph_vlabel Events Since Reboot graph_category wormhole happy.label Happy happy.draw LINE2 happy.type GAUGE total.label Total total.draw LINE1 total.type GAUGE scary.label Scary scary.draw LINE2 scary.type GAUGE pruney.label Pruney pruney.draw LINE1 pruney.type GAUGE lonely.label Lonely lonely.draw LINE2 lonely.type GAUGE errory.label Errory errory.draw LINE1 errory.type GAUGE """ if len(sys.argv) > 1 and sys.argv[1] == "config": print(CONFIG.rstrip()) sys.exit(0) usagedbfile = os.environ["usagedb"] assert os.path.exists(usagedbfile) 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 + 6*MINUTE: sys.exit(1) # expired if blur is not None: rebooted = blur * (rebooted // blur) # After a reboot, the operator will get to see events that happen during # the first blur window (without this adjustment, those events would be # hidden since they'd appear to start before the reboot). The downside is # that the counter won't drop down to zero at a reboot (if there are recent # events). #r = usage_db.execute("SELECT COUNT(`mood`) FROM `mailboxes` WHERE `started` > ?", # (rebooted,)).fetchone() for mood in ["happy", "scary", "lonely", "errory", "pruney", "crowded"]: r = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `started` >= ?" " AND `result` = ?", (rebooted, mood)).fetchone()[0] print("%s.value" % mood, r) r = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `started` >= ?", (rebooted,)).fetchone()[0] print("total.value", r)