My favorites | Sign in
Project Logo
          
Changes to /trunk/rrd_feeder_http.py
r18 vs. r19   Edit
  Compare: vs.   Format:
Revision r19
Go to: 
Project members, sign in to write a code review
/trunk/rrd_feeder_http.py   r18 /trunk/rrd_feeder_http.py   r19
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2008 Corey Goldberg (corey@goldb.org) 2 # Copyright (c) 2008 Corey Goldberg (corey@goldb.org)
3 # 3 #
4 # RRDTool HTTP Performance Meter (Data Feeder/Grapher) 4 # RRDTool HTTP Performance Meter (Data Feeder/Grapher)
5 5
6 6
7 import rrd 7 import rrd
8 import time 8 import time
9 import sys 9 import sys
10 import httplib 10 import httplib
11 11
12 12
13 host = 'www.python.org' 13 host = 'www.python.org'
14 path = '/' 14 path = '/'
15 use_ssl = False 15 use_ssl = False
16 16
17 interval = 10 17 interval = 10
18 rrd_file = 'test.rrd' 18 rrd_file = 'test.rrd'
19 19
20 20
21 def main(): 21 def main():
22 my_rrd = rrd.RRD(rrd_file, 'Response Time') 22 my_rrd = rrd.RRD(rrd_file, 'Response Time')
23 while True: 23 while True:
24 start_time = time.clock() 24 start_time = time.clock()
25 try: 25 try:
26 send(host) 26 send(host)
27 except: 27 except:
28 print 'failed request' 28 print 'failed request'
29 end_time = time.clock() 29 end_time = time.clock()
30 raw_latency = (end_time - start_time) 30 raw_latency = (end_time - start_time)
31 expire_time = (interval - raw_latency) 31 expire_time = (interval - raw_latency)
32 latency = ('%.3f' % raw_latency) 32 latency = ('%.3f' % raw_latency)
33 try: 33 try:
34 my_rrd.update(latency) 34 my_rrd.update(latency)
35 except: 35 except:
36 print 'can not find RRD file to update' 36 print 'error updating RRD'
37 sys.exit() 37 sys.exit()
38 my_rrd.graph(60) 38 my_rrd.graph(60)
39 print latency 39 print latency
40 if expire_time > 0: 40 if expire_time > 0:
41 time.sleep(expire_time) 41 time.sleep(expire_time)
42 42
43 43
44 def send(host): 44 def send(host):
45 if use_ssl: 45 if use_ssl:
46 conn = httplib.HTTPSConnection(host) 46 conn = httplib.HTTPSConnection(host)
47 else: 47 else:
48 conn = httplib.HTTPConnection(host) 48 conn = httplib.HTTPConnection(host)
49 try: 49 try:
50 conn.request('GET', path) 50 conn.request('GET', path)
51 conn.getresponse().read() 51 conn.getresponse().read()
52 except: 52 except:
53 raise 53 raise
54 54
55 55
56 if __name__ == '__main__': 56 if __name__ == '__main__':
57 main() 57 main()
58 58
Hosted by Google Code