Python Forum
python read iperf log and parse throughput
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python read iperf log and parse throughput
#1
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.


 #!/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
Reply


Messages In This Thread
python read iperf log and parse throughput - by jacklee26 - Aug-26-2022, 01:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 231 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  parse/read from file seperated by dots giovanne 5 1,160 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  [split] Parse Nested JSON String in Python mmm07 4 1,600 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Read directory listing of files and parse out the highest number? cubangt 5 2,446 Sep-28-2022, 10:15 PM
Last Post: Larz60+
  How to parse a live feed in Python? Daring_T 2 4,203 Jan-20-2022, 04:17 AM
Last Post: Daring_T
  Parse a REST API call using Python GKT 1 1,934 May-07-2020, 04:15 AM
Last Post: buran
  print the result of iperf log jacklee26 3 3,066 Feb-23-2020, 04:51 AM
Last Post: Larz60+
  Read csv file, parse data, and store in a dictionary markellefultz20 4 4,624 Nov-26-2019, 03:33 PM
Last Post: DeaD_EyE
  Python Library to parse RAML 1.0 sameekb 1 3,257 Jan-21-2019, 04:55 PM
Last Post: Larz60+
  How to parse the data in python sandy 10 5,330 Jan-15-2019, 05:50 PM
Last Post: sandy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020