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
#3
Note: no error checking added
def file_last_line(file_path):
    line = ""
    with open(file_path, "r") as file:
        for line in file:
            pass
    return line.strip()


def throughput_text(throughput_line):
    throughput = throughput_line.split(" ")[-3]
    rounded_throughput = round(float(throughput))
    state = "pass" if rounded_throughput < 100 else "Fail"
    return (
       f"####Test4:Iperf Result: {state}, Throughput:{rounded_throughput}.0 Mbps ####\n"
        f"{'='*20}Iperf3 Result{'='*20}\n"
        f"{throughput_line}\n"
        f"{'='*50}\n"
        f"Iperf Throughput:{throughput}GBytes,rounded=>{rounded_throughput}.0 Gbps. Result PASS\n"
    )


def main():
    last_line = file_last_line(iperf3.txt")
    text = throughput_text(last_line)
    with open(testresult.txt", "a+") as file:
        file.write(text)


if __name__ == "__main__":
    main()
jacklee26 likes this post
Reply


Messages In This Thread
RE: python read iperf log and parse throughput - by Yoriz - Aug-26-2022, 03:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  parse/read from file seperated by dots giovanne 5 2,340 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  [split] Parse Nested JSON String in Python mmm07 4 2,836 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Read directory listing of files and parse out the highest number? cubangt 5 5,439 Sep-28-2022, 10:15 PM
Last Post: Larz60+
  How to parse a live feed in Python? Daring_T 2 8,755 Jan-20-2022, 04:17 AM
Last Post: Daring_T
  Parse a REST API call using Python GKT 1 2,614 May-07-2020, 04:15 AM
Last Post: buran
  print the result of iperf log jacklee26 3 4,181 Feb-23-2020, 04:51 AM
Last Post: Larz60+
  Read csv file, parse data, and store in a dictionary markellefultz20 4 6,182 Nov-26-2019, 03:33 PM
Last Post: DeaD_EyE
  Python Library to parse RAML 1.0 sameekb 1 4,048 Jan-21-2019, 04:55 PM
Last Post: Larz60+
  How to parse the data in python sandy 10 7,139 Jan-15-2019, 05:50 PM
Last Post: sandy
  i woule a way to parse a line python source like split Skaperen 2 3,556 Nov-11-2018, 07:35 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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