Debian Codegraph @

misc/munin/wormhole_events

raw symbols SCIP
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 Mailbox Events (since reboot)
15 graph_vlabel Events Since Reboot
16 graph_category wormhole
17 happy.label Happy
18 happy.draw LINE2
19 happy.type GAUGE
20 total.label Total
21 total.draw LINE1
22 total.type GAUGE
23 scary.label Scary
24 scary.draw LINE2
25 scary.type GAUGE
26 pruney.label Pruney
27 pruney.draw LINE1
28 pruney.type GAUGE
29 lonely.label Lonely
30 lonely.draw LINE2
31 lonely.type GAUGE
32 errory.label Errory
33 errory.draw LINE1
34 errory.type GAUGE
35 """
36
37 if len(sys.argv) > 1 and sys.argv[1] == "config":
38 print(CONFIG.rstrip())
39 sys.exit(0)
40
41 usagedbfile = os.environ["usagedb"]
42 assert os.path.exists(usagedbfile)
43 usage_db = sqlite3.connect(usagedbfile)
44
45 MINUTE = 60.0
46 updated,rebooted,blur = usage_db.execute(
47 "SELECT `updated`,`rebooted`,`blur_time` FROM `current`").fetchone()
48 if time.time() > updated + 6*MINUTE:
49 sys.exit(1) # expired
50 if blur is not None:
51 rebooted = blur * (rebooted // blur)
52 # After a reboot, the operator will get to see events that happen during
53 # the first blur window (without this adjustment, those events would be
54 # hidden since they'd appear to start before the reboot). The downside is
55 # that the counter won't drop down to zero at a reboot (if there are recent
56 # events).
57
58 #r = usage_db.execute("SELECT COUNT(`mood`) FROM `mailboxes` WHERE `started` > ?",
59 # (rebooted,)).fetchone()
60 for mood in ["happy", "scary", "lonely", "errory", "pruney", "crowded"]:
61 r = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `started` >= ?"
62 " AND `result` = ?",
63 (rebooted, mood)).fetchone()[0]
64 print("%s.value" % mood, r)
65 r = usage_db.execute("SELECT COUNT() FROM `mailboxes` WHERE `started` >= ?",
66 (rebooted,)).fetchone()[0]
67 print("total.value", r)