magic-wormhole-transit-relay/misc/munin/wormhole_transit_errors

50 lines
1.2 KiB
Plaintext
Raw Normal View History

#! /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)