read data from subprocess, but it's bad for shell scripts
This commit is contained in:
parent
52438cfe6f
commit
3ec61813cf
@ -7,6 +7,7 @@ import json
|
||||
from scalpels.db import api as db_api
|
||||
import subprocess
|
||||
import time
|
||||
import signal
|
||||
|
||||
def _parse_agents_from_args(config):
|
||||
parsed_agents = set()
|
||||
@ -32,8 +33,9 @@ def _parse_agents_from_file(config):
|
||||
return parsed_agents
|
||||
|
||||
# TODO this map should be saved in a config file
|
||||
# TODO refar to pre/exec/post
|
||||
agents_map = {
|
||||
"mysql": "",
|
||||
"mysql": "bash /opt/stack/scalpels/scripts/mysql-live.sh",
|
||||
"rabbit": "",
|
||||
"traffic": "",
|
||||
"rpctraffic": "",
|
||||
@ -47,13 +49,15 @@ def run(config):
|
||||
for ag in agents:
|
||||
ag_exec = agents_map.get(ag)
|
||||
if ag_exec:
|
||||
ag_p = subprocess.Popen(ag_exec, stdout=subprocess.PIPE)
|
||||
ag_p = subprocess.Popen(ag_exec.split(), stdout=subprocess.PIPE)
|
||||
running_agents.append(ag_p)
|
||||
time.sleep(15)
|
||||
time.sleep(5)
|
||||
data = []
|
||||
for ag_p in running_agents:
|
||||
stdout = ag_p.communicate()[0]
|
||||
ag_p.terminate()
|
||||
# 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)
|
||||
stdout = ag_p.stdout.read()
|
||||
data.append(stdout)
|
||||
rets = []
|
||||
ret = db_api.result_create(data)
|
||||
|
@ -11,7 +11,20 @@ log_switch_var=general_log
|
||||
log_file=/tmp/mysqllive.log
|
||||
old_log_file=`mysql -e "SELECT @@$log_file_var" | grep -v $log_file_var | grep -v '\-\-\-\-\-'`
|
||||
old_log_switch=`mysql -e "SELECT @@$log_switch_var" | grep -v $log_switch_var | grep -v '\-\-\-\-\-'`
|
||||
trap ':' INT
|
||||
|
||||
reset () {
|
||||
echo -------------------------------------
|
||||
echo reset $log_file_var to $old_log_file
|
||||
echo reset $log_switch_var to $old_log_switch
|
||||
mysql -e "SET GLOBAL $log_switch_var = $old_log_switch;"
|
||||
mysql -e "SET GLOBAL $log_file_var = '$old_log_file';"
|
||||
|
||||
echo remove $log_file
|
||||
echo -------------------------------------
|
||||
sudo rm $log_file
|
||||
}
|
||||
|
||||
trap "reset" SIGINT SIGTERM
|
||||
|
||||
echo -------------------------------------
|
||||
echo reserve $log_file_var: $log_file
|
||||
@ -21,8 +34,11 @@ echo -------------------------------------
|
||||
mysql -e "SET GLOBAL $log_file_var = '$log_file';"
|
||||
mysql -e "SET GLOBAL $log_switch_var = ON;"
|
||||
|
||||
sleep 1
|
||||
sudo chmod +r $log_file
|
||||
|
||||
# TODO use awk /reg/ statement instead
|
||||
sudo tailf $log_file | awk '{
|
||||
tailf $log_file | awk '{
|
||||
if ( $1 + 0 != $1 )
|
||||
# TODO cat this line on its above line
|
||||
print $0;
|
||||
@ -37,13 +53,3 @@ else
|
||||
{ $1=$2=""; print $0; print ""}
|
||||
}
|
||||
'
|
||||
|
||||
echo -------------------------------------
|
||||
echo reset $log_file_var to $old_log_file
|
||||
echo reset $log_switch_var to $old_log_switch
|
||||
mysql -e "SET GLOBAL $log_switch_var = $old_log_switch;"
|
||||
mysql -e "SET GLOBAL $log_file_var = '$old_log_file';"
|
||||
|
||||
echo remove $log_file
|
||||
echo -------------------------------------
|
||||
sudo rm $log_file
|
||||
|
Loading…
Reference in New Issue
Block a user