
如果我使用帶有 -y C 和 -r 參數的 iperf 來測試雙向傳輸並將其匯出為 CSV。
我得到一些輸出,但問題是我不知道列名是什麼。例如,它顯示三行數據,但我不知道哪一行對應於發送以及哪一行對應於接收。
其他專欄我可以猜測,但我寧願確定。
我在任何地方都找不到這個記錄!
答案1
這些字段是
時間戳記、來源位址、來源連接埠、目標位址、目標連接埠、間隔、傳輸位元組數、每秒位數
我透過查看推斷出這一點
$ iperf -c localhost -r
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
------------------------------------------------------------
Client connecting to localhost, TCP port 5001
TCP window size: 648 KByte (default)
------------------------------------------------------------
[ 5] local 127.0.0.1 port 54401 connected with 127.0.0.1 port 5001
[ 4] local 127.0.0.1 port 5001 connected with 127.0.0.1 port 54401
[ ID] Interval Transfer Bandwidth
[ 5] 0.0-10.0 sec 50.3 GBytes 43.2 Gbits/sec
[ 4] 0.0-10.0 sec 50.3 GBytes 43.2 Gbits/sec
$ iperf -c localhost -r -y C
20140114124826,127.0.0.1,54402,127.0.0.1,5001,5,0.0-10.0,52551090176,42041052917
20140114124826,127.0.0.1,5001,127.0.0.1,54402,4,0.0-10.0,52551090200,41999020136
編輯:您可以找到相關的源代碼這裡:
// TCP Reporting
printf( reportCSV_bw_format,
timestamp,
(stats->reserved_delay == NULL ? ",,," : stats->reserved_delay),
stats->transferID,
stats->startTime,
stats->endTime,
stats->TotalLen,
speed);
} else {
// UDP Reporting
printf( reportCSV_bw_jitter_loss_format,
timestamp,
(stats->reserved_delay == NULL ? ",,," : stats->reserved_delay),
stats->transferID,
stats->startTime,
stats->endTime,
stats->TotalLen,
speed,
stats->jitter*1000.0,
stats->cntError,
stats->cntDatagrams,
(100.0 * stats->cntError) / stats->cntDatagrams, stats->cntOutofOrder );
}
答案2
接受的答案會跳過一個奇怪的欄位:來源和目標 IP+連接埠對之後的欄位:
timestamp,
source_address,
source_port,
destination_address,
destination_port,
XXX, <---- this one
interval,
transferred_bytes,
bits_per_second
接受的答案中的程式碼表示這來自transferID
變數。這裡的一些其他答案似乎認為它代表連接標識符或連接方向。然而,快速瀏覽程式碼表明它transferID
來自一個名為 的全域變數groupID
。這是已初始化歸零:
// Global ID that we increment to be used
// as identifier for SUM reports
int groupID = 0;
然而,快速查看程式碼似乎表明它增加和減少了很多,非常令人困惑。似乎沒有任何定義的常數來說明它的意義。手動測試 ( iperf version 2.0.9 (9 Sept 2016) pthreads
) 顯示連線之間重複使用的數量。所以我想這個故事的寓意是…忽略這個數字?或使用iperf3。
答案3
日期和時間、來源IP、來源連接埠、目標IP、目標連接埠、iperf 進程編號、時間間隔、傳輸的資料量(位元組)、頻寬(每秒位元數)、抖動(毫秒)、遺失資料報數、總數發送的資料報數量、遺失百分比、無序接收的資料報數量
我從以下管道得到上述資訊:
答案4
這是一個簡單的演示,使用 CSV 值並循環運行檢查是否滿足給定的 bps。
我還發現上面的答案中存在一個額外的字段,其值為 3/4/5。 4和5好像是方向。 3 我不知道這意味著什麼。無論如何,如果這有幫助的話:
#!/usr/bin/python
import sys
import subprocess
from subprocess import Popen
def runProcess(exe):
p = subprocess.Popen(exe, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while(True):
retcode = p.poll() #returns None while subprocess is running
line = p.stdout.readline()
yield line
if(retcode is not None):
break
#
# do an iperf to a peer and check the bps calculated is at least
# what we asked for
#
def peer_run_until_target_bps_not_met (peer, sample_period, target_bps):
debug = 0
target_kbps = target_bps / 1024.0
target_mbps = target_bps / (1024.0 * 1024.0)
cmd = "iperf -c %s -t %d -i %d -y C" % (peer, sample_period, sample_period)
while (True):
bps=0
for line in runProcess(cmd.split()):
if line == "":
break
if (debug):
print "timestamp %s" % line.split(',')[0]
print "source_address %s" % line.split(',')[1]
print "source_port %s" % line.split(',')[2]
print "destination_address %s" % line.split(',')[3]
print "destination_port %s" % line.split(',')[4]
#
# "3" ???
# "5" indicates client -> server connection,
# "4" indicates "server -> client"
#
print "direction %s" % line.split(',')[5]
print "interval %s" % line.split(',')[6]
print "transferred_bytes %s" % line.split(',')[7]
print "bits_per_second %s" % line.split(',')[8]
transferred_bytes = float(line.split(',')[7])
bps = (transferred_bytes * 8) / float(sample_period)
kbps = bps / 1024.0
mbps = bps / (1024.0 * 1024.0)
print "OK: %12.2f bps / %10.2f Kbps / %10.2f Mbps (target %-10.2f Mbps)" % (bps, kbps, mbps, target_mbps)
if (bps < target_bps):
print "FAILED: need %.2f bps / %.2fKbps / %.2f Mbps" % \
(target_bps, target_kbps, target_mbps)
return
peer_run_until_target_bps_not_met("10.2.0.0", 5, 0.2 * 1024 * 1024) # 10 Mbps