Skip to content

Instantly share code, notes, and snippets.

@fillest
Last active February 11, 2018 12:06
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 fillest/61878186356341fa9391f52bd5d303ae to your computer and use it in GitHub Desktop.
Save fillest/61878186356341fa9391f52bd5d303ae to your computer and use it in GitHub Desktop.
import subprocess
import time
import sys
interval = 2.0
while True:
t1 = time.time()
#http://manpages.ubuntu.com/manpages/trusty/en/man1/curl.1.html
#http://stackoverflow.com/questions/17638026/calculating-server-processing-time-with-curl/29650456#29650456
#https://curl.haxx.se/mail/lib-2011-05/0026.html
subprocess.call("date -u --rfc-3339=seconds | tr -d '\\n'; echo -n ' '; curl --write-out 'st=%{http_code} sz=%{size_download} ip=%{remote_ip}"
" ns^%{time_namelookup} conn^%{time_connect} sent^%{time_pretransfer} firstbyte^%{time_starttransfer} tot=%{time_total}\\n'"
" --silent --show-error --compressed -o /dev/null https://localhost/", shell = True)
sys.stdout.flush()
lat = time.time() - t1
time.sleep(max(0, interval - lat))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment