Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passenger status config updated for Passenger 4 #24

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
15 changes: 14 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ This project contains munin plugins that not only work in munin, but are also co
Most things in this repository rely heavily on the request-log-analyzer gem.
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.

== About this fork ({sce/munin-plugins-rails}[https://github.com/sce/munin-plugins-rails])

Upstream is {barttenbrinnke/munin-plugins-rails}[https://github.com/barttenbrinke/munin-plugins-rails]. This fork has the following branches as of writing:

* {rvm_support}[https://github.com/sce/munin-plugins-rails/tree/rvm_support] - The patches from {huangxiangdan's fork}[https://github.com/huangxiangdan/munin-plugins-rails] that enable rvm support.
* {refactor_passenger_status}[https://github.com/sce/munin-plugins-rails/tree/refactor_passenger_status] - The patch from whatcould that fixes Passenger 4 support plus patch from sce to clean up plugin.
* {passenger4_rvm}[https://github.com/sce/munin-plugins-rails/tree/passenger4_rvm] - The two above branches merged.
* master - The passenger4_rvm branch plus this section added to the README.rdoc.

The master branch will be rebased at my discretion, so do not use or rely on it. (It should only contain patches relevant only for this particular repository anyway.)

This section is the only addition to this README from upstream. The rest of this file is unmodified.

== What's in the box?
* passenger_memory_stats - Munin plugin to monitor the memory usage of passenger application servers.
* pasenger_queue - Montoring of passenger queue lenth.
Expand Down Expand Up @@ -74,4 +87,4 @@ Happy monitoring!
* Screenshots http://barttenbrinke.github.com/munin-plugins-rails/
* Munin: http://munin.projects.linpro.no/wiki/ConcisePlugins
* Munin Plugin Starter http://www.packtpub.com/munin-plugin-starter/book
* License: MIT
* License: MIT
41 changes: 23 additions & 18 deletions lib/munin/command.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'fileutils'
require 'erb'
module Munin
class Command
class Command
def run(args)
if args.first == "install"
install_passenger_plugins
Expand All @@ -16,18 +16,18 @@ def run(args)
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'
command <%= ruby_path %> %c
env.passenger_status passenger-status
env.passenger_memory_stats passenger-memory-stats
env.graph_category <%= graph_category %>
DATA

RAILS_PLUGIN_CONFIG = <<-DATA
[<%= plugin_target_name %>]
[<%= 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
command <%= ruby_path %> %c
env.request_log_analyzer request-log-analyzer
env.graph_category <%= graph_category %>
DATA

Expand All @@ -36,44 +36,49 @@ def run(args)
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, app_name, RAILS_PLUGIN_CONFIG, :log_file => log_file)
end
add_plugin_config(plugin_target_name, app_name, ruby_path, 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_CATEGORY, PASSENGER_PLUGIN_CONFIG)
add_plugin_config(plugin, PASSENGER_CATEGORY, ruby_path, PASSENGER_PLUGIN_CONFIG)
end
end

def add_plugin_config(plugin_target_name, graph_category, config_template, options = {})
FileUtils.mkdir_p(munin_plugin_config_path)
def add_plugin_config(plugin_target_name, graph_category, ruby_path, 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)
file << template.result(binding)
end
end

def add_plugin(plugin_file, plugin_target_name = nil)
FileUtils.mkdir_p(munin_plugins_path)
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}"`
`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
end

def munin_dir
File.join(File.dirname(__FILE__), "..", "..", "munin")
end

def ruby_path
"/usr/bin/env GEM_PATH=#{ENV['GEM_PATH']} GEM_HOME=#{ENV['GEM_HOME']} PATH=#{ENV['PATH']} ruby"
end
end
end
end
4 changes: 2 additions & 2 deletions lib/munin/plugins/passenger_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Munin
class PassengerQueue < RequestLogAnalyzerPlugin
def ensure_configuration
require_passenger_status
super
super
end

def config
Expand All @@ -22,7 +22,7 @@ def config

def run
status = run_command(passenger_status, debug)
if status =~ /Version : 4/
if status =~ /Version : [45]/
status =~ /Requests in top-level queue\s+:\s+(\d+)/
puts "requests.value #{$1}"
else
Expand Down
51 changes: 23 additions & 28 deletions lib/munin/plugins/passenger_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def ensure_configuration

def config
status = `#{passenger_status}`
values = parse(status)

status =~ /max\s+=\s+(\d+)/
upper_limit = $1 || 150
upper_limit = values[:max] || 150

puts <<-CONFIG
graph_category #{graph_category}
Expand All @@ -30,43 +30,38 @@ def config

def run
status = run_command(passenger_status, debug)
values = parse(status)

if status =~ /Version : 4/
run_version4(status)
else
run_version3(status)
end
puts "max.value %s" % values[:max]
puts "running.value %s" % values[:running]
puts "active.value %s" % values[:active]
puts "sessions.value %s" % values[:sessions]
end

private
def run_version4(status)
status =~ /Max pool size\s+:\s+(\d+)/
puts "max.value #{$1}"

status =~ /Processes\s+:\s+(\d+)/
puts "running.value #{$1}"
def parse(status)
values = {}

active_processes = status.scan(/Sessions:\s+(\d+)/).flatten.select { |count| count.to_i != 0 }.size
puts "active.value #{active_processes}"
if status =~ /Version : [45]/
values[:max] = status =~ /Max pool size\s+:\s+(\d+)/ && $1
values[:running] = status =~ /Processes\s+:\s+(\d+)/ && $1

total_sessions = 0
status.scan(/Sessions: (\d+)/).flatten.each { |count| total_sessions += count.to_i }
puts "sessions.value #{total_sessions}"
end
sessions = status.scan(/Sessions: (\d+)/).flatten.map(&:to_i).select { |num| num > 0 }

def run_version3(status)
status =~ /max\s+=\s+(\d+)/
puts "max.value #{$1}"
values[:sessions] = sessions.inject(&:+) || 0
values[:active] = sessions.size

status =~ /count\s+=\s+(\d+)/
puts "running.value #{$1}"
else
values[:max] = status =~ /max\s+=\s+(\d+)/ && $1
values[:running] = status =~ /count\s+=\s+(\d+)/ && $1
values[:active] = status =~ /active\s+=\s+(\d+)/ && $1

status =~ /active\s+=\s+(\d+)/
puts "active.value #{$1}"
values[:sessions] = status.scan(/Sessions: (\d+)/).flatten.inject(0) { |total, count| total += count.to_i }
end

total_sessions = 0
status.scan(/Sessions: (\d+)/).flatten.each { |count| total_sessions += count.to_i }
puts "sessions.value #{total_sessions}"
values
end

end
end
2 changes: 1 addition & 1 deletion lib/munin/rails_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def handle_arguments(args, environment)
super

self.interval = environment['interval'] ? environment['interval'].to_i : 300
self.number_of_lines = environment['lines'] || 50000
self.number_of_lines = environment['lines'] || 100000
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')
Expand Down
Binary file added munin-plugins-rails-0.2.12.gem
Binary file not shown.