Module | RubyRunReport__ |
In: |
lib/rubyrun/rubyrun_report__.rb
|
Add an item to performance summary RSS channel
# File lib/rubyrun/rubyrun_report__.rb, line 37 37: def add_perf_summary_rss_item(req_count) 38: return unless $rubyrun_host_with_port # Server started but no request yet 39: # First, Throughput Summary 40: $rubyrun_throughput.shift if $rubyrun_throughput.length == $rubyrun_report_shift_age 41: index = $rubyrun_throughput.length 42: $rubyrun_throughput[index] = [Time.now, req_count.to_f/$rubyrun_report_timer*60] 43: bar_content = '' 44: label_content = '' 45: max = ($rubyrun_throughput.max {|a,b| a[1] <=> b[1]})[1] 46: max = 1 if max == 0 # Avoid divided by zero below 47: $rubyrun_throughput.reverse! 48: $rubyrun_report_shift_age.times { |i| 49: if $rubyrun_throughput[i] 50: bar_content += sprintf(THROUGHPUT_BAR_TABLE, sprintf('%0.0f',$rubyrun_throughput[i][1]), ($rubyrun_throughput[i][1]*250/max).to_i) 51: label_content += sprintf(THROUGHPUT_LABEL_TABLE, $rubyrun_throughput[i][0].strftime("%H:%M %b %d")) 52: else 53: bar_content += sprintf(THROUGHPUT_BAR_TABLE, '', 0) 54: label_content += sprintf(THROUGHPUT_LABEL_TABLE, '') 55: end 56: } 57: $rubyrun_throughput.reverse! 58: html_content = THROUGHPUT_HTML.sub(/%THROUGHPUT_BAR_TABLE%/, bar_content) 59: html_content.sub!(/%THROUGHPUT_LABEL_TABLE%/, label_content) 60: html_content.sub!(/%APPS_NAME%/,Rails::Configuration.new.root_path.split('/').last) 61: html_content.sub!(/%TIMESTAMP%/,Time.now.strftime("%H:%M:%S %m/%d/%Y")) 62: # Second, Top Slowest Requests 63: results = sort_performance_metrics 64: table_content = '' 65: 10.times { |i| 66: break unless results[i] 67: table_content += sprintf(TOP_SLOWEST_REQUESTS_TABLE, results[i][0], 68: (150*results[i][1][0]/results[0][1][0]).round, results[i][1][0]) 69: } 70: (html_content << TOP_SLOWEST_REQUESTS_HTML).sub!(/%TOP_SLOWEST_REQUESTS_TABLE%/,table_content) 71: # Third, Request Performance Breakdown 72: odd = true 73: table_content = '' 74: results.each { |metrics| 75: table_content += sprintf("#{odd ? REQ_PERF_BREAKDOWN_TABLE_ODD : REQ_PERF_BREAKDOWN_TABLE_EVEN}", metrics[0], metrics[1][6], metrics[1][0], metrics[1][1], (metrics[1][1]/metrics[1][0]*100).round, metrics[1][2], (metrics[1][2]/metrics[1][0]*100).round, metrics[1][3], (metrics[1][3]/metrics[1][0]*100).round, metrics[1][5], (metrics[1][5]/metrics[1][0]*100).round, metrics[1][4]) 76: odd = odd ? false : true 77: } 78: (html_content << REQ_PERF_BREAKDOWN_HTML).sub!(/%REQ_PERF_BREAKDOWN_TABLE%/,table_content); 79: $rubyrun_perf_summary_rss.add_item(RubyRunRSS::RUBYRUN_RSS_PERF_SUMMARY_ITEM_TITLE, 80: RubyRunRSS::RUBYRUN_RSS_PERF_SUMMARY_ITEM_DESCRIPTION, html_content) 81: end
Add entries to transaction log CSV file metrics structure metrics[0] Thread ID metrics[1] Timestamp of the request metrics[2] URL metrics[3] Controller name metrics[4] Action name metrics[5] Response time metrics[6] Action time metrics[7] Database IO time metrics[8] View time metrics[9] Uncaptured time metrics[10] Dispatch wait time CSV format is URL, thread ID, timestamp, response time, action time,
database io time, view time, dispatch wait time, uncaptured time
# File lib/rubyrun/rubyrun_report__.rb, line 28 28: def add_txn_log_csv_item(buffer) 29: return if buffer.length == 0 30: $rubyrun_txn_log_reporter.info "\n----- Transaction Log at #{Time.now.ctime} -----" 31: buffer.each { |metrics| 32: $rubyrun_txn_log_reporter.info "#{metrics[2]},#{metrics[0]},#{metrics[1].strftime("%H:%M:%S")}.#{("%.3f" % metrics[1].to_f).split('.')[1]} #{metrics[1].strftime("%m/%d/%y")},#{sprintf("%0.3f", metrics[5])},#{sprintf("%0.3f", metrics[6])},#{sprintf("%0.3f", metrics[7])},#{sprintf("%0.3f", metrics[8])},#{sprintf("%0.3f", metrics[10])},#{sprintf("%0.3f", metrics[9])}" 33: } 34: end
Create the CSV files
# File lib/rubyrun/rubyrun_report__.rb, line 104 104: def create_csv_files 105: $rubyrun_txn_log_reporter = Logger.new("#{@rubyrun_report_folder}/#{File.basename($0, ".*")}_#{$$.to_s}_txn_log.csv", shift_age = 10, shift_size = 4096000) 106: $rubyrun_txn_log_reporter.info "#\n# Format: [URL],[thread ID],[timestamp],[response time],[action time],[database IO time],[view time],[dispatch delay time],[uncaptured time]\n#" 107: end
Create the folder for keeping RSS XML file and HTML files Create the RSS channel
# File lib/rubyrun/rubyrun_report__.rb, line 85 85: def create_rss_channels 86: rss_folder = $rubyrun_config['RSS_PATH'] ? $rubyrun_config['RSS_PATH'] \ 87: : "#{Rails::Configuration.new.root_path}/public/#{RubyRunRSS::RUBYRUN_RSS_FOLDER}" 88: begin 89: Dir.mkdir(rss_folder) unless File.exist?(rss_folder) 90: rescue Exception 91: rss_folder = @rubyrun_report_folder 92: end 93: $rubyrun_perf_summary_rss = RubyRunRSS.new \ 94: RubyRunRSS::RUBYRUN_RSS_PERF_SUMMARY_CHANNEL_TITLE, 95: RubyRunRSS::RUBYRUN_RSS_PERF_SUMMARY_CHANNEL_DESCRIPTION, 96: rss_folder, 97: RubyRunRSS::RUBYRUN_RSS_PERF_SUMMARY_CHANNEL_FILENAME, 98: RubyRunRSS::RUBYRUN_RSS_PERF_SUMMARY_CHANNEL_ITEM_FILENAME \ 99: unless $rubyrun_perf_summary_rss 100: $rubyrun_throughput = Array.new 101: end