Module: LogStats::Requests::TextOutput
- Defined in:
- lib/log_stats/requests/text_output.rb
Class Method Summary collapse
- .print(data, event_config) ⇒ Object
- .print_heading(heading) ⇒ Object
- .print_kpi(kpi) ⇒ Object
- .print_percentages(total_lines_count, grouped_lines) ⇒ Object
- .print_request(request) ⇒ Object
- .print_top_list(stats, metric, options = {}) ⇒ Object
Class Method Details
.print(data, event_config) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/log_stats/requests/text_output.rb', line 4 def self.print(data, event_config) print_heading("KPIs") print_kpi(data[:kpi]) print_heading("STATUS CODES") print_percentages(data[:requests_count], data[:requests_by_status]) print_heading("HEROKU ERROR CODES") print_percentages(data[:requests_count], data[:requests_by_code]) = { direction: 1, limit: event_config[:top_list_limit], apdex_goal: event_config[:apdex_goal] } print_heading("POPULARITY TOP LIST") print_top_list(data[:stats], Stats.method(:popularity_metric), ) print_heading("APDEX TOP LIST") print_top_list(data[:stats], Stats.method(:apdex_metric), .merge(direction: -1)) print_heading("DURATION TOP LIST") print_top_list(data[:stats], Stats.method(:duration_metric), ) print_heading("ERROR RATE TOP LIST") print_top_list(data[:stats], Stats.method(:error_rate_metric), ) print_heading("TIMEOUT TOP LIST") print_top_list(data[:stats], Stats.method(:timeout_metric), ) data[:requests_by_status].each do |status, requests| print_heading("REQUESTS - STATUS #{status}") Stats.requests_by_duration(requests).each do |request| print_request(request) end end end |
.print_heading(heading) ⇒ Object
73 74 75 76 77 |
# File 'lib/log_stats/requests/text_output.rb', line 73 def self.print_heading(heading) puts "\n-----------------------------------------------------------" puts heading puts "-----------------------------------------------------------\n\n" end |
.print_kpi(kpi) ⇒ Object
80 81 82 83 84 |
# File 'lib/log_stats/requests/text_output.rb', line 80 def self.print_kpi(kpi) kpi.each do |key, value| puts "#{key}: #{value}" end end |
.print_percentages(total_lines_count, grouped_lines) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/log_stats/requests/text_output.rb', line 54 def self.print_percentages(total_lines_count, grouped_lines) grouped_lines.select { |key, _| !key.nil? }.each do |key, lines| percent = (lines.size.to_f*100/total_lines_count).round(4) puts "#{key} #{percent}%" end end |
.print_request(request) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/log_stats/requests/text_output.rb', line 43 def self.print_request(request) parts = [(request[:method] == "GET" ? nil : request[:method]), request[:path], request[:service], request[:code] ].compact if parts.size > 1 puts parts.join(" ") end end |
.print_top_list(stats, metric, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/log_stats/requests/text_output.rb', line 61 def self.print_top_list(stats, metric, = {}) Stats.stats_by_metric(stats, metric, [:direction])[0, [:limit]].each do |stat| apdex = Stats.apdex_metric(stat).round(2) puts [stat[:id], metric.call(stat), "count=#{stat[:count]}", "apdex=#{apdex}", (apdex >= [:apdex_goal] ? "OK" : "SLOW") ].join(' ') end end |