Class: Munin::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/munin/command.rb

Constant Summary collapse

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'    
env.graph_category <%= graph_category %>
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    
env.graph_category <%= graph_category %>
DATA
PASSENGER_CATEGORY =
"Passenger"

Instance Method Summary collapse

Instance Method Details

#add_plugin(plugin_file, plugin_target_name = nil) ⇒ Object



61
62
63
64
65
# File 'lib/munin/command.rb', line 61

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

#add_plugin_config(plugin_target_name, graph_category, config_template, options = {}) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/munin/command.rb', line 53

def add_plugin_config(plugin_target_name, graph_category, 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

#install_application(args) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/munin/command.rb', line 36

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      
end

#install_passenger_pluginsObject



46
47
48
49
50
51
# File 'lib/munin/command.rb', line 46

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

#munin_dirObject



75
76
77
# File 'lib/munin/command.rb', line 75

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

#munin_plugin_config_pathObject



71
72
73
# File 'lib/munin/command.rb', line 71

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

#munin_plugins_pathObject



67
68
69
# File 'lib/munin/command.rb', line 67

def munin_plugins_path
  "/etc/munin/plugins"
end

#run(args) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/munin/command.rb', line 5

def run(args)
  if args.first == "install"
    install_passenger_plugins
  elsif args.first == "add"
    args.shift
    install_application(args)
  end
end