magic-wormhole/misc/munin/wormhole_transit

34 lines
715 B
Plaintext
Raw Normal View History

2016-05-27 00:46:16 +00:00
#! /usr/bin/env python
"""
Use the following in /etc/munin/plugin-conf.d/wormhole :
[wormhole_*]
env.serverdir /path/to/your/wormhole/server
"""
2016-06-27 00:15:31 +00:00
import os, sys, time, json
2016-05-27 00:46:16 +00:00
CONFIG = """\
graph_title Magic-Wormhole Transit Usage (since reboot)
2016-06-27 00:15:31 +00:00
graph_vlabel Bytes Since Reboot
2016-05-27 00:46:16 +00:00
graph_category network
2016-05-27 01:04:52 +00:00
bytes.label Transit Bytes
bytes.draw LINE1
2016-06-27 00:15:31 +00:00
bytes.type GAUGE
2016-05-27 00:46:16 +00:00
"""
if len(sys.argv) > 1 and sys.argv[1] == "config":
print CONFIG.rstrip()
sys.exit(0)
2016-06-27 00:15:31 +00:00
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"]:
sys.exit(1) # expired
t = data["transit"]["since_reboot"]
print "bytes.value", t["bytes"]