Class: Munin::Command
- Inherits:
-
Object
- Object
- Munin::Command
- 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 =
"[<%= plugin_target_name %>]\nuser root\ncommand ruby %c\nenv.passenger_status passenger-status\nenv.passenger_memory_stats passenger-memory-stats\nenv.graph_category <%= graph_category %>\n"
- RAILS_PLUGIN_CONFIG =
"[<%= plugin_target_name %>] \nenv.log_file <%= options[:log_file] %>\nuser root\ncommand ruby %c\nenv.request_log_analyzer request-log-analyzer\nenv.graph_category <%= graph_category %>\nenv.log_format rails3\n"
- PASSENGER_CATEGORY =
"Passenger"
Instance Method Summary collapse
- #add_plugin(plugin_file, plugin_target_name = nil) ⇒ Object
- #add_plugin_config(plugin_target_name, graph_category, config_template, options = {}) ⇒ Object
- #install_application(args) ⇒ Object
- #install_passenger_plugins ⇒ Object
- #munin_dir ⇒ Object
- #munin_plugin_config_path ⇒ Object
- #munin_plugins_path ⇒ Object
- #run(args) ⇒ Object
Instance Method Details
#add_plugin(plugin_file, plugin_target_name = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/munin/command.rb', line 62 def add_plugin(plugin_file, plugin_target_name = nil) FileUtils.mkdir_p(munin_plugins_path) plugin_source_path = File.join(munin_dir, plugin_file) plugin_target_path = File.join(munin_plugins_path, plugin_target_name || plugin_file) File.unlink plugin_target_path if File.symlink?(plugin_target_path) File.symlink plugin_source_path, plugin_target_path end |
#add_plugin_config(plugin_target_name, graph_category, config_template, options = {}) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/munin/command.rb', line 54 def add_plugin_config(plugin_target_name, graph_category, config_template, = {}) 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
37 38 39 40 41 42 43 44 45 |
# File 'lib/munin/command.rb', line 37 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_plugins ⇒ Object
47 48 49 50 51 52 |
# File 'lib/munin/command.rb', line 47 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_dir ⇒ Object
80 81 82 |
# File 'lib/munin/command.rb', line 80 def munin_dir File.join(File.dirname(__FILE__), "..", "..", "munin") end |
#munin_plugin_config_path ⇒ Object
76 77 78 |
# File 'lib/munin/command.rb', line 76 def munin_plugin_config_path "/etc/munin/plugin-conf.d" end |
#munin_plugins_path ⇒ Object
72 73 74 |
# File 'lib/munin/command.rb', line 72 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 |