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 = """\
|
|
|
|
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
|
2017-11-10 06:09:27 +00:00
|
|
|
updated,waiting,connected = db.execute("SELECT `updated`,`waiting`,`connected`"
|
|
|
|
" FROM `current`").fetchone()
|
|
|
|
if time.time() > updated + 5*MINUTE:
|
2017-11-09 21:23:46 +00:00
|
|
|
sys.exit(1) # expired
|
|
|
|
|
|
|
|
print("waiting.value", waiting)
|
|
|
|
print("connected.value", connected)
|