Skip to content

Instantly share code, notes, and snippets.

@alexswerner
Created October 25, 2022 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexswerner/cbfd67ce4a6229ccb8a911a0951f102e to your computer and use it in GitHub Desktop.
Save alexswerner/cbfd67ce4a6229ccb8a911a0951f102e to your computer and use it in GitHub Desktop.
iperf3-log
#!/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