diff --git a/misc/munin/wormhole_transit b/misc/munin/wormhole_transit index e7ba14f..d912044 100755 --- a/misc/munin/wormhole_transit +++ b/misc/munin/wormhole_transit @@ -4,10 +4,10 @@ Use the following in /etc/munin/plugin-conf.d/wormhole : [wormhole_*] -env.serverdir /path/to/your/wormhole/server +env.usagedb /path/to/your/wormhole/server/usage.sqlite """ -import os, sys, time, json +import os, sys, time, sqlite3 CONFIG = """\ graph_title Magic-Wormhole Transit Usage (since reboot) @@ -19,15 +19,18 @@ bytes.type GAUGE """ if len(sys.argv) > 1 and sys.argv[1] == "config": - print CONFIG.rstrip() + print(CONFIG.rstrip()) sys.exit(0) -serverdir = os.environ["serverdir"] -fn = os.path.join(serverdir, "stats.json") -with open(fn) as f: - data = json.load(f) -if time.time() > data["valid_until"]: +dbfile = os.environ["usagedb"] +assert os.path.exists(dbfile) +db = sqlite3.connect(dbfile) + +MINUTE = 60.0 +rebooted = db.execute("SELECT `rebooted` FROM `current`").fetchone()[0] +if time.time() > rebooted + 5*MINUTE: sys.exit(1) # expired -t = data["transit"]["since_reboot"] -print "bytes.value", t["bytes"] +value = db.execute("SELECT SUM(`total_bytes`) FROM `usage` WHERE `started` > ?", + (rebooted,)).fetchone()[0] +print("bytes.value", value) diff --git a/misc/munin/wormhole_transit_active b/misc/munin/wormhole_transit_active new file mode 100644 index 0000000..3799f6e --- /dev/null +++ b/misc/munin/wormhole_transit_active @@ -0,0 +1,39 @@ +#! /usr/bin/env python + +""" +Use the following in /etc/munin/plugin-conf.d/wormhole : + +[wormhole_*] +env.usagedb /path/to/your/wormhole/server/usage.sqlite +""" + +import os, sys, time, sqlite3 + +CONFIG = """\ +graph_title Magic-Wormhole Transit Active Channels +graph_vlabel Channels +graph_category network +waiting.label Transit Waiting +waiting.draw LINE1 +waiting.type GAUGE +connected.label Transit Connected +connected.draw LINE1 +connected.type GAUGE +""" + +if len(sys.argv) > 1 and sys.argv[1] == "config": + print(CONFIG.rstrip()) + sys.exit(0) + +dbfile = os.environ["usagedb"] +assert os.path.exists(dbfile) +db = sqlite3.connect(dbfile) + +MINUTE = 60.0 +rebooted,waiting,connected = db.execute("SELECT `rebooted`,`waiting`,`connected`" + " FROM `current`").fetchone() +if time.time() > rebooted + 5*MINUTE: + sys.exit(1) # expired + +print("waiting.value", waiting) +print("connected.value", connected) diff --git a/misc/munin/wormhole_transit_alltime b/misc/munin/wormhole_transit_alltime index 459116b..25cbf4b 100644 --- a/misc/munin/wormhole_transit_alltime +++ b/misc/munin/wormhole_transit_alltime @@ -4,10 +4,10 @@ Use the following in /etc/munin/plugin-conf.d/wormhole : [wormhole_*] -env.serverdir /path/to/your/wormhole/server +env.usagedb /path/to/your/wormhole/server/usage.sqlite """ -import os, sys, time, json +import os, sys, time, sqlite3 CONFIG = """\ graph_title Magic-Wormhole Transit Usage (all time) @@ -19,15 +19,17 @@ bytes.type GAUGE """ if len(sys.argv) > 1 and sys.argv[1] == "config": - print CONFIG.rstrip() + print(CONFIG.rstrip()) sys.exit(0) -serverdir = os.environ["serverdir"] -fn = os.path.join(serverdir, "stats.json") -with open(fn) as f: - data = json.load(f) -if time.time() > data["valid_until"]: +dbfile = os.environ["usagedb"] +assert os.path.exists(dbfile) +db = sqlite3.connect(dbfile) + +MINUTE = 60.0 +rebooted = db.execute("SELECT `rebooted` FROM `current`").fetchone()[0] +if time.time() > rebooted + 5*MINUTE: sys.exit(1) # expired -t = data["transit"]["all_time"] -print "bytes.value", t["bytes"] +value = db.execute("SELECT SUM(`total_bytes`) FROM `usage`").fetchone()[0] +print("bytes.value", value) diff --git a/misc/munin/wormhole_transit_errors b/misc/munin/wormhole_transit_errors new file mode 100644 index 0000000..182ab64 --- /dev/null +++ b/misc/munin/wormhole_transit_errors @@ -0,0 +1,49 @@ +#! /usr/bin/env python + +""" +Use the following in /etc/munin/plugin-conf.d/wormhole : + +[wormhole_*] +env.usagedb /path/to/your/wormhole/server/usage.sqlite +""" + +import os, sys, time, sqlite3 + +CONFIG = """\ +graph_title Magic-Wormhole Transit Server Errors (since reboot) +graph_vlabel Events Since Reboot +graph_category network +errory.label Errory +errory.draw LINE1 +errory.type GAUGE +lonely.label Lonely +lonely.draw LINE1 +lonely.type GAUGE +""" + +if len(sys.argv) > 1 and sys.argv[1] == "config": + print(CONFIG.rstrip()) + sys.exit(0) + +dbfile = os.environ["usagedb"] +assert os.path.exists(dbfile) +db = sqlite3.connect(dbfile) + +MINUTE = 60.0 +rebooted = db.execute("SELECT `rebooted` FROM `current`").fetchone()[0] +if time.time() > rebooted + 5*MINUTE: + sys.exit(1) # expired + +count = db.execute("SELECT COUNT() FROM `usage`" + " WHERE" + " `started` > ? AND" + " `result` = 'errory'", + (rebooted,)).fetchone()[0] +print("errory.value", count) + +count = db.execute("SELECT COUNT() FROM `usage`" + " WHERE" + " `started` > ? AND" + " `result` = 'lonely'", + (rebooted,)).fetchone()[0] +print("lonely.value", count)