Skip to content

Instantly share code, notes, and snippets.

@esirK
Created October 7, 2019 17:58
Show Gist options
  • Save esirK/594142a21b8c996d2a1f3833f90f05e7 to your computer and use it in GitHub Desktop.
Save esirK/594142a21b8c996d2a1f3833f90f05e7 to your computer and use it in GitHub Desktop.
# Network latency
"""
Here we will ping google at an interval of five seconds for five times and record the
min response time, average response time, and the max response time.
"""
ping_result = subprocess.run(['ping', '-i 5', '-c 5', 'google.com'], stdout=subprocess.PIPE).stdout.decode('utf-8').split('\n')
min, avg, max = ping_result[-2].split('=')[-1].split('/')[:3]
statistics['network_latency'] = dict(
{
'min': min.strip(),
'avg': avg.strip(),
'max': max.strip(),
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment