Class: InternetHakai::TsvReporter
- Inherits:
-
Reporter
- Object
- BaseHandler
- Reporter
- InternetHakai::TsvReporter
- Defined in:
- lib/internethakai/reporter.rb
Overview
TSV形式で保存するクラス
Constant Summary collapse
- UNIQUE_BY_THREAD =
false
Instance Method Summary collapse
Methods inherited from Reporter
Methods inherited from BaseHandler
clear, clearall, get_class, get_config, get_handler, get_instance, get_instance_thread, get_thread_id, #initialize, #on_create, set_config, set_thread_id, unique_by_thread?
Constructor Details
This class inherits a constructor from InternetHakai::BaseHandler
Instance Method Details
#init_filename(starttime) ⇒ Object
35 36 37 |
# File 'lib/internethakai/reporter.rb', line 35 def init_filename starttime @filename = "report_#{starttime}.tsv" end |
#run(record) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/internethakai/reporter.rb', line 38 def run record super if not record @logger.run("no rocord\n", 2) exit -1 end keys = record.keys.to_a.sort strResultTSV = "Path\tCount\tAvgResponse(ms)\tMinResponse(ms)\tMaxResponse(ms)\tAvgContentLength\tError%\tHTTP_STATUS_CODE\ttime(ms)\n" rank_avg_time = [] sum_avg_time = 0 rank_error_per = [] sum_error = 0 sum_access = 0 if keys.nil? @logger.run("cannot show report\n", 2) exit -1 end keys.to_a.each do |key| v = record[key] next if v[:accesscount] == 0 avg_res = v[:totaltime] * 1000.0 / v[:accesscount] error_per = (v[:errorcount].to_f / v[:accesscount])*100 rank_avg_time << [key, avg_res, v[:accesscount], v[:min]*1000.0] sum_avg_time += v[:totaltime] * 1000.0 rank_error_per << [key, error_per, v[:accesscount]] sum_error += v[:errorcount] sum_access += v[:accesscount] strResultTSV += key + "\t" + # URL v[:accesscount].to_s + "\t" + # COUNT format( '%f', avg_res ) + "\t" + # AVG format('%f', v[:min].to_f*1000) + "\t" + format('%f', v[:max].to_f*1000) + "\t" + format( '%d', v[:size] / v[:accesscount] ) + "\t" + # AVG (error_per).to_s + "\t" # ERROR% status_code = [] res_time =[] v.keys.each do |v_key| if(v_key.to_s =~ /^status:/) status_code << "#{v_key}: #{v[v_key]}" end if(v_key.to_s =~ /^time:/) res_time << "#{v_key}: #{v[v_key]}" end end strResultTSV += status_code.sort.join(",") + "\t" # HTTP_STAT strResultTSV += res_time.sort.join(",") # RESPONSE TIME strResultTSV += "\n" end if @config["save_report"] save strResultTSV fpath = File::join(@dir, @filename) @logger.run("save to:"+fpath+"\n", 2) end #ranking rank_error_per = rank_error_per.sort_by{|p|p[1]}.reverse.slice(0,@config["ranking"]).to_a rank_avg_time = rank_avg_time.sort_by{|p|p[1]}.reverse.slice(0,@config["ranking"]).to_a rank_min_time = rank_avg_time.sort_by{|p|p[3]}.reverse.slice(0,@config["ranking"]).to_a @logger.run("MinResponse Worst:\n", 2) rank = 1 rank_min_time.each do |p| @logger.run("\t#{rank}: #{p[0]} #{p[3]} #{p[2]}\n", 2) rank += 1 end @logger.run("AvgResponse Worst:\n", 2) rank = 1 rank_avg_time.each do |p| @logger.run("\t#{rank}: #{p[0]} #{p[1]} #{p[2]}\n", 2) rank += 1 end @logger.run("AvgResponse Total:\n", 2) @logger.run("\t#{sum_avg_time.to_f / sum_access}\n", 2) @logger.run("ErrorRate Worst:\n", 2) rank = 1 rank_error_per.each do |p| @logger.run("\t#{rank}: #{p[0]} #{p[1]} #{p[2]}\n", 2) rank += 1 end @logger.run("ErrorRate Total:\n", 2) @logger.run("\t#{(sum_error.to_f / sum_access)*100.0}\n", 2) if(@config["show_report"]) @logger.run(strResultTSV, 2) end end |
#save(str) ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/internethakai/reporter.rb', line 132 def save str begin fpath = File::join(@dir, @filename) File::open(fpath, "w") do |io| io.print str end rescue raise $! end end |