2017-09-13 06:46:56 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
Use the following in /etc/munin/plugin-conf.d/wormhole :
|
|
|
|
|
|
|
|
[wormhole_*]
|
2017-11-09 21:23:46 +00:00
|
|
|
env.usagedb /path/to/your/wormhole/server/usage.sqlite
|
2017-09-13 06:46:56 +00:00
|
|
|
"""
|
|
|
|
|
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
|
2017-09-13 06:46:56 +00:00
|
|
|
|
|
|
|
CONFIG = """\
|
|
|
|
graph_title Magic-Wormhole Transit Usage (all time)
|
|
|
|
graph_vlabel Bytes Since DB Creation
|
2018-03-28 21:14:31 +00:00
|
|
|
graph_category wormhole
|
2018-02-19 19:23:05 +00:00
|
|
|
bytes.label Transit Bytes (complete)
|
2017-09-13 06:46:56 +00:00
|
|
|
bytes.draw LINE1
|
|
|
|
bytes.type GAUGE
|
2018-02-19 19:23:05 +00:00
|
|
|
incomplete.label Transit Bytes (incomplete)
|
|
|
|
incomplete.draw LINE1
|
|
|
|
incomplete.type GAUGE
|
2017-09-13 06:46:56 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "config":
|
2017-11-09 21:23:46 +00:00
|
|
|
print(CONFIG.rstrip())
|
2017-09-13 06:46:56 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
2017-11-09 21:23:46 +00:00
|
|
|
dbfile = os.environ["usagedb"]
|
|
|
|
assert os.path.exists(dbfile)
|
|
|
|
db = sqlite3.connect(dbfile)
|
|
|
|
|
|
|
|
MINUTE = 60.0
|
2018-02-19 19:23:05 +00:00
|
|
|
updated,incomplete = db.execute("SELECT `updated`,`incomplete_bytes`"
|
|
|
|
" FROM `current`").fetchone()
|
2017-11-10 06:09:27 +00:00
|
|
|
if time.time() > updated + 5*MINUTE:
|
2017-09-13 06:46:56 +00:00
|
|
|
sys.exit(1) # expired
|
|
|
|
|
2018-02-19 19:23:05 +00:00
|
|
|
complete = db.execute("SELECT SUM(`total_bytes`)"
|
|
|
|
" FROM `usage`").fetchone()[0] or 0
|
|
|
|
print("bytes.value", complete)
|
|
|
|
print("incomplete.value", complete+incomplete)
|