Created
June 29, 2015 13:52
-
-
Save valhallasw/aaf79b1617b27d9f9d4a to your computer and use it in GitHub Desktop.
ssh RTT tester
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
# (C) 2015 Merlijn van Deen (valhallasw) | |
# Licensed under the MIT license | |
# | |
# pip install paramiko | |
# | |
# | |
import paramiko, time | |
import argparse | |
import math | |
parser = argparse.ArgumentParser(description='Measure SSH RTTs') | |
parser.add_argument('--host', help='the host to connect to', default='tools-login.wmflabs.org') | |
parser.add_argument('--user', help='the username to use', default='valhallasw') | |
parser.add_argument('--mode', choices=['char', 'line'], help='Measurement mode: single character or line-based', default='char') | |
parser.add_argument('--sleep', help='time to sleep between sends', default=0, type=float) | |
parser.add_argument('--tries', help='amount of RTTs to measure', default=1000, type=int) | |
parser.add_argument('--file', help='File to store measured RTTs (ms)', default=None) | |
args = parser.parse_args() | |
client = paramiko.SSHClient() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
client.connect(args.host, username='valhallasw') | |
stdin, stdout, stderr = client.exec_command('cat', bufsize=0) | |
if args.file: | |
f = open(args.file, 'w') | |
else: | |
f = None | |
for i in range(args.tries): | |
time.sleep(args.sleep) | |
if args.mode == 'line': | |
stdin.write(str(time.time()) + "\n") | |
sentat = stdout.readline() | |
deltat = time.time() - float(sentat.strip()) | |
elif args.mode == 'char': | |
stdin.write("a") | |
sentat = time.time() | |
assert(stdout.read(1) == "a") | |
deltat = time.time() - sentat | |
print (deltat)*1000, "ms" | |
if f: | |
f.write(str(deltat * 1000) + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment