Debian Codegraph @

misc/munin/wormhole_event_rate

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 from collections import defaultdict
13
14 CONFIG = """\
15 graph_title Magic-Wormhole Server Events
16 graph_vlabel Events per Hour
17 graph_category wormhole
18 happy.label Happy
19 happy.draw LINE
20 happy.type DERIVE
21 happy.min 0
22 happy.max 60
23 happy.cdef happy,3600,*
24 incomplete.label Incomplete
25 incomplete.draw LINE
26 incomplete.type DERIVE
27 incomplete.min 0
28 incomplete.max 60
29 incomplete.cdef incomplete,3600,*
30 scary.label Scary
31 scary.draw LINE
32 scary.type DERIVE
33 scary.min 0
34 scary.max 60
35 scary.cdef scary,3600,*
36 """
37
38 if len(sys.argv) > 1 and sys.argv[1] == "config":
39 print(CONFIG.rstrip())
40 sys.exit(0)
41
42 usagedbfile = os.environ["usagedb"]
43 assert os.path.exists(usagedbfile)
44 usage_db = sqlite3.connect(usagedbfile)
45
46 MINUTE = 60.0
47 updated,rebooted = usage_db.execute("SELECT `updated`,`rebooted` FROM `current`").fetchone()
48 if time.time() > updated + 6*MINUTE:
49 sys.exit(1) # expired
50
51 atm = defaultdict(int)
52 for mood in ["happy", "scary", "lonely", "errory", "pruney", "crowded"]:
53 atm[mood] = usage_db.execute("SELECT COUNT() FROM `mailboxes`"
54 " WHERE `result` = ?", (mood,)).fetchone()[0]
55
56 print("happy.value", atm["happy"])
57 print("incomplete.value", (atm["pruney"] + atm["lonely"]))
58 print("scary.value", atm["scary"])