def get(self): hostname = "http://" + os.environ['PATH_INFO'].replace("/report/", "") self.response.headers["Content-Type"] = "text/html" self.response.out.write("<html><body><h2>report page for %s</h2>\n\n" % hostname) m = MonitorSample.all().filter("url =", hostname) # .order("date") foo = m.fetch(300) if len(foo) == 0: self.response.out.write("<p>no data for hostname %s</p>" % hostname) return self.response.out.write("<p>samples: %s</p>" % len(foo)) mean = 0.00 num = 0 stddev = 0.00 #chd=t:27,25,60,31,25,39,25, #31,26,28,80,28,27,31,27, #29,26,35,70,25 charturl = """http://chart.apis.google.com/chart?chs=250x100&cht=ls&chtt=response_time&chxt=x,y&chd=t:""" chartdata = '' for s in foo: #self.response.out.write("<li>sample: %s %s</p>" % (s.date, s.responsetime)) num += 1 mean += s.responsetime chartdata += '%.0f,' % (s.responsetime*100) # haha, dirty #if num > 500: # chartdata = chartdata[ chartdata.find(",")+1:] mean = mean / float(num) charturl += chartdata[:-1] #self.response.out.write(charturl) self.response.out.write("<p>mean response time: %.3fs</p>" % (mean)) self.response.out.write("<br/>") self.response.out.write('<img src="%s" />' % charturl) self.response.out.write('</body></html>')
try: conn = httplib.HTTPConnection(urlparts.netloc) except Exception, e: print "ERROR: Unable to connect to %s. Exepction: %s" % (urlparts.netloc, e) conn_stop = time.time() t_start = time.time() try: conn.request("GET", urlparts.path, {}, headers) r1 = conn.getresponse() r1.read() except Exception, e: print "ERROR: unable to request. error: %s" % e t_stop = time.time() t_connect = conn_stop - conn_start t_fetch = t_stop - t_start t_totals = t_connect + t_fetch print "%.3f %.3f %.3f" % (t_connect, t_fetch, t_totals) sample = MonitorSample() sample.url = url sample.responsetime = t_totals sample.put() if __name__ == "__main__": print "Content-Type: text/plain\n" monitor_url = "http://" + os.environ['PATH_INFO'].replace("/mon/http/", "") run(monitor_url)