记录时延采用Ping和SockPerf,分别采用下面的Bash命令记录到相关的文件中:
ping 10.2.1.5 -i 15 | while read pong; do echo "$(date): $pong" >> ping.txt; done & while true; \ do sockperf ping-pong \ -i 10.2.1.5 -p 80 --tcp \ --full-rtt -m 64 | awk '{print $0 " --- " strftime()}' >> sock.txt; \ sleep 60; \ done &
对于获取到的文件,可以采用下面的脚本统计相关的数据:
#!/bin/bash a=$(cat $1 | wc -l) echo Total $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 >= 5' | wc -l) echo bigger_5ms $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 < 5 ' | awk -F '=' '$4 >= 4' | wc -l) echo between_4ms-5ms $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 < 4 ' | awk -F '=' '$4 >= 3' | wc -l) echo between_3ms-4ms $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 < 3 ' | awk -F '=' '$4 >= 2' | wc -l) echo between_2ms-3ms $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 < 2 ' | awk -F '=' '$4 >= 1' | wc -l) echo between_1ms-2ms $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 <1 ' | awk -F '=' '$4 >= 0.9'| wc -l) echo between_0.9ms-1ms $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 <0.9 ' | awk -F '=' '$4 >= 0.8' | wc -l) echo between_0.8ms-0.9ms $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 <0.8 ' | awk -F '=' '$4 >= 0.7' | wc -l) echo between_0.7ms-0.8ms $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 <0.7 ' | awk -F '=' '$4 >= 0.6' | wc -l) echo between_0.6ms-0.7ms $a a=$(cat $1 | awk -F 'ms' '{print $1}' | awk -F '=' '$4 <0.6 ' | wc -l) echo smaller_0.6ms $a echo ============================================ a=$(cat $2 | grep Summary | wc -l) echo Summary_total $a a=$(cat $2 | grep Summary | awk '$6 <= 40' | wc -l) echo Summary_smaller_40us $a a=$(cat $2 | grep Summary | awk '$6 <= 43' | awk '$6 > 40' | wc -l) echo Summary_between_40us-43us $a a=$(cat $2 | grep Summary | awk '$6 <= 46' | awk '$6 > 43' | wc -l) echo Summary_between_43us-46us $a a=$(cat $2 | grep Summary | awk '$6 <= 49' | awk '$6 > 46' | wc -l) echo Summary_between_46us-49us $a a=$(cat $2 | grep Summary | awk '$6 > 49' | wc -l) echo Summary_bigger_49us $a echo =========================================== a=$(cat $2 | grep MAX | awk -F ' = ' '{print $2}' | awk -F ' --- ' '{print $1}' | wc -l) echo MAX_total $a a=$(cat $2 | grep MAX | awk -F ' = ' '{print $2}' | awk -F ' --- ' '{print $1}' | awk '$1 <= 50' | wc -l) echo MAX_smaller_50us $a a=$(cat $2 | grep MAX | awk -F ' = ' '{print $2}' | awk -F ' --- ' '{print $1}' | awk '$1 <= 75' | awk '$1 > 50' |wc -l) echo MAX_between_50us-75us $a a=$(cat $2 | grep MAX | awk -F ' = ' '{print $2}' | awk -F ' --- ' '{print $1}' | awk '$1 <= 100' | awk '$1 > 75' |wc -l) echo MAX_between_75us-100us $a a=$(cat $2 | grep MAX | awk -F ' = ' '{print $2}' | awk -F ' --- ' '{print $1}' | awk '$1 <= 200' | awk '$1 > 100' |wc -l) echo MAX_between_100us-200us $a a=$(cat $2 | grep MAX | awk -F ' = ' '{print $2}' | awk -F ' --- ' '{print $1}' | awk '$1 <= 400' | awk '$1 > 200' |wc -l) echo MAX_between_200us-400us $a a=$(cat $2 | grep MAX | awk -F ' = ' '{print $2}' | awk -F ' --- ' '{print $1}' | awk '$1 <= 1000' | awk '$1 > 400' |wc -l) echo MAX_between_400us-1000us $a a=$(cat $2 | grep MAX | awk -F ' = ' '{print $2}' | awk -F ' --- ' '{print $1}' | awk '$1 <= 2000' | awk '$1 > 1000' |wc -l) echo MAX_between_1000us-2000us $a a=$(cat $2 | grep MAX | awk -F ' = ' '{print $2}' | awk -F ' --- ' '{print $1}' | awk '$1 > 2000' |wc -l) echo MAX_bigger_2000us $a
通过命令result.sh ping.txt sock.txt实现数据的统计。