summaryrefslogtreecommitdiffstats
path: root/ping-ssh
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2019-01-04 13:54:00 +0100
committerFlorian Pritz <bluewind@xinu.at>2019-01-04 13:54:00 +0100
commitd4b107f5035413bcf93f24a523a6f8b695ba6b92 (patch)
tree74f53d2c3cbf7d71264d1c9239d6af21f3038724 /ping-ssh
parentf2c64faeecf602c024b81fcc3760981e36de45f4 (diff)
downloadbin-d4b107f5035413bcf93f24a523a6f8b695ba6b92.tar.gz
bin-d4b107f5035413bcf93f24a523a6f8b695ba6b92.tar.xz
Add new scripts
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'ping-ssh')
-rwxr-xr-xping-ssh47
1 files changed, 47 insertions, 0 deletions
diff --git a/ping-ssh b/ping-ssh
new file mode 100755
index 0000000..a35e44c
--- /dev/null
+++ b/ping-ssh
@@ -0,0 +1,47 @@
+#!/usr/bin/python
+
+from timeit import default_timer as timer
+import statistics
+import subprocess
+import sys
+
+if len(sys.argv) <= 3:
+ print("usage: ping-ssh <host> <repeat count> <string>")
+ sys.exit(1)
+
+host = sys.argv[1]
+repeat = int(sys.argv[2])
+ping_string = sys.argv[3]
+
+def ping(stdin, stdout):
+ ping_bytes = (ping_string+"\n").encode()
+ stdin.write(ping_bytes)
+ result = stdout.read(len(ping_bytes))
+ assert result == ping_bytes
+
+proc = subprocess.Popen(['ssh', host, 'cat'],
+ bufsize=0,
+ stdout=subprocess.PIPE, stdin=subprocess.PIPE)
+
+# ping once to ensure the "connection" is ready. Without this the first ping
+# would be much slower than all others due to ssh/cat starting up
+ping(proc.stdin, proc.stdout)
+
+times = []
+
+for i in range(repeat):
+ start = timer()
+ ping(proc.stdin, proc.stdout)
+ end = timer()
+ time = end - start
+ times.append(time)
+ print("{:.5f}ms".format(time * 1000))
+
+print("")
+print("mean: {:.5f}ms".format(statistics.mean(times) * 1000))
+print("median: {:.5f}ms".format(statistics.median(times) * 1000))
+print("min: {:.5f}ms".format(min(times) * 1000))
+print("max: {:.5f}ms".format(max(times) * 1000))
+
+proc.stdin.close()
+proc.wait()