2017-11-09 21:23:46 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
Use the following in /etc/munin/plugin-conf.d/wormhole :
|
|
|
|
|
|
|
|
[wormhole_*]
|
|
|
|
env.usagedb /path/to/your/wormhole/server/usage.sqlite
|
|
|
|
"""
|
|
|
|
|
2017-11-10 06:11:34 +00:00
|
|
|
from __future__ import print_function
|
2017-11-09 21:23:46 +00:00
|
|
|
import os, sys, time, sqlite3
|
|
|
|
|
|
|
|
CONFIG = """\
|
2018-02-13 01:04:45 +00:00
|
|
|
graph_title Magic-Wormhole Transit Server Events (since reboot)
|
2017-11-09 21:23:46 +00:00
|
|
|
graph_vlabel Events Since Reboot
|
2018-03-28 21:14:31 +00:00
|
|
|
graph_category wormhole
|
2018-02-13 01:04:45 +00:00
|
|
|
happy.label Happy
|
|
|
|
happy.draw LINE1
|
|
|
|
happy.type GAUGE
|
2017-11-09 21:23:46 +00:00
|
|
|
errory.label Errory
|
|
|
|
errory.draw LINE1
|
|
|
|
errory.type GAUGE
|
|
|
|
lonely.label Lonely
|
|
|
|
lonely.draw LINE1
|
|
|
|
lonely.type GAUGE
|
2018-02-13 01:04:45 +00:00
|
|
|
redundant.label Redundant
|
|
|
|
redundant.draw LINE1
|
|
|
|
redundant.type GAUGE
|
2017-11-09 21:23:46 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
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
|
2017-11-10 06:09:27 +00:00
|
|
|
rebooted,updated = db.execute("SELECT `rebooted`, `updated` FROM `current`").fetchone()
|
|
|
|
if time.time() > updated + 5*MINUTE:
|
2017-11-09 21:23:46 +00:00
|
|
|
sys.exit(1) # expired
|
|
|
|
|
2018-02-13 01:04:45 +00:00
|
|
|
count = db.execute("SELECT COUNT() FROM `usage`"
|
|
|
|
" WHERE"
|
|
|
|
" `started` > ? AND"
|
|
|
|
" `result` = 'happy'",
|
|
|
|
(rebooted,)).fetchone()[0]
|
|
|
|
print("happy.value", count)
|
|
|
|
|
2017-11-09 21:23:46 +00:00
|
|
|
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)
|
2018-02-13 01:04:45 +00:00
|
|
|
|
|
|
|
count = db.execute("SELECT COUNT() FROM `usage`"
|
|
|
|
" WHERE"
|
|
|
|
" `started` > ? AND"
|
|
|
|
" `result` = 'redundant'",
|
|
|
|
(rebooted,)).fetchone()[0]
|
|
|
|
print("redundant.value", count)
|