36 lines
		
	
	
		
			820 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			820 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#! /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 Usage (all time)
 | 
						|
graph_vlabel Bytes Since DB Creation
 | 
						|
graph_category network
 | 
						|
bytes.label Transit Bytes
 | 
						|
bytes.draw LINE1
 | 
						|
bytes.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
 | 
						|
 | 
						|
value = db.execute("SELECT SUM(`total_bytes`) FROM `usage`").fetchone()[0]
 | 
						|
print("bytes.value", value)
 |