def start_cpu_logger(file_prefix='', remote_dir='', local_dir='.'): "Start CPU loade logger" # log cpu load logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_cpuload.log" host = env.host_string.split(':')[0] # resolve to IP to make sure we filter on right address host_ip = socket.gethostbyname(host) if host_ip == '': host_ip = host #top -b -d 0.1 | grep Cpu #pid = runbg(' top -b -d 0.5 ' , out_file=logfile) #pid = runbg(' vmstat 1 100000 -n ' , out_file=logfile) pid = runbg(' sar 1 ', out_file=logfile) bgproc.register_proc_later( env.host_string, local_dir, 'cpuloadlogger', '00', pid, logfile)
def start_qdisc_logger(file_prefix='', remote_dir='', local_dir='.'): "Start qdisc logger" # log queue length and queue delay logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_qdisc_stats.log" # make sure script is there put(config.TPCONF_script_path + '/qdisc_logger.sh', '/usr/bin') run('chmod a+x /usr/bin/qdisc_logger.sh') sample_interval = 0.01 try: sample_interval = float(config.TPCONF_web10g_poll_interval) / 1000.0 except AttributeError: pass # run qdisc_logger.sh script # FIXME: ifb interfaces qdisc_type = config.TPCONF_aqms[0] pid = runbg('qdisc_logger.sh %f %s %s %s' % (sample_interval, 'ifb1', qdisc_type, logfile)) bgproc.register_proc_later( env.host_string, local_dir, 'qdisclogger', '00', pid, logfile)
def start_custom_logger_local(file_prefix='', remote_dir='', local_dir='', name='', logname='', directory='', copy_file='0', add_prefix='0', parameters=''): logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(':', '_') + '_' + logname + '.log' custom_cmd = '' if name == '': abort('Custom logging: "name" variable must be set to the name of the command to run.') if directory == '': if copy_file == '0' or copy_file == 0: pass else: abort('Custom logging: "copy_file" is set, but "directory" is not set.') else: if directory[-1] != '/': directory = directory + '/' if copy_file == '0' or copy_file == 0: custom_cmd = directory else: put(directory + name, '/usr/bin') run('chmod a+x /usr/bin/' + name, pty=False) run('which ' + name, pty=False) if add_prefix == '0' or add_prefix == 0: custom_cmd += name + ' ' + parameters else: custom_cmd += name + ' ' + file_prefix + '_' + \ env.host_string.replace(':', '_') + ' ' + parameters pid = runbg(custom_cmd, out_file=logfile) bgproc.register_proc_later( env.host_string, local_dir, logname, '0', pid, logfile)
def start_tcp_logger(file_prefix='', remote_dir='', local_dir='.'): "Start TCP information logger (e.g. siftr on FreeBSD)" if remote_dir != '' and remote_dir[-1] != '/': remote_dir += '/' # get host type htype = get_type_cached(env.host_string) if htype == 'FreeBSD': # load kernel module with settings(warn_only=True): run('kldunload siftr') # run('kldunload h_ertt') # do not attempt to unload, can cause # kernel panic # if h_ertt is loaded siftr outputs unsmoothed rtt as well??? # h_ertt appears to have a bug that makes it impossible to unload, # so don't try to unload. test if present and only try to load if # not present with settings(warn_only=True): ret = run('kldstat | grep h_ertt') if ret.return_code != 0: run('kldload h_ertt') run('kldload siftr') # we need an absolute path if remote_dir == '': remote_dir = '/tmp/' logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_siftr.log" run('sysctl net.inet.siftr.logfile=%s' % logfile) run('sysctl net.inet.siftr.ppl=1') run('sysctl net.inet.siftr.genhashes=1') run('sysctl net.inet.siftr.enabled=1') #bgproc.register_proc(env.host_string, 'tcplogger', '00', '0', logfile) bgproc.register_proc_later( env.host_string, local_dir, 'tcplogger', '00', '0', logfile) elif htype == 'Linux': try: linux_tcp_logger = config.TPCONF_linux_tcp_logger except AttributeError: linux_tcp_logger = 'web10g' if linux_tcp_logger == 'ttprobe' or linux_tcp_logger == 'both': ttprobe_output_mode = config.TPCONF_ttprobe_output_mode ttprobe_direction = config.TPCONF_ttprobe_direction if ttprobe_output_mode == 'binary': ttprobe_output_mode = '1' else: ttprobe_output_mode = '0' if ttprobe_direction == 'o': ttprobe_direction = '0' elif ttprobe_direction == 'i': ttprobe_direction = '1' else: ttprobe_direction = '2' # ttprobe - start_tcp_logger code with settings(warn_only=True): run('rmmod ttprobe') # start new_tcp_probe kernel module run('modprobe ttprobe port=0 full=1 bufsize=16384 omode=%s direction=%s' % (ttprobe_output_mode, ttprobe_direction)) logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_ttprobe.log" host = env.host_string.split(':')[0] # resolve to IP to make sure we filter on right address host_ip = socket.gethostbyname(host) if host_ip == '': host_ip = host pid = runbg('cat /proc/net/ttprobe', out_file=logfile) #pid = runbg('cat /proc/kmsg', out_file=logfile) bgproc.register_proc_later( env.host_string, local_dir, 'tcploggerprobe', '00', pid, logfile) if linux_tcp_logger == 'web10g' or linux_tcp_logger == 'both': # set default sample interval to roughly 10ms sample_interval = 0.01 try: sample_interval = float(config.TPCONF_web10g_poll_interval) / 1000.0 except AttributeError: pass # with new web10g we use the provided web10g-logger which needs interval # in milliseconds, so convert here with settings(warn_only=True): out = run('web10g-logger -h | grep "poll interval given in seconds"') if out == '': sample_interval *= 1000 # turn off logging and remove kernel module with settings(warn_only=True): run('echo 0 > /proc/sys/net/ipv4/tcp_estats') # version 2.0.8+ run('rmmod tcp_estats_nl') # start kernel module run('modprobe tcp_estats_nl') # for new web10g (version 2.08 and higher) we need to turn it on, note # that /proc/sys/net/ipv4/tcp_estats is not just 0/1 but we need to # specify a bit mask to turn on/off different features. # we turn on all features to be compatible to previous version # (see /usr/src/<linux>/include/net/tcp_estats.h for bit flags, # the TCP_ESTATS_TABLEMASK_* constants) with settings(warn_only=True): run('echo 95 > /proc/sys/net/ipv4/tcp_estats') # OLD: # check userland code is there #run('which web10g-listconns') #run('which web10g-readvars') # make sure script is there #put(config.TPCONF_script_path + '/web10g_logger.sh', '/usr/bin') #run('chmod a+x /usr/bin/web10g_logger.sh') # check userland code is there run('which web10g-logger') logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_web10g.log" host = env.host_string.split(':')[0] # OLD: #pid = runbg('web10g_logger.sh %f %s %s' % (sample_interval, logfile, host)) # run with high priority #run('renice -n -20 -p %s' % pid) # resolve to IP to make sure we filter on right address host_ip = socket.gethostbyname(host) if host_ip == '': host_ip = host pid = runbg( 'web10g-logger -e %s -i %f' % (host_ip, sample_interval), out_file=logfile) #bgproc.register_proc(env.host_string, 'tcplogger', '00', pid, logfile) bgproc.register_proc_later( env.host_string, local_dir, 'tcplogger', '00', pid, logfile) elif htype == 'Darwin': # start dtrace based logging tool run('which dsiftr-osx-teacup.d') # since the Mac tool produces the same output as SIFTR # we give it the same _siftr.log extension logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_siftr.log" host = env.host_string.split(':')[0] # resolve to IP to make sure we filter on right address host_ip = socket.gethostbyname(host) if host_ip == '': host_ip = host pid = runbg( 'dsiftr-osx-teacup.d "%s"' % (host_ip), out_file=logfile) #bgproc.register_proc(env.host_string, 'tcplogger', '00', pid, logfile) bgproc.register_proc_later( env.host_string, local_dir, 'tcplogger', '00', pid, logfile) elif htype == 'CYGWIN': # set sample interval to roughly 10ms sample_interval = 0.01 try: sample_interval = float(config.TPCONF_web10g_poll_interval) / 1000.0 except AttributeError: pass # check userland code is there run('which win-estats-logger') # since the windows tool produces the same output as the web10g logger # we give it the same _web10g.log extension logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_web10g.log" host = env.host_string.split(':')[0] # resolve to IP to make sure we filter on right address host_ip = socket.gethostbyname(host) if host_ip == '': host_ip = host pid = runbg( 'win-estats-logger -q -e %s -i %f' % (host_ip, sample_interval), out_file=logfile) #bgproc.register_proc(env.host_string, 'tcplogger', '00', pid, logfile) bgproc.register_proc_later( env.host_string, local_dir, 'tcplogger', '00', pid, logfile) else: warn("No TCP logger available on OS '%s'" % htype)
def start_tcpdump( file_prefix='', remote_dir='', local_dir='.', snap_len='80', tcpdump_filter='', internal_int='1'): "Start tcpdump instance on host" # get host type htype = get_type_cached(env.host_string) if env.host_string in config.TPCONF_router: interfaces = get_netint_cached(env.host_string, int_no=-1, internal_int=internal_int) else: if htype == 'CYGWIN': interfaces = get_netint_windump_cached(env.host_string, int_no=0, internal_int=internal_int) else: interfaces = get_netint_cached(env.host_string, int_no=0, internal_int=internal_int) if len(interfaces) < 1: abort('Internal interface not specified') if remote_dir != '' and remote_dir[-1] != '/': remote_dir += '/' for interface in interfaces: if env.host_string in config.TPCONF_router: if internal_int == '1': file_name = remote_dir + file_prefix + '_' + \ env.host_string.replace(':', '_') + \ '_' + interface + '_router.dmp' else: file_name = remote_dir + file_prefix + '_' + \ env.host_string.replace(':', '_') + '_ctl.dmp' else: if internal_int == '1': file_name = remote_dir + file_prefix + '_' + \ env.host_string.replace(':', '_') + '.dmp' else: file_name = remote_dir + file_prefix + '_' + \ env.host_string.replace(':', '_') + '_ctl.dmp' if htype == 'FreeBSD' or htype == 'Linux' or htype == 'Darwin': tcpdump_cmd = 'tcpdump -n -s %s -i %s -w %s \'%s\'' % ( snap_len, interface, file_name, tcpdump_filter) else: # CYGWIN tcpdump_cmd = 'WinDump -n -s %s -i %s -w ' \ '"$(cygpath -aw "%s")" \'%s\'' % ( snap_len, interface, file_name, tcpdump_filter) pid = runbg(tcpdump_cmd) name = 'tcpdump-' + interface #bgproc.register_proc(env.host_string, name, '0', pid, file_name) bgproc.register_proc_later( env.host_string, local_dir, name, '0', pid, file_name)
def start_tcp_logger(file_prefix='', remote_dir='', local_dir='.'): "Start TCP information logger (e.g. siftr on FreeBSD)" if remote_dir != '' and remote_dir[-1] != '/': remote_dir += '/' # get host type htype = get_type_cached(env.host_string) if htype == 'FreeBSD': # load kernel module with settings(warn_only=True): run('kldunload siftr') # run('kldunload h_ertt') # do not attempt to unload, can cause # kernel panic # if h_ertt is loaded siftr outputs unsmoothed rtt as well??? # h_ertt appears to have a bug that makes it impossible to unload, # so don't try to unload. test if present and only try to load if # not present with settings(warn_only=True): ret = run('kldstat | grep h_ertt') if ret.return_code != 0: run('kldload h_ertt') run('kldload siftr') # we need an absolute path if remote_dir == '': remote_dir = '/tmp/' logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_siftr.log" run('sysctl net.inet.siftr.logfile=%s' % logfile) run('sysctl net.inet.siftr.ppl=1') run('sysctl net.inet.siftr.genhashes=1') run('sysctl net.inet.siftr.enabled=1') #bgproc.register_proc(env.host_string, 'tcplogger', '00', '0', logfile) bgproc.register_proc_later( env.host_string, local_dir, 'tcplogger', '00', '0', logfile) elif htype == 'Linux': # set default sample interval to roughly 10ms sample_interval = 0.01 try: sample_interval = float(config.TPCONF_web10g_poll_interval) / 1000.0 except AttributeError: pass # with new web10g we use the provided web10g-logger which needs interval # in milliseconds, so convert here with settings(warn_only=True): out = run('web10g-logger -h | grep "poll interval given in seconds"') if out == '': sample_interval *= 1000 # turn off logging and remove kernel module with settings(warn_only=True): run('echo 0 > /proc/sys/net/ipv4/tcp_estats') # version 2.0.8+ run('rmmod tcp_estats_nl') # start kernel module run('modprobe tcp_estats_nl') # for new web10g (version 2.08 and higher) we need to turn it on, note # that /proc/sys/net/ipv4/tcp_estats is not just 0/1 but we need to # specify a bit mask to turn on/off different features. # we turn on all features to be compatible to previous version # (see /usr/src/<linux>/include/net/tcp_estats.h for bit flags, # the TCP_ESTATS_TABLEMASK_* constants) with settings(warn_only=True): run('echo 95 > /proc/sys/net/ipv4/tcp_estats') # OLD: # check userland code is there #run('which web10g-listconns') #run('which web10g-readvars') # make sure script is there #put(config.TPCONF_script_path + '/web10g_logger.sh', '/usr/bin') #run('chmod a+x /usr/bin/web10g_logger.sh') # check userland code is there run('which web10g-logger') logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_web10g.log" host = env.host_string.split(':')[0] # OLD: #pid = runbg('web10g_logger.sh %f %s %s' % (sample_interval, logfile, host)) # run with high priority #run('renice -n -20 -p %s' % pid) # resolve to IP to make sure we filter on right address host_ip = socket.gethostbyname(host) if host_ip == '': host_ip = host pid = runbg( 'web10g-logger -e %s -i %f' % (host_ip, sample_interval), out_file=logfile) #bgproc.register_proc(env.host_string, 'tcplogger', '00', pid, logfile) bgproc.register_proc_later( env.host_string, local_dir, 'tcplogger', '00', pid, logfile) elif htype == 'Darwin': # start dtrace based logging tool run('which dsiftr-osx-teacup.d') # since the Mac tool produces the same output as SIFTR # we give it the same _siftr.log extension logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_siftr.log" host = env.host_string.split(':')[0] # resolve to IP to make sure we filter on right address host_ip = socket.gethostbyname(host) if host_ip == '': host_ip = host pid = runbg( 'dsiftr-osx-teacup.d "%s"' % (host_ip), out_file=logfile) #bgproc.register_proc(env.host_string, 'tcplogger', '00', pid, logfile) bgproc.register_proc_later( env.host_string, local_dir, 'tcplogger', '00', pid, logfile) elif htype == 'CYGWIN': # set sample interval to roughly 10ms sample_interval = 0.01 try: sample_interval = float(config.TPCONF_web10g_poll_interval) / 1000.0 except AttributeError: pass # check userland code is there run('which win-estats-logger') # since the windows tool produces the same output as the web10g logger # we give it the same _web10g.log extension logfile = remote_dir + file_prefix + '_' + \ env.host_string.replace(":", "_") + "_web10g.log" host = env.host_string.split(':')[0] # resolve to IP to make sure we filter on right address host_ip = socket.gethostbyname(host) if host_ip == '': host_ip = host pid = runbg( 'win-estats-logger -q -e %s -i %f' % (host_ip, sample_interval), out_file=logfile) #bgproc.register_proc(env.host_string, 'tcplogger', '00', pid, logfile) bgproc.register_proc_later( env.host_string, local_dir, 'tcplogger', '00', pid, logfile) else: warn("No TCP logger available on OS '%s'" % htype)