forked from AlexanderChudnovets/magnetodb-test-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocust_plugin.py
39 lines (28 loc) · 835 Bytes
/
locust_plugin.py
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
import collectd
import requests
def get_gauge(data):
if not data:
return 0
if isinstance(data, float):
return int(data)
return data
def put_data(data):
del(data['name'])
for key in data:
vl = collectd.Values(plugin='locust')
vl.type = 'gauge'
vl.type_instance = key
vl.dispatch(values=[get_gauge(data[key])])
def write(vl, data=None):
for i in vl.values:
print "%s (%s): %f" % (vl.plugin, vl.type, i)
def read(data=None):
rsp = requests.get('http://localhost:8089/stats/requests')
data = rsp.json()
if not data or ('stats' not in data):
collectd.error('locust plugin: No info received')
return
for r in data['stats']:
if r['name'] == 'Total':
put_data(r)
collectd.register_read(read)