Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/data/data/com.termux/files/usr/bin/bash
- ### Simplw color outpur
- NoCol='\033[0m'
- Black='\033[0;30m'
- Red='\033[0;31m'
- Green='\033[0;32m'
- Yellow='\033[0;33m'
- Blue='\033[0;34m'
- Purple='\033[0;35m'
- Cyan='\033[0;36m'
- White='\033[0;37m'
- BBlack='\033[1;30m'
- BRed='\033[1;31m'
- BGreen='\033[1;32m'
- BYellow='\033[1;33m'
- BBlue='\033[1;34m'
- BPurple='\033[1;35m'
- BCyan='\033[1;36m'
- BWhite='\033[1;37m'
- UBlack='\033[4;30m'
- URed='\033[4;31m'
- UGreen='\033[4;32m'
- UYellow='\033[4;33m'
- UBlue='\033[4;34m'
- UPurple='\033[4;35m'
- UCyan='\033[4;36m'
- UWhite='\033[4;37m'
- ### Setu0 Plotping (install packages etc)
- setup-plotping () {
- echo "OK!"
- }
- #setup-plotping
- ############# Adds average RRT per ping and total transit time
- fixplot () {
- TMP=$(mktemp)
- newfile="$1_avg.plot"
- tavg=1
- ttot=0
- ctot=0
- cavg=1
- tail -n+2 $1 > $TMP
- xrange=$(cat $TMP |wc -l)
- lpcount=$(tail -n 1 $TMP |awk '{print $2}')
- rtts=$(cat $TMP |awk '{printf "%.0f + ", $5}')
- yrange=$(cat $TMP |awk '{print $5}' |sort -rn |head -n+1)
- iylow=$(cat $TMP |awk '{print $5}' |sort -n |head -n+1)
- ylow=$(printf "%.0f" $iylow)
- ttot=$(expr $rtts 0)
- tavg=$(expr $ttot / $lpcount)
- rm -f $newfile
- stime=$(cat $TMP |head -n 1 |awk '{print $1}')
- orig=$(cat "$1" |wc -l)
- run=1
- xrange=$(cat $TMP |wc -l)
- cat $TMP |while read line
- do
- rtt=$(echo $line|awk '{printf "%.0f", $5}')
- cping=$(echo $line |awk '{print $2}')
- ctot=$(( $ctot + $rtt ))
- ctots=$(echo "$ctot" | awk '{printf "%.2f", $1 / 1000}')
- cavg=$(( $ctot / $cping ))
- dtime=$(echo $line |awk '{print $1}')
- difftime=$(( $dtime - $stime ))
- sed -e "s/$/\t$cavg\t$ctots/g" <<< $line >> $newfile
- left=$(( $xrange - $run ))
- proc=$(awk -vn=$xrange -vrun=$run 'BEGIN{printf "%.0f", run*(100/n)}')
- echo -ne "${White}Proc:${BGreen} $proc% ${White}|| Rem:${BGreen}$left ${White} || InFlight:${BGreen}$ctots s ${White}|| Length:${BGreen}$difftime s${White}"\\r
- run=$(( $run + 1 ))
- done
- plotfile "$newfile"
- }
- ######################## End of plotfix
- ### Plot the file
- plotfile () {
- newfile="$1"
- yrange=$(cat $newfile |awk '{print $5}' |sort -rn |head -n 1)
- lavg=$(cat $newfile |awk '{print $5}' |tail -n 1)
- avgrtt=$(printf "%.0f" $lavg)
- xrange=$(cat $newfile |wc -l)
- PLOT="$newfile"
- pngfile="/sdcard/Download/$PLOT.png"
- echo -e "${Green} Plotting to: ${BWhite}$pngfile"
- echo -e -n "${White}Scaling to:${BGreen} X:$xrange/Y:$yrange/Z:$avgrtt"
- start=$(date +'%s')
- gnuplot << EOF
- set style data points
- #set style histogram columnstacked
- set boxwidth 0.5
- unset style line
- set style line 1 linetype 1 linewidth 1 pointsize 1 linecolor palette
- set style line 2 linetype 2 linewidth 2 linecolor rgb "#222222"
- set style line 3 linetype 3 linewidth 2 pointsize 3 linecolor rgb "#999999"
- set style line 4 linetype 4 linewidth 5 pointsize 5 linecolor palette
- set style line 5 linetype 5 linewidth 4 pointsize -1 linecolor rgb "#dddddd"
- set style increment userstyles
- set style fill transparent border lt -1
- set palette model RGB maxcolors 256
- set palette defined ( -1 '#77ff77', 25 '#00dd000', 50 '#ffff00', 75 '#dabd00', 100 '#ff0000', 125 '#990000' )
- set format x '%.0f'
- unset grid
- set grid linecolor rgb 'white'
- set xtics nomirror out
- set ytics nomirror out
- set border 3 back
- unset key
- #set title auto
- set xlabel "$yrange pings" textcolor rgb 'white'
- set ylabel "RTT (ms)" textcolor rgb 'white'
- set xrange [1:500]
- set yrange [0:$yrange]
- set xtics rotate 90
- set mxtics 100
- set tics textcolor rgb 'white'
- set cbrange [0:125]
- #set autoscale y
- set terminal png size 1280,720 font 'Source Sans Pro' 16 butt background '#000000'
- set output "$pngfile"
- plot "$PLOT" u 2:6:6 with lines ls 0.25 palette cb $avgrtt, "" u 2:5:5 with boxes palette z lw 0.25
- EOF
- end=$(date +'%s')
- echo -ne "${BWhite} done in " $(awk -va=$start -vb=$end 'BEGIN{print (a - b)}')
- echo " seconds."
- echo -e "${Green} Updated plot file:${BWhite} $newfile"
- echo -e "${Green} PNG location:${BWhite} $pngfile"
- }
- ###### End of plot functi9n
- ####### Ping plot function
- plotpings () {
- OUT="$1.plot"
- echo -e "${Green} Plotting to:${BWhite} $OUT"
- ping -c $2 -W 1s -i 1 "$1" \
- |sed -u -e 's/(\|):\|ttl=\|time=//g' \
- | grep "bytes from" \
- |awk 'BEGIN {print "Time\t\tPing\t\tHost\t\tTTL\t RTT";}
- {srand(); print srand(),"\t", NR,"\t",$5,"\t",$7,"\t",$8;}' \
- > $OUT
- echo "Done! Adding additional data, may take a while..."
- fixplot "$OUT"
- }
- if [ "$1" = "" ]; then
- echo "Malfunction! Need input!"
- exit 1
- else
- if [ "$2" == "" ] && [ -f "$1" ]; then
- echo "File found!"
- cols="$(tail -n 1 "$1" |wc -w)"
- if [ "$cols" = "5" ]; then
- echo "Processing plot file"
- fixplot "$1"
- elif [ "$cols" = "7" ]; then
- echo "Plot file already updated!"
- plotfile "$1"
- else
- echo "Yup, I didn't like that!"
- exit 1
- fi
- elif [ $2 > 14 ]; then
- echo "Attempting to plot pings on $1 for $2 seconds"
- plotpings "$1" "$2"
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement