#!/usr/bin/python # poor man's script to time page loads throgh a proxy # rodrick.brown@gmail.com 04/04/2006 import os import sys import string import time check_urls = ['www.sun.com','www.fxcm.com','www.google.com', 'www.mtv.com','www.vh1.com','www.cbs.com'] proxy_host = 'http://psdemo1.page-sense.com:9096' wget = '/usr/local/bin/wget' proxy_log = 'wget_proxy.log' noproxy_log = 'wget_noproxy.log' #proxy_host = 'http://squid.airimba.com:8080' wget_data = {} time_now = list(time.localtime()) def dump_wget_log(logfile): filename = open(logfile,'a') filename.write("---- %d-%.2d-%.2d %.2d:%.2d:%.2d ----\n" % (time_now[0],time_now[1],time_now[2],time_now[3],time_now[4],time_now[5])) filename.write("hostname\t| duration\n") for hostname,duration in wget_data.items(): filename.writelines("%s\t| %f\n" % (hostname,duration)) def wget_proxy(hosts): os.environ['http_proxy'] = proxy_host time_start = time.time() os.system('%s --proxy=on -q -p %s' % (wget,hosts)) time_end = time.time() wget_data[hosts] = (time_end - time_start) def wget_noproxy(hosts): time_start = time.time() os.system('%s -q -p %s' % (wget,hosts)) time_end = time.time() wget_data[hosts] = (time_end - time_start) def main(): if ( len(sys.argv) > 1 and sys.argv[1] == '-p'): for hosts in check_urls: wget_proxy(hosts) dump_wget_log(proxy_log) print "log written to %s" % proxy_log else: for hosts in check_urls: wget_noproxy(hosts) dump_wget_log(noproxy_log) print "log written to %s" % noproxy_log main()