-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsend.py
More file actions
executable file
·53 lines (37 loc) · 1.06 KB
/
Copy pathsend.py
File metadata and controls
executable file
·53 lines (37 loc) · 1.06 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
"""
Use the Python DTrace consumer and push the data through AMQP as the DTrace
probes fire.
Created on Mar 31, 2012
@author: tmetsch
"""
import time
import pika
import dtrace
# pretty num D script counting syscalls...
SCRIPT = 'syscall:::entry { @num[execname] = count(); }'
# Connection to the broker
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='dtrace')
def walk(_iden, key, value):
"""
Walker which sends on the data to RabbitMQ as the DTrace probes fire.
"""
channel.basic_publish(exchange='', routing_key='dtrace',
body=bytes({key[0]: value}))
def run_dtrace():
"""
Runs a DTrace script for 5 seconds...
"""
thr = dtrace.DTraceConsumerThread(SCRIPT, walk_func=walk)
thr.start()
# we will stop the thread after some time...
time.sleep(5)
# stop and wait for join...
thr.stop()
thr.join()
if __name__ == '__main__':
run_dtrace()
connection.close()