Skip to content

Instantly share code, notes, and snippets.

@gliush
Last active January 8, 2022 17:05
Show Gist options
  • Save gliush/7741dc314cab8b1351ab to your computer and use it in GitHub Desktop.
Save gliush/7741dc314cab8b1351ab to your computer and use it in GitHub Desktop.
check_network
[ -z "$1" ] && echo "no logdir specified" && exit 2
[ -z "$2" ] && echo "no node specified" && exit 2
gen=$1
host=$2
mkdir $gen && cd $gen || exit 2
PERIOD="10mins"
end=`date -d +$PERIOD +%s`
cur=`date +%s`
function kill_tcpdump() {
echo "** Killing tcpdump"
killall tcpdump
exit 0
}
# trap ctrl-c and call kill_tcpdump()
trap kill_tcpdump INT
ip=`dig $host +short | tail -1`
TCPDUMP_DEBUG=false
# if tcpdump is needed, uncomment this line and
if [ "$TCPDUMP_DEBUG" = true ]; then
tcpdump -i eth0 -w tcpdump.cap "host $ip" &
fi
let i=0;
while true && [ $cur -lt $end ] ; do
let i=$i+1;
/usr/bin/time strace -o strace.dig.$i.log -C -v -f -ttt dig $host +short >& dig.$i.log;
ret=$?
echo $ret >> dig.$i.log;
if [ "$TCPDUMP_DEBUG" = true ]; then
echo "q" | time strace -o strace.nc.$i.log -C -v -f -ttt nc $ip 80 >& nc.$i.log
fi
ss -nat >& ss.$i.log;
cat /proc/net/sockstat >& sockstat.$i.log;
vmstat >& vmstat.$i.log;
cat /proc/interrupts > interrupts.$i.log;
echo "show stat -1 2 -1" | nc -U /var/run/haproxy.stat | grep "nweb.ec.8081" | cut -d, -f8 > haproxy.$i.log
cur=`cat haproxy.$i.log`
[ $i -gt 1 ] && prev=`cat haproxy.$((i-1)).log` || prev=0
rate=$(($cur-$prev))
printf "$i `grep ^TCP sockstat.$i.log | cut -d' ' -f7`tw ${rate}rps ";
echo "`tail -3 dig.$i.log | head -1 | awk '{print $3, $4}'` -> status=`tail -1 dig.$i.log`";
[ $ret -ne 0 ] && break
sleep 1;
cur=`date +%s`
done;
# to parse tcpdump captured file use:
#tcpdump -tt -nn -vvv -A -r $file
kill_tcpdump
set grid nopolar
set grid xtics nomxtics noytics nomytics noztics nomztics \
nox2tics nomx2tics noy2tics my2tics nocbtics nomcbtics
set grid layerdefault linetype -1 linecolor rgb "gray" linewidth 0.200, linetype -1 linecolor rgb "gray" linewidth 0.200
set key outside right top vertical Right noreverse enhanced autotitles nobox
set xlabel "Time, sec"
set y2label "Requests, rqs"
set ylabel "Number of tw-sockets"
#set logscale y 10
set ytics nomirror
set y2tics nomirror
set y2tics
set key autotitle columnheader
set terminal png transparent nocrop enhanced font arial 8 size 900,400
set output output_fn
set title title_str
#set grid x2tics
#set x2tics 13 format "" scale 0
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5 # --- blue
set style line 2 lc rgb '#00ad50' lt 1 lw 2 pt 5 ps 1.5 # --- blue
plot source_fn using 1:2 with lines ls 2 axes x1y1,\
source_fn using 1:3 with linespoints ls 1 axes x1y2,\
source_fn using 1:($8 == 0 ? NaN : $3) with points notitle pointtype 7 pointsize 2 lc rgbcolor "red" axes x1y2
for f in *.parsed.log; do
s=`basename $f .parsed.log`;
echo $s;
gnuplot -e "source_fn='$f'; output_fn='$s.png'; title_str='$s'" drawer.gnuplot;
done;
[ -z "$1" ] && echo "what node to test?" && exit 2
[ -z "$2" ] && echo "speed?" && exit 2
httperf --server=$1 --port=80 --uri="/index.html" --rate=$2 --num-conns=${2}00 --num-calls=1 -v
#!/bin/bash
ts_start=0
echo "ts tw rqs user_cpu sys_cpu idle_cpu time_dig status"
let i=0
while true; do
let i=$i+1;
# exit condition
[ -f "sockstat.$i.log" ] || break
# sockstat
tw=`cat sockstat.$i.log | grep "^TCP" | cut -d' ' -f7`
# approx timestamp
ts_cur=`head -1 strace.dig.$i.log | sed 's/^[^ ]* *\([0-9]*\.[0-9]*\).*/\1/'`
[ "$i" == "1" ] && ts_start=$ts_cur
ts=`echo "$ts_cur-$ts_start" | bc`
# dig duration
ts_last=`awk '/^% time/{print prev; exit 0};{prev=$0} ' strace.dig.$i.log | sed 's/^[^ ]* *\([0-9]*\.[0-9]*\).*/\1/'`
time_dig=`echo "$ts_last-$ts_cur" | bc`
# time from previous cycle
[ "$i" == "1" ] && ts_prev=$ts_cur
time_iter=`echo "$ts_cur-$ts_prev" | bc`
ts_prev=$ts_cur
# haproxy requests
rqs_cur=`cat haproxy.$i.log`
[ "$i" == "1" ] && rqs=0 || rqs=`echo "($rqs_cur-$rqs_prev)/$time_iter" | bc`
rqs_prev=$rqs_cur
# cpu usage
user_cpu=`tail -1 vmstat.$i.log | awk '{print $13}'`
sys_cpu=`tail -1 vmstat.$i.log | awk '{print $14}'`
idle_cpu=`tail -1 vmstat.$i.log | awk '{print $15}'`
# resolving status
status=`tail -1 dig.$i.log`
echo "$ts $tw $rqs $user_cpu $sys_cpu $idle_cpu $time_dig $status"
#[ "$i" == "8" ] && break
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment