-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_speed_avg.py
executable file
·44 lines (39 loc) · 995 Bytes
/
load_speed_avg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/home/sgrosu/anaconda2/bin/python
from __future__ import division
import requests
import time
import sys
import datetime
import socket
if len(sys.argv) < 2:
url = 'http://winonaesolutions.co.uk'
else:
if not sys.argv[1].startswith('http://'):
url = 'http://'+ sys.argv[1]
else:
url = sys.argv[1]
def getIP(d):
"""
This method returns the first IP address string
that responds as the given domain name
"""
try:
data = socket.gethostbyname(d)
ip = repr(data)
return ip
except Exception:
# fail gracefully!
return False
print url
print getIP(url.strip('http://'))
rezlist = []
for i in range(10):
thetime = requests.get(url).elapsed.total_seconds()
rezlist.append(thetime)
print '%s - TTFB: %.2f seconds' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),thetime)
time.sleep(10)
average = (sum(rezlist) / float(len(rezlist)))
print rezlist
print 'average TTFB: %.2f' % average
print 'bye'
exit(0)