Debian Codegraph @

misc/munin/wormhole_errors

raw
1 #! /usr/bin/env python
2
3 """
4 Use the following in /etc/munin/plugin-conf.d/wormhole :
5
6 [wormhole_*]
7 env.usagedb /path/to/your/wormhole/server/usage.sqlite
8 """
9
10 from __future__ import print_function
11 import os, sys, time, sqlite3
12
13 CONFIG = """\
14 graph_title Magic-Wormhole Server Errors
15 graph_vlabel Events Since Reboot
16 graph_category wormhole
17 nameplates.label Nameplate Errors (total)
18 nameplates.draw LINE1
19 nameplates.type GAUGE
20 mailboxes.label Mailboxes (total)
21 mailboxes.draw LINE1
22 mailboxes.type GAUGE
23 mailboxes_scary.label Mailboxes (scary)
24 mailboxes_scary.draw LINE1
25 mailboxes_scary.type GAUGE
26 """
27
28 if len(sys.argv) > 1 and sys.argv[1] == "config":
29 print(CONFIG.rstrip())
30 sys.exit(0)
31
32 usagedbfile = os.environ["usagedb"]
33 assert os.path.exists(usagedbfile)
34 usage_db = sqlite3.connect(usagedbfile)
35
36 MINUTE = 60.0
37 updated,rebooted = usage_db.execute("SELECT `updated`,`rebooted` FROM `current`").fetchone()
38 if time.time() > updated + 6*MINUTE:
39 sys.exit(1) # expired
40
41 r1 = usage_db.execute("SELECT COUNT() FROM `nameplates` WHERE `started` >= ?",
42 (rebooted,)).fetchone()[0]
43 r2 = usage_db.execute("SELECT COUNT() FROM `nameplates`"
44 " WHERE `started` >= ?"
45 " AND `result` = 'happy'",
46 (rebooted,)).fetchone()[0]
47 print("nameplates.value", (r1 - r2))
48 r1 = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `started` >= ?",
49 (rebooted,)).fetchone()[0]
50 r2 = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `started` >= ?"
51 " AND `result` = 'happy'",
52 (rebooted,)).fetchone()[0]
53 print("mailboxes.value", (r1 - r2))
54 r = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `started` >= ?"
55 " AND `result` = 'scary'",
56 (rebooted,)).fetchone()[0]
57 print("mailboxes_scary.value", r)