Class: RequestLogAnalyzer::Aggregator::Summarizer
- Defined in:
- lib/request_log_analyzer/aggregator/summarizer.rb
Defined Under Namespace
Classes: Definer
Instance Attribute Summary collapse
-
#trackers ⇒ Object
readonly
Returns the value of attribute trackers.
-
#warnings_encountered ⇒ Object
readonly
Returns the value of attribute warnings_encountered.
Attributes inherited from Base
Instance Method Summary collapse
-
#aggregate(request) ⇒ Object
Pass all requests to trackers and let them update if necessary.
-
#finalize ⇒ Object
Call finalize on all trackers.
-
#has_log_ordering_warnings? ⇒ Boolean
Returns true if there were any log ordering warnings.
-
#has_warnings? ⇒ Boolean
Returns true if there were any warnings generated by the trackers.
-
#initialize(source, options = {}) ⇒ Summarizer
constructor
Initialize summarizer.
-
#prepare ⇒ Object
Call prepare on all trackers.
-
#report(output) ⇒ Object
Call report on all trackers.
-
#report_footer(output) ⇒ Object
Generate report footer.
-
#report_header(output) ⇒ Object
Generate report header.
-
#save_results_dump(filename) ⇒ Object
Saves the results of all the trackers in YAML format to a file.
- #setup ⇒ Object
-
#to_yaml ⇒ Object
Exports all the tracker results to YAML.
-
#warning(type, _message, _lineno) ⇒ Object
Store an encountered warning
typeType of warningmessageWarning messagelinenoThe line on which the error was encountered.
Methods inherited from Base
Constructor Details
#initialize(source, options = {}) ⇒ Summarizer
Initialize summarizer. Generate trackers from speciefied source.file_format.report_trackers and set them up
42 43 44 45 46 47 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 42 def initialize(source, = {}) super(source, ) @warnings_encountered = {} @trackers = source.file_format.report_trackers setup end |
Instance Attribute Details
#trackers ⇒ Object (readonly)
Returns the value of attribute trackers.
37 38 39 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 37 def trackers @trackers end |
#warnings_encountered ⇒ Object (readonly)
Returns the value of attribute warnings_encountered.
38 39 40 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 38 def warnings_encountered @warnings_encountered end |
Instance Method Details
#aggregate(request) ⇒ Object
Pass all requests to trackers and let them update if necessary. request The request to pass.
60 61 62 63 64 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 60 def aggregate(request) @trackers.each do |tracker| tracker.update(request) if tracker.should_update?(request) end end |
#finalize ⇒ Object
Call finalize on all trackers. Saves a YAML dump if this is set in the options.
67 68 69 70 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 67 def finalize @trackers.each { |tracker| tracker.finalize } save_results_dump([:yaml]) if [:yaml] end |
#has_log_ordering_warnings? ⇒ Boolean
Returns true if there were any log ordering warnings
141 142 143 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 141 def has_log_ordering_warnings? @warnings_encountered[:no_current_request] && @warnings_encountered[:no_current_request] > 0 end |
#has_warnings? ⇒ Boolean
Returns true if there were any warnings generated by the trackers
136 137 138 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 136 def has_warnings? @warnings_encountered.reduce(0) { |result, (_, value)| result += value } > 0 end |
#prepare ⇒ Object
Call prepare on all trackers.
53 54 55 56 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 53 def prepare fail 'No trackers set up in Summarizer!' if @trackers.nil? || @trackers.empty? @trackers.each { |tracker| tracker.prepare } end |
#report(output) ⇒ Object
Call report on all trackers. output RequestLogAnalyzer::Output object to output to
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 90 def report(output) report_header(output) if source.parsed_requests > 0 @trackers.each { |tracker| output.report_tracker(tracker) } else output.puts output.puts('There were no requests analyzed.') end (output) end |
#report_footer(output) ⇒ Object
Generate report footer. output RequestLogAnalyzer::Output object to output to
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 123 def (output) if has_log_ordering_warnings? output.title('Parse warnings') output.puts 'Parsable lines were encountered without a header line before it. It' output.puts 'could be that logging is not setup correctly for your application.' output.puts 'Visit this website for logging configuration tips:' output.puts output.link('http://github.com/wvanbergen/request-log-analyzer/wikis/configure-logging') output.puts end end |
#report_header(output) ⇒ Object
Generate report header. output RequestLogAnalyzer::Output object to output to
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 103 def report_header(output) output.title('Request summary') output.with_style(cell_separator: false) do output.table({ width: 20 }, { font: :bold }) do |rows| source.processed_files.each do |f| rows << ['Processed File:', f] end rows << ['Parsed lines:', source.parsed_lines] rows << ['Skipped lines:', source.skipped_lines] rows << ['Parsed requests:', source.parsed_requests] rows << ['Skipped requests:', source.skipped_requests] rows << ['Warnings:', @warnings_encountered.map { |(key, value)| "#{key}: #{value}" }.join(', ')] if has_warnings? end end output << "\n" end |
#save_results_dump(filename) ⇒ Object
Saves the results of all the trackers in YAML format to a file. filename The file to store the YAML dump in.
74 75 76 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 74 def save_results_dump(filename) File.open(filename, 'w') { |file| file.write(to_yaml) } end |
#setup ⇒ Object
49 50 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 49 def setup end |
#to_yaml ⇒ Object
Exports all the tracker results to YAML. It will call the to_yaml_object method for every tracker and combines these into a single YAML export.
80 81 82 83 84 85 86 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 80 def to_yaml require 'yaml' trackers_export = @trackers.reduce({}) do |export, tracker| export[tracker.title] = tracker.to_yaml_object; export end YAML.dump(trackers_export) end |
#warning(type, _message, _lineno) ⇒ Object
Store an encountered warning type Type of warning message Warning message lineno The line on which the error was encountered
149 150 151 152 |
# File 'lib/request_log_analyzer/aggregator/summarizer.rb', line 149 def warning(type, , _lineno) @warnings_encountered[type] ||= 0 @warnings_encountered[type] += 1 end |