From abbbc744ba4eea500918c3a337eeb678434cb92a Mon Sep 17 00:00:00 2001 From: Kun Huang Date: Fri, 23 Oct 2015 12:06:07 +0800 Subject: [PATCH] run singal agent successfully now --- scalpels/cli/actions/start.py | 13 +++++++------ scripts/device-input-traffic.sh | 20 ++++++++++++++++++++ scripts/rbt-trace.py | 4 +++- tools/agents.json | 3 ++- 4 files changed, 32 insertions(+), 8 deletions(-) create mode 100755 scripts/device-input-traffic.sh diff --git a/scalpels/cli/actions/start.py b/scalpels/cli/actions/start.py index c2b9036..301dc41 100644 --- a/scalpels/cli/actions/start.py +++ b/scalpels/cli/actions/start.py @@ -35,10 +35,10 @@ def _parse_agents_from_file(config): # TODO this map should be saved in a config file # TODO refar to pre/exec/post agents_map = { - "mysql": "bash /opt/stack/scalpels/scripts/mysql-live.sh", - "rabbit": "", - "traffic": "", - "rpctraffic": "", + "mysql": "bash /opt/stack/scalpels/scripts/mysql-live.sh", #XXX doesn't work now, needs works on interapt pipeline + "rabbit": "python /opt/stack/scalpels/scripts/rbt-trace.py", + "rpc": "bash /opt/stack/scalpels/scripts/port-input-traffic.sh 5672", + "traffic": "bash /opt/stack/scalpels/scripts/device-input-traffic.sh eth1", } def run(config): @@ -51,12 +51,13 @@ def run(config): if ag_exec: ag_p = subprocess.Popen(ag_exec.split(), stdout=subprocess.PIPE) running_agents.append(ag_p) - time.sleep(5) + time.sleep(15) data = [] for ag_p in running_agents: # shell scripts has depend child which can't be killed by subprocess' API # it should be ag_p.kill() - os.system("pkill -P %s" % ag_p.pid) + #os.system("pkill -P %s" % ag_p.pid) + ag_p.send_signal(signal.SIGINT) stdout = ag_p.stdout.read() data.append(stdout) rets = [] diff --git a/scripts/device-input-traffic.sh b/scripts/device-input-traffic.sh new file mode 100755 index 0000000..964d69c --- /dev/null +++ b/scripts/device-input-traffic.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Author: Kun Huang + +dev=${1:-eth0} + +packages=`cat /sys/class/net/$dev/statistics/rx_packets ` +bytes=`cat /sys/class/net/$dev/statistics/rx_bytes ` + +interval=3 + +trap 'break' INT +while [ 1 -eq 1 ] ; do + sleep $interval + n_packages=`cat /sys/class/net/$dev/statistics/rx_packets ` + n_bytes=`cat /sys/class/net/$dev/statistics/rx_bytes ` + python -c "print '%0.2f pkt/s' % (float($n_packages-$packages)/int($interval))" + python -c "print '%0.2f byte/s' % (float($n_bytes-$bytes)/int($interval))" + packages=$n_packages + bytes=$n_bytes +done diff --git a/scripts/rbt-trace.py b/scripts/rbt-trace.py index ccfa3ca..2c8ade8 100755 --- a/scripts/rbt-trace.py +++ b/scripts/rbt-trace.py @@ -3,6 +3,7 @@ # Author: Kun Huang import json +import subprocess from kombu import Connection from kombu import Exchange @@ -53,7 +54,8 @@ class Worker(ConsumerMixin): with Connection('amqp://guest:guest@localhost:5672//') as conn: try: + subprocess.check_call("sudo rabbitmqctl trace_on", shell=True) worker = Worker(conn) worker.run() except KeyboardInterrupt: - print debug + subprocess.check_call("sudo rabbitmqctl trace_off", shell=True) diff --git a/tools/agents.json b/tools/agents.json index d502043..e19417e 100644 --- a/tools/agents.json +++ b/tools/agents.json @@ -12,5 +12,6 @@ { "name": "rpctraffic" } - ] + ], + "sleep": 5, }