VM间记录时延
记录时延采用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 &
对于获取到的文件,可以采用下面的脚本统计相关的数据:
Python脚本:
#!/usr/bin/env python import sys b=[0]*12 m=[0]*12 s=[0]*12 f = open(str(sys.argv[1]), 'r') n = 0 for i in f: if 'ms' in i: a = float(i.split("time=")[1].split()[0]) if a>=10: t=a/10 if t>10: b[10]=b[10]+1 else: b[int(a/10)]=b[int(a/10)]+1 elif a>=1: m[int(a)]=m[int(a)]+1 else: s[int(a*10)]=s[int(a*10)]+1 f.close() for i in range(1,10): print i*0.1,'ms -', (i+1)*0.1, 'ms --- ', s[i] for i in range(1,10): print i,'ms -', i+1, 'ms --- ', m[i] for i in range(1,10): print i*10,'ms -', (i+1)*10, 'ms --- ', b[i] print '>100ms --- ', b[10]
Bash脚本:
#!/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实现数据的统计。