Aug-26-2022, 01:11 PM
HI
i have a file which is iperf3's log file, I wish to get the Throughput value from the file.
I have written python code and would like to ask for any improvement on the code. MY code might not be good, I literally know it.
Any better way to accomplish it?
basically, I want is read the iperf lof file, and get the throughput value, such as 3.39 Gbits, and get the 3.39 value and print our and write into a new file.
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 127.0.0.1, port 39756
[ 5] local 127.0.0.1 port 5201 connected to 127.0.0.1 port 39758
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 389 MBytes 3.26 Gbits/sec
[ 5] 1.00-2.00 sec 401 MBytes 3.37 Gbits/sec
[ 5] 2.00-3.00 sec 405 MBytes 3.40 Gbits/sec
[ 5] 3.00-4.00 sec 372 MBytes 3.12 Gbits/sec
[ 5] 4.00-5.00 sec 419 MBytes 3.51 Gbits/sec
[ 5] 5.00-6.00 sec 401 MBytes 3.36 Gbits/sec
[ 5] 6.00-7.00 sec 422 MBytes 3.54 Gbits/sec
[ 5] 7.00-8.00 sec 411 MBytes 3.45 Gbits/sec
[ 5] 8.00-9.00 sec 412 MBytes 3.45 Gbits/sec
[ 5] 9.00-10.00 sec 410 MBytes 3.44 Gbits/sec
[ 5] 10.00-10.01 sec 896 KBytes 1.47 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate
[ 5] 0.00-10.01 sec 3.95 GBytes 3.39 Gbits/sec receiver
i have a file which is iperf3's log file, I wish to get the Throughput value from the file.
I have written python code and would like to ask for any improvement on the code. MY code might not be good, I literally know it.
Any better way to accomplish it?
basically, I want is read the iperf lof file, and get the throughput value, such as 3.39 Gbits, and get the 3.39 value and print our and write into a new file.
#!/usr/bin/python result="" last_line="" lastResult_line="" TPT="" with open('iperf3.txt', 'r') as f: last_line = f.readlines() #lastResult_line="".join(last_line[-3:]) #lastResult_line=lastResult_line.strip() last_line=last_line[-1].strip() print("="*30) #print(lastResult_line) #print(last_line) TPT= last_line.split(' ') TPT=TPT[0].split(' ')[-2] value= int(round(float(TPT))) print(f"Orginal Throuhgput value: {TPT} Gbps") print(f"after Round Value: {value}.0 Gbps") if value< 100: print("Iperf result: pass") result="Iperf Result: pass" else: print("Iperf result: Fail") result="Iperf Result: Fail" with open("testresult.txt", "a+") as f: # here, position is already at the end f.write(f"####Test4:{result}, Throughput:{value}.0 Mbps ####\n") f.write(f"{'='*20}Iperf3 Result{'='*20}\n") f.write(f"{last_line}\n") #f.write(f"{lastResult_line}\n") f.write(f"{'='*50}\n") f.write(f"Iperf Throughput:{TPT}GBytes,rounded=>{value}.0 Gbps. Result PASS\n")iperf3.txt:
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 127.0.0.1, port 39756
[ 5] local 127.0.0.1 port 5201 connected to 127.0.0.1 port 39758
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 389 MBytes 3.26 Gbits/sec
[ 5] 1.00-2.00 sec 401 MBytes 3.37 Gbits/sec
[ 5] 2.00-3.00 sec 405 MBytes 3.40 Gbits/sec
[ 5] 3.00-4.00 sec 372 MBytes 3.12 Gbits/sec
[ 5] 4.00-5.00 sec 419 MBytes 3.51 Gbits/sec
[ 5] 5.00-6.00 sec 401 MBytes 3.36 Gbits/sec
[ 5] 6.00-7.00 sec 422 MBytes 3.54 Gbits/sec
[ 5] 7.00-8.00 sec 411 MBytes 3.45 Gbits/sec
[ 5] 8.00-9.00 sec 412 MBytes 3.45 Gbits/sec
[ 5] 9.00-10.00 sec 410 MBytes 3.44 Gbits/sec
[ 5] 10.00-10.01 sec 896 KBytes 1.47 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate
[ 5] 0.00-10.01 sec 3.95 GBytes 3.39 Gbits/sec receiver