Class: Munin::RailsPlugin
- Inherits:
-
RequestLogAnalyzerPlugin
- Object
- RequestLogAnalyzerPlugin
- Munin::RailsPlugin
- Defined in:
- lib/munin/rails_plugin.rb
Direct Known Subclasses
RailsDatabaseTime, RailsRequestDuration, RailsRequestError, RailsRequests, RailsViewRenderTime
Instance Attribute Summary collapse
-
#after_time ⇒ Object
Returns the value of attribute after_time.
-
#floor_time ⇒ Object
Returns the value of attribute floor_time.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#log_format ⇒ Object
Returns the value of attribute log_format.
-
#number_of_lines ⇒ Object
Returns the value of attribute number_of_lines.
-
#request_log_analyzer ⇒ Object
Returns the value of attribute request_log_analyzer.
-
#temp_file_name ⇒ Object
Returns the value of attribute temp_file_name.
-
#temp_folder ⇒ Object
Returns the value of attribute temp_folder.
-
#temp_prefix ⇒ Object
Returns the value of attribute temp_prefix.
Attributes inherited from RequestLogAnalyzerPlugin
#debug, #environment, #graph_category, #passenger_memory_stats, #passenger_status
Instance Method Summary collapse
- #ensure_configuration ⇒ Object
- #ensure_log_file ⇒ Object
- #fetch_or_create_yaml_file(log_file, debug = false) ⇒ Object
- #get_request_log_analyzer_file ⇒ Object
- #handle_arguments(args, environment) ⇒ Object
- #parse_request_log_analyzer_data ⇒ Object
Methods inherited from RequestLogAnalyzerPlugin
#autoconf, #initialize, #require_command, #require_gem, #require_passenger_memory_stats, #require_passenger_status, #require_request_log_analyzer_gem, #require_tail_command, #require_yaml_gem, #run_command
Constructor Details
This class inherits a constructor from Munin::RequestLogAnalyzerPlugin
Instance Attribute Details
#after_time ⇒ Object
Returns the value of attribute after_time.
10 11 12 |
# File 'lib/munin/rails_plugin.rb', line 10 def after_time @after_time end |
#floor_time ⇒ Object
Returns the value of attribute floor_time.
11 12 13 |
# File 'lib/munin/rails_plugin.rb', line 11 def floor_time @floor_time end |
#interval ⇒ Object
Returns the value of attribute interval.
6 7 8 |
# File 'lib/munin/rails_plugin.rb', line 6 def interval @interval end |
#log_file ⇒ Object
Returns the value of attribute log_file.
8 9 10 |
# File 'lib/munin/rails_plugin.rb', line 8 def log_file @log_file end |
#log_format ⇒ Object
Returns the value of attribute log_format.
9 10 11 |
# File 'lib/munin/rails_plugin.rb', line 9 def log_format @log_format end |
#number_of_lines ⇒ Object
Returns the value of attribute number_of_lines.
7 8 9 |
# File 'lib/munin/rails_plugin.rb', line 7 def number_of_lines @number_of_lines end |
#request_log_analyzer ⇒ Object
Returns the value of attribute request_log_analyzer.
15 16 17 |
# File 'lib/munin/rails_plugin.rb', line 15 def request_log_analyzer @request_log_analyzer end |
#temp_file_name ⇒ Object
Returns the value of attribute temp_file_name.
14 15 16 |
# File 'lib/munin/rails_plugin.rb', line 14 def temp_file_name @temp_file_name end |
#temp_folder ⇒ Object
Returns the value of attribute temp_folder.
12 13 14 |
# File 'lib/munin/rails_plugin.rb', line 12 def temp_folder @temp_folder end |
#temp_prefix ⇒ Object
Returns the value of attribute temp_prefix.
13 14 15 |
# File 'lib/munin/rails_plugin.rb', line 13 def temp_prefix @temp_prefix end |
Instance Method Details
#ensure_configuration ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/munin/rails_plugin.rb', line 41 def ensure_configuration require_request_log_analyzer_gem require_yaml_gem require_tail_command super end |
#ensure_log_file ⇒ Object
49 50 51 52 53 54 |
# File 'lib/munin/rails_plugin.rb', line 49 def ensure_log_file if log_file == "" || log_file.nil? $stderr.puts "Filepath unspecified. Exiting" exit 1 end end |
#fetch_or_create_yaml_file(log_file, debug = false) ⇒ Object
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 |
# File 'lib/munin/rails_plugin.rb', line 56 def fetch_or_create_yaml_file(log_file, debug = false) # Clean up any old temp files left in de temp folder Dir.new(temp_folder).entries.each do |file_name| if match = file_name.match(/^#{temp_prefix}_.*\.yml/) if match[0] != temp_file_name puts "Removing old cache file: #{file_name}" if debug File.delete(temp_folder + "/" + file_name) end end end temp_file = temp_folder + "/" + temp_file_name # Create temp file rla if needed unless File.exists?(temp_file) puts "Processing the last #{number_of_lines} lines of #{log_file} which are less then #{interval} seconds old." if debug status = `tail -n #{number_of_lines} #{log_file} | #{request_log_analyzer} - --after #{after_time} #{log_format} -b --dump #{temp_file}` unless $?.success? $stderr.puts "failed executing request-log-analyzer. Is the gem path correct?" exit 1 end else puts "Processing cached YAML result #{temp_file}" if debug end return temp_file end |
#get_request_log_analyzer_file ⇒ Object
37 38 39 |
# File 'lib/munin/rails_plugin.rb', line 37 def get_request_log_analyzer_file fetch_or_create_yaml_file(log_file, debug) end |
#handle_arguments(args, environment) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/munin/rails_plugin.rb', line 17 def handle_arguments(args, environment) super self.interval = environment['interval'] ? environment['interval'].to_i : 300 self.number_of_lines = environment['lines'] || 50000 self.log_file = environment['log_file'] || args[0] self.log_format = environment['log_format'] ? "--format #{environment['log_format']}" : '' self.after_time = (Time.now - interval).strftime('%Y%m%d%H%M%S') self.floor_time = Time.at((Time.now.to_f / interval).floor * interval) self.temp_folder = '/tmp' self.temp_prefix = graph_category == 'App' ? 'rla' : graph_category.downcase self.temp_file_name = "#{temp_prefix}_#{floor_time.to_i}.yml" self.request_log_analyzer = environment['request_log_analyzer'] || '/usr/bin/request-log-analyzer' end |
#parse_request_log_analyzer_data ⇒ Object
33 34 35 |
# File 'lib/munin/rails_plugin.rb', line 33 def parse_request_log_analyzer_data YAML::load_file( get_request_log_analyzer_file ) end |