entombedvirus-munin_manager 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'echoe'
2
- Echoe.new('munin_manager', '0.0.2') do |s|
2
+ Echoe.new('munin_manager', '0.0.3') do |s|
3
3
  s.description = "Tool to maintain and install munin plugins written in Ruby"
4
4
  s.author = "Rohith Ravi"
5
5
  s.email = "entombedvirus@gmail.com"
data/bin/munin_manager CHANGED
@@ -11,10 +11,12 @@ options = OpenStruct.new
11
11
  options.plugin_dir = "/etc/munin/plugins"
12
12
 
13
13
  parser = OptionParser.new do |opts|
14
- opts.banner = "Usage: munin_manager <command> [<plugin_name>[:<symlink_name>]] [options]"
14
+ opts.banner = "Usage: munin_manager <command> [options]"
15
15
  opts.separator ""
16
16
 
17
17
  opts.separator "Commands:"
18
+ opts.separator "PLUGIN_NAME is of the form <plugin>[:<symlink>]"
19
+ opts.separator ""
18
20
 
19
21
  opts.on("-l", "--list", "List available plugins to install") do
20
22
  buffer = []
@@ -40,26 +42,17 @@ parser = OptionParser.new do |opts|
40
42
  end
41
43
  end
42
44
 
43
- opts.on("-i", "--install PLUGIN_NAME [PLUGIN_NAME]", Array,
45
+ opts.on("-i", "--install PLUGIN_NAME[,PLUGIN_NAME]", Array,
44
46
  "Installs a plugin by creating a symlink in '%s'" % options.plugin_dir) do |names|
45
- if options.plugins = MuninManager::Plugins[*names]
46
47
  options.action = :install
47
48
  options.plugin_names = names
48
- else
49
- puts "'%s' plugin not found" % names.join
50
- end
51
49
  end
52
50
 
53
- opts.on("-u", "--uninstall PLUGIN_NAME [PLUGIN_NAME]", Array,
51
+ opts.on("-u", "--uninstall PLUGIN_NAME[,PLUGIN_NAME]", Array,
54
52
  "Removes plugins from '%s'" % options.plugin_dir,
55
53
  "if it is a symlink") do |names|
56
-
57
- if options.plugins = MuninManager::Plugins[*names]
58
54
  options.action = :uninstall
59
55
  options.plugin_names = names
60
- else
61
- puts "'#{names}' plugin not found"
62
- end
63
56
  end
64
57
 
65
58
  opts.separator ""
@@ -85,7 +78,18 @@ parser.parse!(ARGV)
85
78
  options.freeze!
86
79
 
87
80
  case options.action
88
- when :uninstall, :install
89
- plugins = Array(MuninManager::Plugins[*options.plugin_names])
90
- plugins.each {|p| p.send(options.action, options)}
81
+ when :install, :uninstall
82
+ options.plugin_names.each do |plugin_name|
83
+ plugin_klass = MuninManager::Plugins.search(plugin_name)
84
+
85
+ unless plugin_klass
86
+ STDERR.puts "ERROR: Matching plugin not found for '%s'" % plugin_name
87
+ exit(1)
88
+ end
89
+
90
+ new_options = options.dup
91
+ new_options.install_name = plugin_name
92
+
93
+ plugin_klass.send(options.action, new_options)
94
+ end
91
95
  end
@@ -23,24 +23,29 @@ module MuninManager
23
23
  downcase
24
24
  end
25
25
 
26
- def help_text
26
+ def help_text(options = {})
27
27
  # Any general info concerning the plugin. Should be overriden by included class
28
28
  end
29
29
 
30
30
  def install(options)
31
- symlink = File.join(options.plugin_dir, plugin_name)
31
+ install_as = options.install_name.split(":").last
32
+ symlink = File.join(options.plugin_dir, install_as)
32
33
  runner = File.join(File.dirname(__FILE__), "..", "..", "bin", "runner")
33
34
  runner = File.expand_path(runner)
34
35
 
35
- if File.exists?(symlink) && !options.force
36
- STDERR.puts "'%s' already exists. Please specify --force option to overwrite" % symlink
37
- return
36
+ if File.exists?(symlink)
37
+ if options.force
38
+ File.unlink(symlink)
39
+ else
40
+ STDERR.puts "'%s' already exists. Please specify --force option to overwrite" % symlink
41
+ return
42
+ end
38
43
  end
39
44
 
40
45
  STDOUT.puts "Installing '%s' at '%s'" % [plugin_name, symlink]
41
46
  FileUtils.ln_sf(runner, symlink)
42
47
 
43
- STDOUT.puts help_text
48
+ STDOUT.puts help_text(:symlink => install_as)
44
49
 
45
50
  rescue Errno::EACCES
46
51
  STDERR.puts "ERROR: Permission denied while attempting to install to '%s'" % symlink
@@ -48,7 +53,8 @@ module MuninManager
48
53
 
49
54
  # Default uninstaller. Override in included classes if the default is not sufficient
50
55
  def uninstall(options)
51
- symlink = File.join(options.plugin_dir, plugin_name)
56
+ install_as = options.install_name.split(":").last
57
+ symlink = File.join(options.plugin_dir, install_as)
52
58
 
53
59
  unless File.exists?(symlink)
54
60
  STDERR.puts "'%s' does not seem to exist. Aborting..." % symlink
@@ -62,6 +68,8 @@ module MuninManager
62
68
 
63
69
  STDOUT.puts "Removing '%s'..." % symlink
64
70
  File.unlink(symlink)
71
+ rescue Errno::EACCES
72
+ STDERR.puts "ERROR: Permission denied while attempting to uninstall '%s'" % symlink
65
73
  end
66
74
  end
67
75
 
@@ -1,6 +1,13 @@
1
1
  module MuninManager
2
2
  class Plugins::RailsResponseTime < LogReader
3
3
  include ActsAsMuninPlugin
4
+ attr_accessor :search_pattern
5
+
6
+ def initialize(log_file, options = {})
7
+ super(log_file)
8
+ @search_pattern = options[:search_pattern] || /.*/
9
+ @search_pattern = Regexp.new(@search_pattern) if @search_pattern.is_a?(String)
10
+ end
4
11
 
5
12
  def data
6
13
  @data ||= Hash.new {|h, k| h[k] = Array.new}
@@ -13,10 +20,12 @@ module MuninManager
13
20
 
14
21
  if line.starts_with?("Processing ")
15
22
  cols = line.split(/\s+/)
16
- current_action = cols[1]
23
+ current_action = cols[1] if self.search_pattern.match(cols[1])
24
+
17
25
  elsif line.starts_with?("Completed in ") && !current_action.nil?
18
26
  cols = line.split(/\s+/)
19
27
  data[current_action] << cols[2].to_f
28
+ current_action = nil
20
29
  end
21
30
 
22
31
  end
@@ -56,7 +65,7 @@ module MuninManager
56
65
  log_file = ENV['log_file'] || "/var/log/rails.log"
57
66
  allowed_commands = ['config']
58
67
 
59
- rails = new(log_file)
68
+ rails = new(log_file, :search_pattern => ENV['search_pattern'])
60
69
 
61
70
  if cmd = ARGV[0] and allowed_commands.include? cmd then
62
71
  puts rails.send(cmd.to_sym)
@@ -66,7 +75,7 @@ module MuninManager
66
75
  end
67
76
  end
68
77
 
69
- def self.help_text
78
+ def self.help_text(options = {})
70
79
  %Q{
71
80
  #{plugin_name.capitalize} Munin Plugin
72
81
  ===========================
@@ -74,8 +83,9 @@ module MuninManager
74
83
  Please remember to add something like the lines below to /etc/munin/plugin-conf.d/munin-node
75
84
  if the rails log file is not at /var/log/rails.log
76
85
 
77
- [#{plugin_name}]
86
+ [#{options[:symlink] || plugin_name}]
78
87
  env.log_file /var/log/custom/rails.log
88
+ env.search_pattern UsersController.*
79
89
 
80
90
  Also, make sure that the '/var/lib/munin/plugin-state' is writable by munin.
81
91
 
@@ -15,10 +15,15 @@ module MuninManager
15
15
 
16
16
  def [](*names)
17
17
  if names.length == 1
18
- return detect {|plugin| plugin.plugin_name == names.first}
18
+ return detect {|plugin_klass| plugin_klass.plugin_name == names.first}
19
19
  end
20
20
 
21
21
  names.map {|name| self[name]}
22
22
  end
23
+
24
+ def search(name)
25
+ str = name.to_s.split(':', 2).first
26
+ detect {|plugin_klass| plugin_klass.plugin_name.starts_with?(str)}
27
+ end
23
28
  end
24
29
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{munin_manager}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Rohith Ravi"]
9
- s.date = %q{2009-03-10}
9
+ s.date = %q{2009-04-09}
10
10
  s.description = %q{Tool to maintain and install munin plugins written in Ruby}
11
11
  s.email = %q{entombedvirus@gmail.com}
12
12
  s.executables = ["munin_manager", "runner"]
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.rubyforge_project = %q{munin_manager}
20
20
  s.rubygems_version = %q{1.3.1}
21
21
  s.summary = %q{Tool to maintain and install munin plugins written in Ruby}
22
- s.test_files = ["test/haproxy_response_time_test.rb", "test/log_reader_test.rb", "test/test_helper.rb", "test/rails_response_time_test.rb"]
22
+ s.test_files = ["test/haproxy_response_time_test.rb", "test/log_reader_test.rb", "test/rails_response_time_test.rb", "test/test_helper.rb"]
23
23
 
24
24
  if s.respond_to? :specification_version then
25
25
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -13,8 +13,12 @@ class RailsResponseTimeTest < Test::Unit::TestCase
13
13
  rescue
14
14
  # Do nothing
15
15
  end
16
+
17
+ def test_has_default_search_pattern
18
+ assert_kind_of Regexp, @reader.search_pattern
19
+ end
16
20
 
17
- def test_parsing
21
+ def test_parsing_with_default_search_pattern
18
22
  @reader.collect!
19
23
  assert @reader.data.keys.length > 0
20
24
 
@@ -23,6 +27,15 @@ class RailsResponseTimeTest < Test::Unit::TestCase
23
27
  end
24
28
  end
25
29
 
30
+ def test_parsing_with_non_default_search_string
31
+ @reader.search_pattern = /UsersController.*/
32
+ @reader.collect!
33
+
34
+ @reader.data.each_pair do |action_name, time|
35
+ assert_not_nil /UsersController.*/.match(action_name), "'%s' does not match search pattern" % action_name
36
+ end
37
+ end
38
+
26
39
  def test_config_parses_log
27
40
  assert @reader.config.split("\n").select {|line| not line.starts_with?("graph_")}.length > 0
28
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entombedvirus-munin_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rohith Ravi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-10 00:00:00 -07:00
12
+ date: 2009-04-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -84,5 +84,5 @@ summary: Tool to maintain and install munin plugins written in Ruby
84
84
  test_files:
85
85
  - test/haproxy_response_time_test.rb
86
86
  - test/log_reader_test.rb
87
- - test/test_helper.rb
88
87
  - test/rails_response_time_test.rb
88
+ - test/test_helper.rb