Created
October 25, 2022 22:26
-
-
Save alexswerner/cbfd67ce4a6229ccb8a911a0951f102e to your computer and use it in GitHub Desktop.
iperf3-log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# Executes iperf3 repeatedly and extracts the connection speed from the results | |
import json | |
import subprocess | |
import sys | |
import datetime | |
import time | |
import argparse | |
wait = 300 | |
parser = argparse.ArgumentParser( | |
description='Run iperf3 in a loop and summarize output', | |
usage="usage example: iperf-log --wait N [-4|-6] [-r] -c hostname" | |
) | |
parser.add_argument('--wait', | |
dest='wait', | |
action='store', | |
default=300, | |
type=int, | |
help='wait time in seconds') | |
args, iperf_args = parser.parse_known_args() | |
while True: | |
try: | |
results = subprocess.check_output( | |
["iperf3","--json",*iperf_args]) | |
parsed_results = json.loads(results) | |
print("{0:} - {1:.2f}Mbit/s".format( | |
datetime.datetime.now(), | |
float(parsed_results["end"]["sum_sent"]["bits_per_second"])/1e6 ) ) | |
except Exception as ex: | |
print("Failed run {}".format(ex)) | |
time.sleep(args.wait) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment