munin-plugins-rails-x 0.2.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ce1d624b4a1ea09458f3442666c7751741719c5
4
+ data.tar.gz: 3ce2c8b06fe94a8956fa71c2c3427843164e2733
5
+ SHA512:
6
+ metadata.gz: 8c036b5c2782c3237bf86717861cdcd2af556d62e80b37e3bb7f5bbec47cfa21b880cefa04986d164adc0fcf073aa3a84fa422d761411ab6460b16a96fcd88db
7
+ data.tar.gz: 93617f035028da8c0c6324a8a399ac9aab830c21de1a6d9f30b52f0c9a16cbd2582a0e87ad68b0a00c48e962c97e11cb0b3d6864d57703a644dd11d7ef67b2b8
data/README.rdoc ADDED
@@ -0,0 +1,77 @@
1
+ = Munin-Rails-Plugins
2
+ Collection of Concise Munin plugins for Rails server environments.
3
+ This will make monitoring your rails app a piece of cake.
4
+
5
+ This project contains munin plugins that not only work in munin, but are also concise (see references).
6
+ Most things in this repository rely heavily on the request-log-analyzer gem.
7
+ The project has recenly been converted into a gem. If you are looking for the loose scripts, please checkout: https://github.com/barttenbrinke/munin-plugins-rails/tree/master/munin.
8
+
9
+ == What's in the box?
10
+ * passenger_memory_stats - Munin plugin to monitor the memory usage of passenger application servers.
11
+ * pasenger_queue - Montoring of passenger queue lenth.
12
+ * passenger_status - Running, active and maximum number of passenger instances as well as sessions.
13
+ * rails_database_time - Min, avg, max of database times.
14
+ * rails_request_duration - Min, avg, max of the total request durations.
15
+ * rails_request_error - Application errors and process blocker counters.
16
+ * rails_requests - Get, put, post and delete requests.
17
+ * rails_view_render_time - Min, avg and max view render times.
18
+
19
+ For screenshots, head over to: http://barttenbrinke.github.com/munin-plugins-rails/
20
+
21
+ == Installation
22
+ Installing should be as easy as
23
+
24
+ $ gem install munin-plugins-rails
25
+
26
+ After that you have two options.
27
+ You can add the passenger plugins that will monitor the server as a whole by running:
28
+ $ sudo request-log-analyzer-munin install
29
+
30
+ This will create the necessary symlinks in /etc/munin/plugins and create reasonable configurations in /etc/munin/plugin-conf.d/*
31
+
32
+ * munin_passenger_memory_stats
33
+ * munin_passenger_queue
34
+ * munin_passenger_status
35
+
36
+ Which you can customize as needed. Please note that passenger-memory-status currently only works on Linux (http://bit.ly/krKO2x).
37
+
38
+ The other option is to add a specific application's logfile. To do this, run:
39
+
40
+ $ sudo request-log-analyzer-munin add <app_name> <path_to_log_file>
41
+
42
+ * app_name: this will be the prefix for the graphs and the munin plugins so it should be a valid identifier (/[A-Za-z0-9_]*/).
43
+ * path_to_log_file: this is the path to the log file against which request-log-analyzer will run
44
+
45
+ After running this command you'll have appropriate symlinks in /etc/munin/plugins and a set of configuration files in /etc/munin/plugin-conf.d:
46
+
47
+ * app_name_munin_rails_database_time
48
+ * app_name_munin_rails_request_duration
49
+ * app_name_munin_rails_request_error
50
+ * app_name_munin_rails_requests
51
+ * app_name_munin_rails_view_render_time
52
+
53
+ For more detailed information, see the documentation embedded in the plugins.
54
+ Remember to restart munin-node.
55
+
56
+ $ sudo /etc/init.d/munin-node restart
57
+
58
+ == Troubleshooting
59
+ * Specify the format of your logfile in the munin conf (i.e: <tt>env.log_format rails3</tt>).
60
+ * <tt>sudo gem install request-log-analyzer</tt>
61
+ * Check if the paths in the plugin configuration are correct.
62
+ * Use munin-run to test the plugin with the <tt>--debug</tt> option.
63
+ * Make sure the specified user is allowed to write to <tt>/tmp</tt> and read your rails logfile.
64
+
65
+ If you encounter performance problems with your app, please take a look at the request-log-analyzer wiki on
66
+ examples on how to drill down to the core of your problem. If you want to hire an expert, please visit us at
67
+ http://railsdoctors.com or mail me at: bart@railsdoctors.com
68
+
69
+ Happy monitoring!
70
+
71
+ == Additional information
72
+ * Railsdoctors: http://railsdoctors.com
73
+ * Request-log-analzer: http://github.com/wvanbergen/request-log-analyzer/
74
+ * Screenshots http://barttenbrinke.github.com/munin-plugins-rails/
75
+ * Munin: http://munin.projects.linpro.no/wiki/ConcisePlugins
76
+ * Munin Plugin Starter http://www.packtpub.com/munin-plugin-starter/book
77
+ * License: MIT
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.13
@@ -0,0 +1,30 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
5
+
6
+ require 'munin-plugins-rails'
7
+
8
+ if ARGV.length > 0
9
+ Munin::Command.new.run(ARGV)
10
+ else
11
+ puts "Request-log-analyzer-munin, by Andrew Eberbach & Bart ten Brinke - version 0.2.10"
12
+ puts
13
+ puts "This gem automatates munin-plugin configurations for monitoring of rails apps using"
14
+ puts "the request-log-analyzer gem"
15
+ puts
16
+ puts "Usage: request-log-analyzer-munin [install|appname] <OPTIONS>"
17
+ puts
18
+ puts
19
+ puts "To install passenger plugins:"
20
+ puts " request-log-analyzer-munin install"
21
+ puts
22
+ puts "To install railsplugins:"
23
+ puts " request-log-analyzer-munin <app-name> <log-file>"
24
+ puts
25
+ puts "Examples:"
26
+ puts " request-log-analyzer-munin install"
27
+ puts " request-log-analyzer-munin MyAwesomeApp /srv/my_app/current/log/production.log"
28
+ puts
29
+ exit(0)
30
+ end
@@ -0,0 +1,7 @@
1
+ require 'munin/request_log_analyzer_plugin'
2
+ require 'munin/rails_plugin'
3
+ require 'munin/command'
4
+
5
+ Dir.glob(File.join(File.dirname(__FILE__), "munin", "plugins", "*.rb")).each do |file|
6
+ require file
7
+ end
@@ -0,0 +1,79 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+ module Munin
4
+ class Command
5
+ def run(args)
6
+ if args.first == "install"
7
+ install_passenger_plugins
8
+ elsif args.first == "add"
9
+ args.shift
10
+ install_application(args)
11
+ end
12
+ end
13
+ PASSENGER_PLUGINS = %W{munin_passenger_memory_stats munin_passenger_queue munin_passenger_status}
14
+ RAILS_PLUGINS = %W{munin_rails_database_time munin_rails_request_duration munin_rails_request_error munin_rails_requests munin_rails_view_render_time}
15
+
16
+ PASSENGER_PLUGIN_CONFIG = <<-DATA
17
+ [<%= plugin_target_name %>]
18
+ user root
19
+ command /usr/local/bin/ruby %c
20
+ env.passenger_status '/usr/local/bin/passenger-status'
21
+ env.passenger_memory_stats '/usr/local/bin/passenger-memory-stats'
22
+ env.graph_category <%= graph_category %>
23
+ DATA
24
+
25
+ RAILS_PLUGIN_CONFIG = <<-DATA
26
+ [<%= plugin_target_name %>]
27
+ env.log_file <%= options[:log_file] %>
28
+ user root
29
+ command /usr/local/bin/ruby %c
30
+ env.request_log_analyzer /usr/local/bin/request-log-analyzer
31
+ env.graph_category <%= graph_category %>
32
+ DATA
33
+
34
+ PASSENGER_CATEGORY = "Passenger"
35
+
36
+ def install_application(args)
37
+ app_name = args.shift
38
+ log_file = args.shift
39
+ RAILS_PLUGINS.each do |plugin|
40
+ plugin_target_name = [app_name, plugin].join("_")
41
+ add_plugin(plugin, plugin_target_name)
42
+ add_plugin_config(plugin_target_name, app_name, RAILS_PLUGIN_CONFIG, :log_file => log_file)
43
+ end
44
+ end
45
+
46
+ def install_passenger_plugins
47
+ PASSENGER_PLUGINS.each do |plugin|
48
+ add_plugin(plugin, plugin)
49
+ add_plugin_config(plugin, PASSENGER_CATEGORY, PASSENGER_PLUGIN_CONFIG)
50
+ end
51
+ end
52
+
53
+ def add_plugin_config(plugin_target_name, graph_category, config_template, options = {})
54
+ FileUtils.mkdir_p(munin_plugin_config_path)
55
+ template = ERB.new config_template
56
+ File.open(File.join(munin_plugin_config_path, plugin_target_name), "w+") do |file|
57
+ file << template.result(binding)
58
+ end
59
+ end
60
+
61
+ def add_plugin(plugin_file, plugin_target_name = nil)
62
+ FileUtils.mkdir_p(munin_plugins_path)
63
+ plugin_target_name ||= plugin_file
64
+ `ln -nsf "#{File.join(munin_dir, plugin_file)}" "#{munin_plugins_path}/#{plugin_target_name}"`
65
+ end
66
+
67
+ def munin_plugins_path
68
+ "/etc/munin/plugins"
69
+ end
70
+
71
+ def munin_plugin_config_path
72
+ "/etc/munin/plugin-conf.d"
73
+ end
74
+
75
+ def munin_dir
76
+ File.join(File.dirname(__FILE__), "..", "..", "munin")
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,43 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class PassengerMemoryStats < RequestLogAnalyzerPlugin
5
+ def ensure_configuration
6
+ require_passenger_memory_stats
7
+
8
+ super
9
+ end
10
+
11
+ def config
12
+ memory_info = open('/proc/meminfo', 'r') do |lines|
13
+ lines.inject({}) do |h, line|
14
+ matched = line.match(/^([\w_\(\)]+):\s+(\d+)/)
15
+ h[matched[1].to_sym] = matched[2].to_i * 1024
16
+ h
17
+ end
18
+ end
19
+ upper_limit = memory_info[:MemTotal]
20
+ puts <<-CONFIG
21
+ graph_category #{graph_category}
22
+ graph_title Passenger memory stats
23
+ graph_vlabel Bytes
24
+ graph_args --base 1000 -l 0 --upper-limit #{upper_limit}
25
+ graph_info The memory used by passenger instances on this application server
26
+
27
+ memory.label memory
28
+ CONFIG
29
+ exit 0
30
+ end
31
+
32
+ # Collect the data
33
+ # <tt>debug</tt> Show debug information
34
+ def run
35
+ stats = run_command(passenger_memory_stats, debug)
36
+
37
+ #### Total private dirty RSS: 81.81 MB
38
+ stats =~ /RSS:\s*([\d\.]+)\s*MB\Z/m
39
+ memory = ($1.to_f * 1024 * 1024).to_i
40
+ puts "memory.value #{memory}"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,34 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class PassengerQueue < RequestLogAnalyzerPlugin
5
+ def ensure_configuration
6
+ require_passenger_status
7
+ super
8
+ end
9
+
10
+ def config
11
+ puts <<-CONFIG
12
+ graph_category #{graph_category}
13
+ graph_title Passenger queue
14
+ graph_vlabel count
15
+ graph_args --base 1000 -l 0
16
+ graph_info The amount of requests waiting on global queue
17
+
18
+ requests.label requests
19
+ CONFIG
20
+ exit 0
21
+ end
22
+
23
+ def run
24
+ status = run_command(passenger_status, debug)
25
+ if status =~ /Version : 4/
26
+ status =~ /Requests in top-level queue\s+:\s+(\d+)/
27
+ puts "requests.value #{$1}"
28
+ else
29
+ status =~ /Waiting on global queue:\s+(\d+)/
30
+ puts "requests.value #{$1}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,72 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class PassengerStatus < RequestLogAnalyzerPlugin
5
+ def ensure_configuration
6
+ require_passenger_status
7
+ super
8
+ end
9
+
10
+ def config
11
+ status = `#{passenger_status}`
12
+
13
+ status =~ /max\s+=\s+(\d+)/
14
+ upper_limit = $1 || 150
15
+
16
+ puts <<-CONFIG
17
+ graph_category #{graph_category}
18
+ graph_title Passenger status
19
+ graph_vlabel count
20
+ graph_args --base 1000 -l 0 --upper-limit #{upper_limit}
21
+ graph_info The amount of active passengers on this application server - railsdoctors.com
22
+
23
+ sessions.label sessions
24
+ max.label max processes
25
+ running.label running processes
26
+ active.label active processes
27
+ CONFIG
28
+ exit 0
29
+ end
30
+
31
+ def run
32
+ status = run_command(passenger_status, debug)
33
+
34
+ if status =~ /Version : 4/
35
+ run_version4(status)
36
+ else
37
+ run_version3(status)
38
+ end
39
+ end
40
+
41
+ private
42
+ def run_version4(status)
43
+ status =~ /Max pool size\s+:\s+(\d+)/
44
+ puts "max.value #{$1}"
45
+
46
+ status =~ /Processes\s+:\s+(\d+)/
47
+ puts "running.value #{$1}"
48
+
49
+ active_processes = status.scan(/Sessions:\s+(\d+)/).flatten.select { |count| count.to_i != 0 }.size
50
+ puts "active.value #{active_processes}"
51
+
52
+ total_sessions = 0
53
+ status.scan(/Sessions: (\d+)/).flatten.each { |count| total_sessions += count.to_i }
54
+ puts "sessions.value #{total_sessions}"
55
+ end
56
+
57
+ def run_version3(status)
58
+ status =~ /max\s+=\s+(\d+)/
59
+ puts "max.value #{$1}"
60
+
61
+ status =~ /count\s+=\s+(\d+)/
62
+ puts "running.value #{$1}"
63
+
64
+ status =~ /active\s+=\s+(\d+)/
65
+ puts "active.value #{$1}"
66
+
67
+ total_sessions = 0
68
+ status.scan(/Sessions: (\d+)/).flatten.each { |count| total_sessions += count.to_i }
69
+ puts "sessions.value #{total_sessions}"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,51 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class RailsDatabaseTime < RailsPlugin
5
+ def config
6
+ puts <<-CONFIG
7
+ graph_category #{graph_category}
8
+ graph_title Database time
9
+ graph_vlabel Seconds
10
+ graph_args --base 1000 -l 0
11
+ graph_info The minimum, maximum and average database times - railsdoctors.com
12
+
13
+ min.label min
14
+ max.label max
15
+ average.label avg
16
+ CONFIG
17
+ exit 0
18
+ end
19
+
20
+ # Gather information
21
+ def run
22
+ ensure_log_file
23
+
24
+ # Initialize values
25
+ max_value = 0
26
+ min_value = 1.0/0.0
27
+ cumulative = 0
28
+ hits = 0
29
+
30
+ rla = parse_request_log_analyzer_data
31
+
32
+ if rla && rla["Database time"]
33
+ rla["Database time"].each do |item|
34
+ max_value = item[1][:max] if item[1][:max] > max_value
35
+ min_value = item[1][:min] if item[1][:min] < min_value
36
+ hits += item[1][:hits]
37
+ cumulative += item[1][:sum]
38
+ end
39
+ else
40
+ hits = 1
41
+ min_value = 0
42
+ end
43
+
44
+ # Report in seconds
45
+ puts "max.value #{max_value}"
46
+ puts "min.value #{min_value}"
47
+ puts "average.value #{cumulative / hits.to_f}"
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,49 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class RailsRequestDuration < RailsPlugin
5
+ def config
6
+ puts <<-CONFIG
7
+ graph_category #{graph_category}
8
+ graph_title Request time
9
+ graph_vlabel Seconds
10
+ graph_args --base 1000 -l 0
11
+ graph_info The minimum, maximum and average request times - railsdoctors.com
12
+
13
+ min.label min
14
+ max.label max
15
+ average.label avg
16
+ CONFIG
17
+ exit 0
18
+ end
19
+
20
+ # Gather information
21
+ def run
22
+ ensure_log_file
23
+
24
+ # Initialize values
25
+ max_value = 0
26
+ min_value = 1.0/0.0
27
+ cumulative = 0
28
+ hits = 0
29
+
30
+ rla = parse_request_log_analyzer_data
31
+
32
+ if rla && rla["Request duration"]
33
+ rla["Request duration"].each do |item|
34
+ max_value = item[1][:max] if item[1][:max] > max_value
35
+ min_value = item[1][:min] if item[1][:min] < min_value
36
+ hits += item[1][:hits]
37
+ cumulative += item[1][:sum]
38
+ end
39
+ else
40
+ hits = 1
41
+ min_value = 0
42
+ end
43
+
44
+ puts "max.value #{max_value}"
45
+ puts "min.value #{min_value}"
46
+ puts "average.value #{cumulative / hits.to_f}"
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,44 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class RailsRequestError < RailsPlugin
5
+ def config
6
+ puts <<-CONFIG
7
+ graph_category #{graph_category}
8
+ graph_title Request errors
9
+ graph_vlabel Count
10
+ graph_info The amount of request errors - railsdoctors.com
11
+
12
+ error.label error
13
+ blocker.label blocker
14
+ CONFIG
15
+ exit 0
16
+ end
17
+
18
+ # Gather information
19
+ def run
20
+ ensure_log_file
21
+
22
+ # Initialize values
23
+ error_value = 0
24
+ blocker_value = 0
25
+
26
+ rla = parse_request_log_analyzer_data
27
+
28
+ if rla && rla["Failed requests"]
29
+ rla["Failed requests"].each do |item|
30
+ error_value += item[1]
31
+ end
32
+ end
33
+
34
+ if rla && rla["Process blockers (> 1 sec duration)"]
35
+ rla["Process blockers (> 1 sec duration)"].each do |item|
36
+ blocker_value += item[1]
37
+ end
38
+ end
39
+
40
+ puts "error.value #{error_value}"
41
+ puts "blocker.value #{blocker_value}"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,53 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class RailsRequests < RailsPlugin
5
+ def config
6
+ puts <<-CONFIG
7
+ graph_category #{graph_category}
8
+ graph_title Processed requests
9
+ graph_vlabel Requests per second
10
+ graph_info The amount of requests processed by this application server - railsdoctors.com
11
+
12
+ get.label get
13
+ get.draw AREA
14
+ post.label post
15
+ post.draw STACK
16
+ put.label put
17
+ put.draw STACK
18
+ delete.label delete
19
+ delete.draw STACK
20
+ CONFIG
21
+ exit 0
22
+ end
23
+
24
+ # Gather information
25
+ def run
26
+ ensure_log_file
27
+
28
+ # Initialize values
29
+ get_value = 0
30
+ post_value = 0
31
+ put_value = 0
32
+ delete_value = 0
33
+
34
+ # Walk through the
35
+ File.open(get_request_log_analyzer_file).each_line{ |line|
36
+ if match = line.match(/^\s+GET\:\s(\d+).*/)
37
+ get_value = match[1].to_i
38
+ elsif match = line.match(/^\s+POST\:\s(\d+).*/)
39
+ post_value = match[1].to_i
40
+ elsif match = line.match(/^\s+PUT\:\s(\d+).*/)
41
+ put_value = match[1].to_i
42
+ elsif match = line.match(/^\s+DELETE\:\s(\d+).*/)
43
+ delete_value = match[1].to_i
44
+ end
45
+ }
46
+
47
+ puts "get.value #{get_value / interval.to_f}"
48
+ puts "post.value #{post_value / interval.to_f}"
49
+ puts "put.value #{put_value / interval.to_f}"
50
+ puts "delete.value #{delete_value / interval.to_f}"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,49 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class RailsViewRenderTime < RailsPlugin
5
+ def config
6
+ puts <<-CONFIG
7
+ graph_category #{graph_category}
8
+ graph_title View render times
9
+ graph_vlabel Seconds
10
+ graph_args --base 1000 -l 0
11
+ graph_info The minimum, maximum and average view render times - railsdoctors.com
12
+
13
+ min.label min
14
+ max.label max
15
+ average.label avg
16
+ CONFIG
17
+ exit 0
18
+ end
19
+
20
+ # Gather information
21
+ def run
22
+ ensure_log_file
23
+
24
+ # Initialize values
25
+ max_value = 0
26
+ min_value = 1.0/0.0
27
+ cumulative = 0
28
+ hits = 0
29
+
30
+ rla = parse_request_log_analyzer_data
31
+
32
+ if rla && rla["View rendering time"]
33
+ rla["View rendering time"].each do |item|
34
+ max_value = item[1][:max] if item[1][:max] > max_value
35
+ min_value = item[1][:min] if item[1][:min] < min_value
36
+ hits += item[1][:hits]
37
+ cumulative += item[1][:sum]
38
+ end
39
+ else
40
+ hits = 1
41
+ min_value = 0
42
+ end
43
+
44
+ puts "max.value #{max_value}"
45
+ puts "min.value #{min_value}"
46
+ puts "average.value #{cumulative / hits.to_f}"
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,85 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class RailsPlugin < RequestLogAnalyzerPlugin
5
+
6
+ attr_accessor :interval
7
+ attr_accessor :number_of_lines
8
+ attr_accessor :log_file
9
+ attr_accessor :log_format
10
+ attr_accessor :after_time
11
+ attr_accessor :floor_time
12
+ attr_accessor :temp_folder
13
+ attr_accessor :temp_prefix
14
+ attr_accessor :temp_file_name
15
+ attr_accessor :request_log_analyzer
16
+
17
+ def handle_arguments(args, environment)
18
+ super
19
+
20
+ self.interval = environment['interval'] ? environment['interval'].to_i : 300
21
+ self.number_of_lines = environment['lines'] || 50000
22
+ self.log_file = environment['log_file'] || args[0]
23
+ self.log_format = environment['log_format'] ? "--format #{environment['log_format']}" : ''
24
+ self.after_time = (Time.now - interval).strftime('%Y%m%d%H%M%S')
25
+ self.floor_time = Time.at((Time.now.to_f / interval).floor * interval)
26
+
27
+ self.temp_folder = '/tmp'
28
+ self.temp_prefix = graph_category == 'App' ? 'rla' : graph_category.downcase
29
+ self.temp_file_name = "#{temp_prefix}_#{floor_time.to_i}.yml"
30
+ self.request_log_analyzer = environment['request_log_analyzer'] || '/usr/bin/request-log-analyzer'
31
+ end
32
+
33
+ def parse_request_log_analyzer_data
34
+ YAML::load_file( get_request_log_analyzer_file )
35
+ end
36
+
37
+ def get_request_log_analyzer_file
38
+ fetch_or_create_yaml_file(log_file, debug)
39
+ end
40
+
41
+ def ensure_configuration
42
+ require_request_log_analyzer_gem
43
+ require_yaml_gem
44
+ require_tail_command
45
+
46
+ super
47
+ end
48
+
49
+ def ensure_log_file
50
+ if log_file == "" || log_file.nil?
51
+ $stderr.puts "Filepath unspecified. Exiting"
52
+ exit 1
53
+ end
54
+ end
55
+
56
+ def fetch_or_create_yaml_file(log_file, debug = false)
57
+ # Clean up any old temp files left in de temp folder
58
+ Dir.new(temp_folder).entries.each do |file_name|
59
+ if match = file_name.match(/^#{temp_prefix}_.*\.yml/)
60
+ if match[0] != temp_file_name
61
+ puts "Removing old cache file: #{file_name}" if debug
62
+ File.delete(temp_folder + "/" + file_name)
63
+ end
64
+ end
65
+ end
66
+
67
+ temp_file = temp_folder + "/" + temp_file_name
68
+
69
+ # Create temp file rla if needed
70
+ unless File.exists?(temp_file)
71
+ puts "Processing the last #{number_of_lines} lines of #{log_file} which are less then #{interval} seconds old." if debug
72
+ status = `tail -n #{number_of_lines} #{log_file} | #{request_log_analyzer} - --after #{after_time} #{log_format} -b --dump #{temp_file}`
73
+
74
+ unless $?.success?
75
+ $stderr.puts "failed executing request-log-analyzer. Is the gem path correct?"
76
+ exit 1
77
+ end
78
+ else
79
+ puts "Processing cached YAML result #{temp_file}" if debug
80
+ end
81
+
82
+ return temp_file
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,113 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ module Munin
4
+ class RequestLogAnalyzerPlugin
5
+ attr_accessor :graph_category
6
+ attr_accessor :passenger_memory_stats
7
+ attr_accessor :passenger_status
8
+ attr_accessor :debug
9
+ attr_accessor :environment
10
+
11
+ def initialize(args, environment)
12
+ handle_arguments(args, environment)
13
+ ensure_configuration
14
+
15
+ if args[0] == "config"
16
+ config
17
+ elsif args[0] == "autoconf"
18
+ autoconf
19
+ end
20
+ end
21
+
22
+ def handle_arguments(args, environment)
23
+ self.environment = environment
24
+ self.graph_category = environment['graph_category'] || 'App'
25
+
26
+ if args[0] == "debug"
27
+ args.shift
28
+ self.debug = true
29
+ end
30
+ end
31
+
32
+ def run_command(command, debug = false)
33
+ result = `#{command}`
34
+
35
+ unless $?.success?
36
+ $stderr.puts "failed executing #{command}"
37
+ exit 1
38
+ end
39
+
40
+ puts result if debug
41
+
42
+ result
43
+ end
44
+
45
+ def require_request_log_analyzer_gem
46
+ require_gem("request-log-analyzer", ">=1.1.6")
47
+ end
48
+
49
+ def require_yaml_gem
50
+ begin
51
+ require 'yaml'
52
+ rescue Exception => e
53
+ puts "no (yaml not found)"
54
+ exit 1
55
+ end
56
+ end
57
+
58
+ def require_command(command_name)
59
+ status = `#{command_name}`
60
+ unless $?.success?
61
+ puts "no (error when excuting #{command_name})"
62
+ exit 1
63
+ end
64
+ end
65
+
66
+ def require_tail_command
67
+ unless `echo "test" | tail 2>/dev/null`.include?("test")
68
+ puts "no (tail command not found)"
69
+ exit 1
70
+ end
71
+ end
72
+
73
+ def require_passenger_status
74
+ self.passenger_status = environment['passenger_status'] || '/usr/local/bin/passenger-status'
75
+ #to use if you have multiple passenger on the host like phusion passenger standalone
76
+ if environment['apache_pid_file']
77
+ self.passenger_status = "cat #{environment['apache_pid_file']} | xargs -0 #{passenger_status}"
78
+ end
79
+
80
+ require_command(passenger_status)
81
+ end
82
+
83
+ def require_passenger_memory_stats
84
+ self.passenger_memory_stats = environment['passenger_memory_stats'] || '/usr/local/bin/passenger-memory-stats'
85
+
86
+ require_command(passenger_memory_stats)
87
+ end
88
+
89
+ def require_gem(gemname, version = nil)
90
+ begin
91
+ require 'rubygems'
92
+ if version
93
+ gem gemname, version
94
+ else
95
+ gem gemname
96
+ end
97
+ rescue Exception => e
98
+ puts "no (Gem not found: #{e})"
99
+ exit 1
100
+ end
101
+ end
102
+
103
+ def ensure_configuration
104
+
105
+ end
106
+
107
+ def autoconf
108
+ ensure_configuration
109
+ puts "yes"
110
+ exit 0
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ pod=<<-POD
3
+
4
+ =head1 NAME
5
+ passenger_memory_stats - Munin plugin to monitor the memory usage of passenger application servers.
6
+ Monitors the memory consumed by passenger instances.
7
+
8
+ =head1 APPLICABLE SYSTEMS
9
+ All systems that have passenger installed.
10
+
11
+ =head1 CONFIGURATION
12
+ The plugin needs to execute passenger-memory-stats.
13
+ This configuration section shows the defaults of the plugin:
14
+
15
+ [passenger_*]
16
+ user root
17
+ command /usr/local/bin/ruby %c
18
+
19
+ Options
20
+ env.passenger_memory_stats '/path/to/passenger-memory-stats' # Path to passenger memory status.
21
+ env.graph_category 'App' # Graph Category. Defaults to App.
22
+
23
+ ln -s /usr/share/munin/plugins/passenger_memory_stats /etc/munin/plugins/passenger_memory_stats
24
+
25
+ =head1 INTERPRETATION
26
+ The plugin shows the memory consumed by passenger instances.
27
+
28
+ =head1 MAGIC MARKERS
29
+ #%# family=auto
30
+ #%# capabilities=autoconf
31
+
32
+ =head1 VERSION
33
+ 1.9.7
34
+
35
+ =head1 BUGS
36
+ None known
37
+
38
+ =head1 AUTHOR
39
+ Ilya Lityuga
40
+ Bart ten Brinke - railsdoctors.com
41
+
42
+ =head1 LICENSE
43
+ MIT
44
+
45
+ POD
46
+ require 'rubygems'
47
+ require 'munin-plugins-rails'
48
+ Munin::PassengerMemoryStats.new(ARGV, ENV).run
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ #coding: utf-8
3
+ pod=<<-POD
4
+
5
+ =head1 NAME
6
+ passenger_queue - Munin plugin to monitor passenger queue.
7
+ Monitors the amount of requests in global queue.
8
+
9
+ =head1 APPLICABLE SYSTEMS
10
+ All systems that have passenger installed.
11
+
12
+ =head1 CONFIGURATION
13
+ The plugin needs to execute passenger-status.
14
+ This configuration section shows the defaults of the plugin:
15
+
16
+ [passenger_*]
17
+ user root
18
+ command /usr/local/bin/ruby %c
19
+
20
+ Options
21
+ env.passenger_status '/path/to/passenger-status' # Path to passenger-status
22
+ env.apache_pid_file '/path/to/apache2.pid' # Path to passenger-status (like /var/run/apache2.pid)
23
+ env.graph_category 'App' # Graph Category. Defaults to App.
24
+
25
+ ln -s /usr/share/munin/plugins/passenger_queue /etc/munin/plugins/passenger_queue
26
+
27
+ =head1 INTERPRETATION
28
+ The plugin shows the current number of requests waiting on global queue.
29
+
30
+ =head1 MAGIC MARKERS
31
+ #%# family=auto
32
+ #%# capabilities=autoconf
33
+
34
+ =head1 VERSION
35
+ 1.9.7
36
+
37
+ =head1 BUGS
38
+ None known
39
+
40
+ =head1 AUTHOR
41
+ Michaël Witrant - http://michael.witrant.com/
42
+ Bart ten Brinke - railsdoctors.com
43
+ Daniel Manges - http://gist.github.com/20319
44
+
45
+ =head1 LICENSE
46
+ MIT
47
+
48
+ POD
49
+ require 'rubygems'
50
+ require 'munin-plugins-rails'
51
+
52
+ Munin::PassengerQueue.new(ARGV, ENV).run
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ pod=<<-POD
3
+
4
+ =head1 NAME
5
+ passenger_status - Munin plugin to monitor passenger application servers.
6
+ Monitors the amount of sessions and running, active and maximum amount of passenger instances.
7
+
8
+ =head1 APPLICABLE SYSTEMS
9
+ All systems that have passenger installed.
10
+
11
+ =head1 CONFIGURATION
12
+ The plugin needs to execute passenger-status.
13
+ This configuration section shows the defaults of the plugin:
14
+
15
+ [passenger_*]
16
+ user root
17
+ command /usr/local/bin/ruby %c
18
+
19
+ Options
20
+ env.passenger_status '/path/to/passenger-status' # Path to passenger-status
21
+ env.graph_category 'App' # Graph Category. Defaults to App.
22
+ env.apache_pid_file '/var/run/apache2.pid' # Use if you want to monitor multiple installations.
23
+
24
+ ln -s /usr/share/munin/plugins/passenger_status /etc/munin/plugins/passenger_status
25
+
26
+ =head1 INTERPRETATION
27
+ The plugin shows the maximum, active and current number of running passenger instances.
28
+
29
+ =head1 MAGIC MARKERS
30
+ #%# family=auto
31
+ #%# capabilities=autoconf
32
+
33
+ =head1 VERSION
34
+ 1.9.7.1
35
+
36
+ =head1 BUGS
37
+ None known
38
+
39
+ =head1 AUTHOR
40
+ Bart ten Brinke - railsdoctors.com
41
+ Daniel Manges - http://gist.github.com/20319
42
+
43
+ =head1 LICENSE
44
+ MIT
45
+
46
+ POD
47
+ require 'rubygems'
48
+ require 'munin-plugins-rails'
49
+
50
+ Munin::PassengerStatus.new(ARGV, ENV).run
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ pod=<<-POD
3
+
4
+ =head1 NAME
5
+ rails_database_time - Munin plugin to monitor the minimum, average and maximum database times.
6
+
7
+ =head1 APPLICABLE SYSTEMS
8
+ All systems that have a rails application log.
9
+
10
+ =head1 CONFIGURATION
11
+ The request-log-analyzer gem has to be intalled.
12
+ Also the script has to be able to access the rails log file and tail.
13
+ This configuration section shows the defaults of the plugin:
14
+
15
+ [rails_database_time]
16
+ env.log_file '/path/to/production.log'
17
+ user www-data
18
+ command /usr/local/bin/ruby %c
19
+ log_format rails3
20
+
21
+ Options
22
+ env.lines 50000 # Number of lines to tail
23
+ env.interval 300 # Munin interval in seconds (used for graphs and caching)
24
+ env.log_format # request-log-analyzer log format (passed to '--format')
25
+ env.request_log_analyzer '/usr/local/bin' # Path to gem. Use this for Debian.
26
+ env.graph_category 'App' # Graph Category. Defaults to App.
27
+
28
+ ln -s /usr/share/munin/plugins/rails_database_time /etc/munin/plugins/rails_database_time
29
+
30
+ =head1 INTERPRETATION
31
+ Three lines are graphed, showing the minimum, average and maximum database times.
32
+
33
+ =head1 MAGIC MARKERS
34
+ #%# family=auto
35
+ #%# capabilities=autoconf
36
+
37
+ =head1 VERSION
38
+ 1.9.7
39
+
40
+ =head1 BUGS
41
+ None known
42
+
43
+ =head1 AUTHOR
44
+ Bart ten Brinke - railsdoctors.com
45
+
46
+ =head1 LICENSE
47
+ MIT
48
+
49
+ POD
50
+ require 'rubygems'
51
+ require 'munin-plugins-rails'
52
+
53
+ Munin::RailsDatabaseTime.new(ARGV, ENV).run
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ pod=<<-POD
3
+
4
+ =head1 NAME
5
+ rails_request_duration - Munin plugin to monitor the minimum, average and maximum request duration.
6
+
7
+ =head1 APPLICABLE SYSTEMS
8
+ All systems that have a rails application log.
9
+
10
+ =head1 CONFIGURATION
11
+ The request-log-analyzer gem has to be intalled.
12
+ Also the script has to be able to access the rails log file and tail.
13
+ This configuration section shows the defaults of the plugin:
14
+
15
+ [rails_request_duration]
16
+ env.log_file '/path/to/production.log'
17
+ user www-data
18
+ command /usr/local/bin/ruby %c
19
+ log_format rails3
20
+
21
+ Options
22
+ env.lines 50000 # Number of lines to tail
23
+ env.interval 300 # Munin interval in seconds (used for graphs and caching)
24
+ env.log_format # request-log-analyzer log format (passed to '--format')
25
+ env.request_log_analyzer '/usr/local/bin' # Path to gem. Use this for Debian.
26
+ env.graph_category 'App' # Graph Category. Defaults to App.
27
+
28
+ ln -s /usr/share/munin/plugins/rails_request_duration /etc/munin/plugins/rails_request_duration
29
+
30
+ =head1 INTERPRETATION
31
+ Three lines are graphed, showing the minimum, average and maximum request times.
32
+
33
+ =head1 MAGIC MARKERS
34
+ #%# family=auto
35
+ #%# capabilities=autoconf
36
+
37
+ =head1 VERSION
38
+ 1.9.7
39
+
40
+ =head1 BUGS
41
+ None known
42
+
43
+ =head1 AUTHOR
44
+ Bart ten Brinke - railsdoctors.com
45
+
46
+ =head1 LICENSE
47
+ MIT
48
+
49
+ POD
50
+ require 'rubygems'
51
+ require 'munin-plugins-rails'
52
+
53
+ Munin::RailsRequestDuration.new(ARGV, ENV).run
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ pod=<<-POD
3
+
4
+ =head1 NAME
5
+ rails_request_error - Munin plugin to monitor the amount of errors and process blockers.
6
+
7
+ =head1 APPLICABLE SYSTEMS
8
+ All systems that have a rails application log.
9
+
10
+ =head1 CONFIGURATION
11
+ The request-log-analyzer gem has to be intalled.
12
+ Also the script has to be able to access the rails log file and tail.
13
+ This configuration section shows the defaults of the plugin:
14
+
15
+ [rails_request_error]
16
+ env.log_file '/path/to/production.log'
17
+ user www-data
18
+ command /usr/local/bin/ruby %c
19
+ log_format rails3
20
+
21
+ Options
22
+ env.lines 50000 # Number of lines to tail
23
+ env.interval 300 # Munin interval in seconds (used for graphs and caching)
24
+ env.log_format # request-log-analyzer log format (passed to '--format')
25
+ env.request_log_analyzer '/usr/local/bin' # Path to gem. Use this for Debian.
26
+ env.graph_category 'App' # Graph Category. Defaults to App.
27
+
28
+ ln -s /usr/share/munin/plugins/rails_request_error /etc/munin/plugins/rails_request_error
29
+
30
+ =head1 INTERPRETATION
31
+ Two lines are graphed, one showing the amount of errors raised and one showing the amount of process
32
+ blockers. Process blockers are requests that took longer than 1 second to complete.
33
+
34
+ =head1 MAGIC MARKERS
35
+ #%# family=auto
36
+ #%# capabilities=autoconf
37
+
38
+ =head1 VERSION
39
+ 1.9.7
40
+
41
+ =head1 BUGS
42
+ None known
43
+
44
+ =head1 AUTHOR
45
+ Bart ten Brinke - railsdoctors.com
46
+
47
+ =head1 LICENSE
48
+ MIT
49
+
50
+ POD
51
+ require 'rubygems'
52
+ require 'munin-plugins-rails'
53
+
54
+ Munin::RailsRequestError.new(ARGV, ENV).run
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ pod=<<-POD
3
+
4
+ =head1 NAME
5
+ rails_requests - Munin plugin to monitor the amount of get, put, post and delete requests from a
6
+ rails application log.
7
+
8
+ =head1 APPLICABLE SYSTEMS
9
+ All systems that have a rails application log.
10
+
11
+ =head1 CONFIGURATION
12
+ The request-log-analyzer gem has to be intalled.
13
+ Also the script has to be able to access the rails log file and tail.
14
+ This configuration section shows the defaults of the plugin:
15
+
16
+ [rails_requests]
17
+ env.log_file '/path/to/production.log'
18
+ user www-data
19
+ command /usr/local/bin/ruby %c
20
+ log_format rails3
21
+
22
+ Options
23
+ env.lines 50000 # Number of lines to tail
24
+ env.interval 300 # Munin interval in seconds (used for graphs and caching)
25
+ env.log_format # request-log-analyzer log format (passed to '--format')
26
+ env.request_log_analyzer '/usr/local/bin' # Path to gem. Use this for Debian.
27
+ env.graph_category 'App' # Graph Category. Defaults to App.
28
+
29
+ ln -s /usr/share/munin/plugins/rails_requests /etc/munin/plugins/rails_requests
30
+
31
+ =head1 INTERPRETATION
32
+ All HTTP methods are stacked so that the total equals the amount of requests processed per 5 minutes.
33
+
34
+ =head1 MAGIC MARKERS
35
+ #%# family=auto
36
+ #%# capabilities=autoconf
37
+
38
+ =head1 VERSION
39
+ 1.9.7
40
+
41
+ =head1 BUGS
42
+ None known
43
+
44
+ =head1 AUTHOR
45
+ Bart ten Brinke - railsdoctors.com
46
+
47
+ =head1 LICENSE
48
+ MIT
49
+
50
+ POD
51
+ require 'rubygems'
52
+ require 'munin-plugins-rails'
53
+
54
+ Munin::RailsRequests.new(ARGV, ENV).run
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ pod=<<-POD
3
+
4
+ =head1 NAME
5
+ rails_view_render_time - Munin plugin to monitor the minimum, average and maximum view render times.
6
+
7
+ =head1 APPLICABLE SYSTEMS
8
+ All systems that have a rails application log.
9
+
10
+ =head1 CONFIGURATION
11
+ The request-log-analyzer gem has to be intalled.
12
+ Also the script has to be able to access the rails log file and tail.
13
+ This configuration section shows the defaults of the plugin:
14
+
15
+ [rails_view_render_time]
16
+ env.log_file '/path/to/production.log'
17
+ user www-data
18
+ command /usr/local/bin/ruby %c
19
+ log_format rails3
20
+
21
+ Options
22
+ env.lines 50000 # Number of lines to tail
23
+ env.interval 300 # Munin interval in seconds (used for graphs and caching)
24
+ env.log_format # request-log-analyzer log format (passed to '--format')
25
+ env.request_log_analyzer '/usr/local/bin' # Path to gem. Use this for Debian.
26
+ env.graph_category 'App' # Graph Category. Defaults to App.
27
+
28
+ ln -s /usr/share/munin/plugins/rails_view_render_time /etc/munin/plugins/rails_view_render_time
29
+
30
+ =head1 INTERPRETATION
31
+ Three lines are graphed, showing the minimum, average and maximum view render times.
32
+
33
+ =head1 MAGIC MARKERS
34
+ #%# family=auto
35
+ #%# capabilities=autoconf
36
+
37
+ =head1 VERSION
38
+ 1.9.7
39
+
40
+ =head1 BUGS
41
+ None known
42
+
43
+ =head1 AUTHOR
44
+ Bart ten Brinke - railsdoctors.com
45
+
46
+ =head1 LICENSE
47
+ MIT
48
+
49
+ POD
50
+ require 'rubygems'
51
+ require 'munin-plugins-rails'
52
+
53
+ Munin::RailsViewRenderTime.new(ARGV, ENV).run
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: munin-plugins-rails-x
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.13.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Eberbach
8
+ - Bart ten Brinke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: request-log-analyzer
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description:
29
+ email: andrew@ebertech.ca
30
+ executables:
31
+ - request-log-analyzer-munin
32
+ extensions: []
33
+ extra_rdoc_files:
34
+ - README.rdoc
35
+ files:
36
+ - VERSION
37
+ - lib/munin-plugins-rails.rb
38
+ - lib/munin/command.rb
39
+ - lib/munin/plugins/passenger_memory_stats.rb
40
+ - lib/munin/plugins/passenger_queue.rb
41
+ - lib/munin/plugins/passenger_status.rb
42
+ - lib/munin/plugins/rails_database_time.rb
43
+ - lib/munin/plugins/rails_request_duration.rb
44
+ - lib/munin/plugins/rails_request_error.rb
45
+ - lib/munin/plugins/rails_requests.rb
46
+ - lib/munin/plugins/rails_view_render_time.rb
47
+ - lib/munin/rails_plugin.rb
48
+ - lib/munin/request_log_analyzer_plugin.rb
49
+ - munin/munin_passenger_memory_stats
50
+ - munin/munin_passenger_queue
51
+ - munin/munin_passenger_status
52
+ - munin/munin_rails_database_time
53
+ - munin/munin_rails_request_duration
54
+ - munin/munin_rails_request_error
55
+ - munin/munin_rails_requests
56
+ - munin/munin_rails_view_render_time
57
+ - README.rdoc
58
+ - bin/request-log-analyzer-munin
59
+ homepage:
60
+ licenses: []
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.0
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Plugins for Munin that use passenger and RLA
82
+ test_files: []