update munin plugins to work with usage-db, add new ones

This commit is contained in:
Brian Warner 2017-11-09 13:23:46 -08:00
parent 17e232de50
commit 9008d4339a
4 changed files with 113 additions and 20 deletions

View File

@ -4,10 +4,10 @@
Use the following in /etc/munin/plugin-conf.d/wormhole : Use the following in /etc/munin/plugin-conf.d/wormhole :
[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 = """\ CONFIG = """\
graph_title Magic-Wormhole Transit Usage (since reboot) 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": if len(sys.argv) > 1 and sys.argv[1] == "config":
print CONFIG.rstrip() print(CONFIG.rstrip())
sys.exit(0) sys.exit(0)
serverdir = os.environ["serverdir"] dbfile = os.environ["usagedb"]
fn = os.path.join(serverdir, "stats.json") assert os.path.exists(dbfile)
with open(fn) as f: db = sqlite3.connect(dbfile)
data = json.load(f)
if time.time() > data["valid_until"]: MINUTE = 60.0
rebooted = db.execute("SELECT `rebooted` FROM `current`").fetchone()[0]
if time.time() > rebooted + 5*MINUTE:
sys.exit(1) # expired sys.exit(1) # expired
t = data["transit"]["since_reboot"] value = db.execute("SELECT SUM(`total_bytes`) FROM `usage` WHERE `started` > ?",
print "bytes.value", t["bytes"] (rebooted,)).fetchone()[0]
print("bytes.value", value)

View File

@ -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)

View File

@ -4,10 +4,10 @@
Use the following in /etc/munin/plugin-conf.d/wormhole : Use the following in /etc/munin/plugin-conf.d/wormhole :
[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 = """\ CONFIG = """\
graph_title Magic-Wormhole Transit Usage (all time) 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": if len(sys.argv) > 1 and sys.argv[1] == "config":
print CONFIG.rstrip() print(CONFIG.rstrip())
sys.exit(0) sys.exit(0)
serverdir = os.environ["serverdir"] dbfile = os.environ["usagedb"]
fn = os.path.join(serverdir, "stats.json") assert os.path.exists(dbfile)
with open(fn) as f: db = sqlite3.connect(dbfile)
data = json.load(f)
if time.time() > data["valid_until"]: MINUTE = 60.0
rebooted = db.execute("SELECT `rebooted` FROM `current`").fetchone()[0]
if time.time() > rebooted + 5*MINUTE:
sys.exit(1) # expired sys.exit(1) # expired
t = data["transit"]["all_time"] value = db.execute("SELECT SUM(`total_bytes`) FROM `usage`").fetchone()[0]
print "bytes.value", t["bytes"] print("bytes.value", value)

View File

@ -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)