1#!/usr/bin/ruby 2# lasthit, part of iExploder 3# 4# Shows statistics about recent agents that have tested with iExploder. 5# It takes all or part of an apache logfile via stdin, and outputs a list 6# of all the agents who tested within that section, what their last test 7# was, and how many tests they have done. 8 9# The usefulness is finding out where a browser crashed. 10 11 12hostHash = Hash.new 13 14if (ARGV[0]) 15 file = File.open(ARGV[0]) 16else 17 file = $stdin 18end 19 20file.readlines.each { |line| 21 if (line =~ /^(.*?) .*iexploder.*?test=(\d+).* HTTP.* \"(.*?)\"$/) 22 host = $1 23 testnum = $2 24 agent = $3 25 if (! hostHash[host]) 26 hostHash[host] = Hash.new 27 end 28 if (! hostHash[host][agent]) 29 hostHash[host][agent] = Hash.new 30 hostHash[host][agent]['total'] = 0 31 end 32 33 hostHash[host][agent]['last'] = testnum 34 if line =~ /subtest=(\d+)/ 35 hostHash[host][agent]['subtest'] = $1 36 else 37 hostHash[host][agent]['subtest'] = '' 38 end 39 hostHash[host][agent]['total'] = hostHash[host][agent]['total'] + 1 40 end 41} 42 43printf("%14.14s | %8.8s | %3.3s | %8.8s | %s\n", 44 "IP", "Test", "SubTest", "Total", "Agent") 45puts "---------------------------------------------------------------------------" 46hostHash.each_key { |host| 47 48 hostHash[host].each_key { |agent| 49 printf("%14.14s | %8.8s | %3.3s | %8.8s | %s\n", 50 host, hostHash[host][agent]['last'], hostHash[host][agent]['subtest'], hostHash[host][agent]['total'], agent); 51 } 52} 53 54