-
Notifications
You must be signed in to change notification settings - Fork 573
Expand file tree
/
Copy pathpybitmessagestatus.py
More file actions
68 lines (57 loc) · 2.01 KB
/
pybitmessagestatus.py
File metadata and controls
68 lines (57 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python2.7
import collectd
import json
from six.moves import xmlrpc_client as xmlrpclib
pybmurl = ""
api = ""
def init_callback():
global api
api = xmlrpclib.ServerProxy(pybmurl)
collectd.info('pybitmessagestatus.py init done')
def config_callback(ObjConfiguration):
global pybmurl
apiUsername = ""
apiPassword = ""
apiInterface = "127.0.0.1"
apiPort = 8445
for node in ObjConfiguration.children:
key = node.key.lower()
if key.lower() == "apiusername" and node.values:
apiUsername = node.values[0]
elif key.lower() == "apipassword" and node.values:
apiPassword = node.values[0]
elif key.lower() == "apiinterface" and node.values:
apiInterface = node.values[0]
elif key.lower() == "apiport" and node.values:
apiPort = node.values[0]
pybmurl = "http://{}:{}@{}:{}/".format(apiUsername, apiPassword, apiInterface, str(int(apiPort)))
collectd.info('pybitmessagestatus.py config done')
def read_callback():
try:
clientStatus = json.loads(api.clientStatus())
except (ValueError, TypeError):
collectd.info("Exception loading or parsing JSON")
return
except: # noqa:E722
collectd.info("Exception loading or parsing JSON")
return
for i in ["networkConnections", "numberOfPubkeysProcessed",
"numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]:
metric = collectd.Values()
metric.plugin = "pybitmessagestatus"
if i[0:6] == "number":
metric.type = 'counter'
else:
metric.type = 'gauge'
metric.type_instance = i.lower()
try:
metric.values = [clientStatus[i]]
except (TypeError, KeyError):
collectd.info("Value for %s missing" % (i))
metric.dispatch()
if __name__ == "__main__":
main()
else:
collectd.register_init(init_callback)
collectd.register_config(config_callback)
collectd.register_read(read_callback)