-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathreceive.py
More file actions
executable file
·53 lines (43 loc) · 1.3 KB
/
Copy pathreceive.py
File metadata and controls
executable file
·53 lines (43 loc) · 1.3 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
#!/usr/bin/env python
"""
Receives up to date data from the DTrace consumer.
Created on Mar 31, 2012
@author: tmetsch
"""
from __future__ import print_function
import ast
import pika
# Connection to the broker.
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='dtrace')
# The aggregated data :-)
data = {}
def callback(_ch, _method, _properties, body):
"""
Callback which picks up the DTrace messages.
"""
tmp = ast.literal_eval(body)
key = tmp.keys()[0]
val = tmp.values()[0]
if key in data:
data[key] += val
else:
data[key] = val
# Print instead of doing print you could life update a chart...msg will
# come as DTrace fires them
print('Received: ', key, val)
if __name__ == '__main__':
channel.basic_consume(on_message_callback=callback,
queue='dtrace',
auto_ack=False)
try:
channel.start_consuming()
except KeyboardInterrupt:
connection.close()
# You could use Google chart to create a plot aferwards...
# from GChartWrapper import Pie
# G = Pie(data.values())
# G.label(*data.keys()).size(400,300).title('Syscalls counter chart')
# G.save()