Class: LogParserNotifier::RailsRequestNotifier
- Inherits:
-
Object
- Object
- LogParserNotifier::RailsRequestNotifier
- Defined in:
- lib/log_parser_notifier/rails_request_notifier.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(log_file, slow_request_threshold = 500) ⇒ RailsRequestNotifier
constructor
A new instance of RailsRequestNotifier.
- #parse_and_trigger_notifications ⇒ Object
- #parser ⇒ Object
- #statsd ⇒ Object
Constructor Details
#initialize(log_file, slow_request_threshold = 500) ⇒ RailsRequestNotifier
Returns a new instance of RailsRequestNotifier.
6 7 8 9 10 |
# File 'lib/log_parser_notifier/rails_request_notifier.rb', line 6 def initialize(log_file, slow_request_threshold = 500) @log_reader = LogReader.new log_file @slow_request_threshold = slow_request_threshold puts @slow_request_threshold end |
Class Method Details
.render_line(line_hash) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/log_parser_notifier/rails_request_notifier.rb', line 52 def self.render_line(line_hash) case line_hash[:line_type] when :started %Q(Started #{line_hash[:method]} "#{line_hash[:path]}" for #{line_hash[:ip]} at #{Time.parse(line_hash[:timestamp].to_s)}) when :processing %Q(Processing by #{line_hash[:controller]}##{line_hash[:action]} as #{line_hash[:format]}) when :parameters %Q(Parameters: #{line_hash[:params].inspect}) when :rendered " Rendered #{line_hash[:rendered_file]} (#{line_hash[:partial_duration]}ms)" when :completed "Completed #{line_hash[:status]} OK in #{(line_hash[:duration] * 1000).to_i}ms (Views: #{(line_hash[:view] || 0) * 1000}ms | ActiveRecord: #{(line_hash[:db] || 0) * 1000}ms)" else line_hash.inspect end end |
Instance Method Details
#parse_and_trigger_notifications ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/log_parser_notifier/rails_request_notifier.rb', line 20 def parse_and_trigger_notifications parser.parse_stream @log_reader.log_io do |request| = %W(controller:#{request[:controller]} action:#{request[:action]} con_act:#{request[:controller]}##{request[:action]}) LogParserNotifier.logger.debug("processing request for #{request[:controller]}##{request[:action]} with status: #{request[:status]} it is complete: #{request.completed?}") if request.completed? && !request[:status].nil? && request[:status] >= 200 && request[:status] < 400 statsd.increment 'rails.requests', tags: statsd.timing 'rails.load_time', request[:duration] * 1000, tags: if request[:duration] * 1000 >= @slow_request_threshold log = request.lines.collect { |line_hash| RailsRequestNotifier.render_line(line_hash) }.join("\n") statsd.event( "#{request[:controller]}##{request[:action]} #{request[:method]} slow request #{request[:duration]} sec", log, { date_happened: Time.parse(request[:timestamp].to_s).to_i.to_s, aggregation_key: 'slow_request_rails', source_type_name: 'rails_log', alert_type: 'warning', tags: } ) end else statsd.increment 'rails.failed_requests', tags: end end end |
#parser ⇒ Object
12 13 14 |
# File 'lib/log_parser_notifier/rails_request_notifier.rb', line 12 def parser @parser ||= RequestLogAnalyzer::Source::LogParser.new(RequestLogAnalyzer::FileFormat::Rails3.create) end |
#statsd ⇒ Object
16 17 18 |
# File 'lib/log_parser_notifier/rails_request_notifier.rb', line 16 def statsd @statsd ||= Statsd.new('localhost', 8125) end |