| 1 |
#! /usr/bin/env python |
| 2 |
|
| 3 |
""" |
| 4 |
Use the following in /etc/munin/plugin-conf.d/wormhole : |
| 5 |
|
| 6 |
[wormhole_*] |
| 7 |
env.channeldb /path/to/your/wormhole/server/channel.sqlite |
| 8 |
env.usagedb /path/to/your/wormhole/server/usage.sqlite |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import print_function |
| 12 |
import os, sys, time, sqlite3 |
| 13 |
|
| 14 |
CONFIG = """\ |
| 15 |
graph_title Magic-Wormhole Active Channels |
| 16 |
graph_vlabel Channels |
| 17 |
graph_category wormhole |
| 18 |
nameplates.label Nameplates |
| 19 |
nameplates.draw LINE2 |
| 20 |
nameplates.type GAUGE |
| 21 |
mailboxes.label Mailboxes |
| 22 |
mailboxes.draw LINE2 |
| 23 |
mailboxes.type GAUGE |
| 24 |
messages.label Messages |
| 25 |
messages.draw LINE1 |
| 26 |
messages.type GAUGE |
| 27 |
""" |
| 28 |
|
| 29 |
if len(sys.argv) > 1 and sys.argv[1] == "config": |
| 30 |
print(CONFIG.rstrip()) |
| 31 |
sys.exit(0) |
| 32 |
|
| 33 |
usagedbfile = os.environ["usagedb"] |
| 34 |
assert os.path.exists(usagedbfile) |
| 35 |
usage_db = sqlite3.connect(usagedbfile) |
| 36 |
|
| 37 |
channeldbfile = os.environ["channeldb"] |
| 38 |
assert os.path.exists(channeldbfile) |
| 39 |
channel_db = sqlite3.connect(channeldbfile) |
| 40 |
|
| 41 |
MINUTE = 60.0 |
| 42 |
updated,rebooted = usage_db.execute("SELECT `updated`,`rebooted` FROM `current`").fetchone() |
| 43 |
if time.time() > updated + 6*MINUTE: |
| 44 |
sys.exit(1) # expired |
| 45 |
|
| 46 |
nameplates = channel_db.execute("SELECT COUNT() FROM `nameplates`").fetchone()[0] |
| 47 |
mailboxes = channel_db.execute("SELECT COUNT() FROM `mailboxes`").fetchone()[0] |
| 48 |
messages = channel_db.execute("SELECT COUNT() FROM `messages`").fetchone()[0] |
| 49 |
|
| 50 |
print("nameplates.value", nameplates) |
| 51 |
print("mailboxes.value", mailboxes) |
| 52 |
print("messages.value", messages) |