Skip to content

Commit

Permalink
moved scripts around
Browse files Browse the repository at this point in the history
  • Loading branch information
ebertech committed Mar 17, 2011
1 parent b3efb30 commit 26a7dc6
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg/*
1 change: 1 addition & 0 deletions bin/request-log-analyzer-munin
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby

require 'munin-plugins-rails'
Munin::Command.new.run(ARGV)
75 changes: 75 additions & 0 deletions lib/munin/command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require 'fileutils'
require 'erb'
module Munin
class Command
def run(args)
if args.first == "install"
install_passenger_plugins
elsif args.first == "add"
args.shift
install_application(args)
end
end
PASSENGER_PLUGINS = %W{munin_passenger_memory_stats munin_passenger_queue munin_passenger_status}
RAILS_PLUGINS = %W{munin_rails_database_time munin_rails_request_duration munin_rails_request_error munin_rails_requests munin_rails_view_render_time}

PASSENGER_PLUGIN_CONFIG = <<-DATA
[<%= plugin_target_name %>]
user root
command /usr/local/bin/ruby %c
env.passenger_status '/usr/local/bin/passenger-status'
env.passenger_memory_stats '/usr/local/bin/passenger-memory-stats'
DATA

RAILS_PLUGIN_CONFIG = <<-DATA
[<%= plugin_target_name %>]
env.log_file <%= options[:log_file] %>
user root
command /usr/local/bin/ruby %c
env.request_log_analyzer /usr/local/bin/request-log-analyzer
DATA

def install_application(args)
app_name = args.shift
log_file = args.shift
RAILS_PLUGINS.each do |plugin|
plugin_target_name = [app_name, plugin].join("_")
add_plugin(plugin, plugin_target_name)
add_plugin_config(plugin_target_name, RAILS_PLUGIN_CONFIG, :log_file => log_file)
end
end

def install_passenger_plugins
PASSENGER_PLUGINS.each do |plugin|
add_plugin(plugin, plugin)
add_plugin_config(plugin, PASSENGER_PLUGIN_CONFIG)
end
end

def add_plugin_config(plugin_target_name, config_template, options = {})
FileUtils.mkdir_p(munin_plugin_config_path)
template = ERB.new config_template
File.open(File.join(munin_plugin_config_path, plugin_target_name), "w+") do |file|
file << template.result(binding)
end
end

def add_plugin(plugin_file, plugin_target_name = nil)
FileUtils.mkdir_p(munin_plugins_path)
plugin_target_name ||= plugin_file
`ln -nsf "#{File.join(munin_dir, plugin_file)}" "#{munin_plugins_path}/#{plugin_target_name}"`
end

def munin_plugins_path
"/etc/munin/plugins"
end

def munin_plugin_config_path
"/etc/munin/plugin-conf.d"
end

def munin_dir
File.join(File.dirname(__FILE__), "..", "..", "munin")
end
end
end
48 changes: 48 additions & 0 deletions munin/munin_passenger_memory_stats
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env ruby
pod=<<-POD
=head1 NAME
passenger_memory_stats - Munin plugin to monitor the memory usage of passenger application servers.
Monitors the memory consumed by passenger instances.
=head1 APPLICABLE SYSTEMS
All systems that have passenger installed.
=head1 CONFIGURATION
The plugin needs to execute passenger-memory-stats.
This configuration section shows the defaults of the plugin:
[passenger_*]
user root
command /usr/local/bin/ruby %c
Options
env.passenger_memory_stats '/path/to/passenger-memory-stats' # Path to passenger memory status.
env.graph_category 'App' # Graph Category. Defaults to App.
ln -s /usr/share/munin/plugins/passenger_memory_stats /etc/munin/plugins/passenger_memory_stats
=head1 INTERPRETATION
The plugin shows the memory consumed by passenger instances.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
1.9.7
=head1 BUGS
None known
=head1 AUTHOR
Ilya Lityuga
Bart ten Brinke - railsdoctors.com
=head1 LICENSE
MIT
POD
require 'rubygems'
require 'munin-plugins-rails'
Munin::PassengerMemoryStats.new(ARGV, ENV).run
51 changes: 51 additions & 0 deletions munin/munin_passenger_queue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env ruby
pod=<<-POD
=head1 NAME
passenger_queue - Munin plugin to monitor passenger queue.
Monitors the amount of requests in global queue.
=head1 APPLICABLE SYSTEMS
All systems that have passenger installed.
=head1 CONFIGURATION
The plugin needs to execute passenger-status.
This configuration section shows the defaults of the plugin:
[passenger_*]
user root
command /usr/local/bin/ruby %c
Options
env.passenger_status '/path/to/passenger-status' # Path to passenger-status
env.apache_pid_file '/path/to/apache2.pid' # Path to passenger-status (like /var/run/apache2.pid)
env.graph_category 'App' # Graph Category. Defaults to App.
ln -s /usr/share/munin/plugins/passenger_queue /etc/munin/plugins/passenger_queue
=head1 INTERPRETATION
The plugin shows the current number of requests waiting on global queue.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
1.9.7
=head1 BUGS
None known
=head1 AUTHOR
Michaël Witrant - http://michael.witrant.com/
Bart ten Brinke - railsdoctors.com
Daniel Manges - http://gist.github.com/20319
=head1 LICENSE
MIT
POD
require 'rubygems'
require 'munin-plugins-rails'

Munin::PassengerQueue.new(ARGV, ENV).run
50 changes: 50 additions & 0 deletions munin/munin_passenger_status
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env ruby
pod=<<-POD
=head1 NAME
passenger_status - Munin plugin to monitor passenger application servers.
Monitors the amount of sessions and running, active and maximum amount of passenger instances.
=head1 APPLICABLE SYSTEMS
All systems that have passenger installed.
=head1 CONFIGURATION
The plugin needs to execute passenger-status.
This configuration section shows the defaults of the plugin:
[passenger_*]
user root
command /usr/local/bin/ruby %c
Options
env.passenger_status '/path/to/passenger-status' # Path to passenger-status
env.graph_category 'App' # Graph Category. Defaults to App.
env.apache_pid_file '/var/run/apache2.pid' # Use if you want to monitor multiple installations.
ln -s /usr/share/munin/plugins/passenger_status /etc/munin/plugins/passenger_status
=head1 INTERPRETATION
The plugin shows the maximum, active and current number of running passenger instances.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
1.9.7.1
=head1 BUGS
None known
=head1 AUTHOR
Bart ten Brinke - railsdoctors.com
Daniel Manges - http://gist.github.com/20319
=head1 LICENSE
MIT
POD
require 'rubygems'
require 'munin-plugins-rails'

Munin::PassengerStatus.new(ARGV, ENV).run
53 changes: 53 additions & 0 deletions munin/munin_rails_database_time
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env ruby
pod=<<-POD
=head1 NAME
rails_database_time - Munin plugin to monitor the minimum, average and maximum database times.
=head1 APPLICABLE SYSTEMS
All systems that have a rails application log.
=head1 CONFIGURATION
The request-log-analyzer gem has to be intalled.
Also the script has to be able to access the rails log file and tail.
This configuration section shows the defaults of the plugin:
[rails_database_time]
env.log_file '/path/to/production.log'
user www-data
command /usr/local/bin/ruby %c
log_format rails3
Options
env.lines 50000 # Number of lines to tail
env.interval 300 # Munin interval in seconds (used for graphs and caching)
env.log_format # request-log-analyzer log format (passed to '--format')
env.request_log_analyzer '/usr/local/bin' # Path to gem. Use this for Debian.
env.graph_category 'App' # Graph Category. Defaults to App.
ln -s /usr/share/munin/plugins/rails_database_time /etc/munin/plugins/rails_database_time
=head1 INTERPRETATION
Three lines are graphed, showing the minimum, average and maximum database times.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
1.9.7
=head1 BUGS
None known
=head1 AUTHOR
Bart ten Brinke - railsdoctors.com
=head1 LICENSE
MIT
POD
require 'rubygems'
require 'munin-plugins-rails'

Munin::RailsDatabaseTime.new(ARGV, ENV).run
53 changes: 53 additions & 0 deletions munin/munin_rails_request_duration
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env ruby
pod=<<-POD
=head1 NAME
rails_request_duration - Munin plugin to monitor the minimum, average and maximum request duration.
=head1 APPLICABLE SYSTEMS
All systems that have a rails application log.
=head1 CONFIGURATION
The request-log-analyzer gem has to be intalled.
Also the script has to be able to access the rails log file and tail.
This configuration section shows the defaults of the plugin:
[rails_request_duration]
env.log_file '/path/to/production.log'
user www-data
command /usr/local/bin/ruby %c
log_format rails3
Options
env.lines 50000 # Number of lines to tail
env.interval 300 # Munin interval in seconds (used for graphs and caching)
env.log_format # request-log-analyzer log format (passed to '--format')
env.request_log_analyzer '/usr/local/bin' # Path to gem. Use this for Debian.
env.graph_category 'App' # Graph Category. Defaults to App.
ln -s /usr/share/munin/plugins/rails_request_duration /etc/munin/plugins/rails_request_duration
=head1 INTERPRETATION
Three lines are graphed, showing the minimum, average and maximum request times.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
1.9.7
=head1 BUGS
None known
=head1 AUTHOR
Bart ten Brinke - railsdoctors.com
=head1 LICENSE
MIT
POD
require 'rubygems'
require 'munin-plugins-rails'

Munin::RailsRequestDuration.new(ARGV, ENV).run
Loading

0 comments on commit 26a7dc6

Please sign in to comment.