munin_manager 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.2
1
+ 1.2.3
data/bin/munin_manager CHANGED
@@ -11,11 +11,10 @@ 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> [options]"
14
+ opts.banner = "Usage: munin_manager [options]"
15
15
  opts.separator ""
16
16
 
17
- opts.separator "Commands:"
18
- opts.separator "PLUGIN_NAME is of the form <plugin>[:<symlink>]"
17
+ opts.separator "PLUGIN_NAME is of the form <plugin>[.<symlink name>]"
19
18
  opts.separator ""
20
19
 
21
20
  opts.on("-l", "--list", "List available plugins to install") do
@@ -28,7 +28,7 @@ module MuninManager
28
28
  end
29
29
 
30
30
  def install(options)
31
- install_as = options.install_name.split(":").last
31
+ install_as = options.install_name
32
32
  symlink = File.join(options.plugin_dir, install_as)
33
33
  runner = File.join(File.dirname(__FILE__), "..", "..", "bin", "runner")
34
34
  runner = File.expand_path(runner)
@@ -53,7 +53,7 @@ module MuninManager
53
53
 
54
54
  # Default uninstaller. Override in included classes if the default is not sufficient
55
55
  def uninstall(options)
56
- install_as = options.install_name.split(":").last
56
+ install_as = options.install_name
57
57
  symlink = File.join(options.plugin_dir, install_as)
58
58
 
59
59
  unless File.exists?(symlink)
@@ -22,7 +22,7 @@ module MuninManager
22
22
  end
23
23
 
24
24
  def search(name)
25
- str = name.to_s.split(':', 2).first
25
+ str = name.to_s.split('.', 2).first
26
26
  detect {|plugin_klass| plugin_klass.plugin_name.starts_with?(str)}
27
27
  end
28
28
  end
@@ -2,6 +2,23 @@ module MuninManager
2
2
  class Plugins::HaproxyAppResponseTime < LogReader
3
3
  include ActsAsMuninPlugin
4
4
 
5
+ EXTRACTORS = {
6
+ :client_connect => lambda {|line| line.split(/\s+/)[9].split("/")[0].to_f},
7
+ :waiting_in_queue => lambda {|line| line.split(/\s+/)[9].split("/")[1].to_f},
8
+ :server_connect => lambda {|line| line.split(/\s+/)[9].split("/")[2].to_f},
9
+ :server_response => lambda {|line| line.split(/\s+/)[9].split("/")[3].to_f},
10
+ :rails_action => lambda {|line| (line.match(/\{([0-9.]+)\}/).captures[0].to_f * 1000) rescue 0},
11
+ :total => lambda {|line| line.split(/\s+/)[9].split("/")[4].to_f},
12
+ }
13
+
14
+ def initialize(logfile, options)
15
+ @measure = options[:measure].to_sym
16
+ raise ArgumentError,
17
+ "I do not know how to measure `%s`" % options[:measure] unless EXTRACTORS.key?(@measure)
18
+
19
+ super(logfile)
20
+ end
21
+
5
22
  def data
6
23
  @data ||= Hash.new {|h, k| h[k] = Hash.new{|d,v| d[v] = Array.new}}
7
24
  end
@@ -13,13 +30,8 @@ module MuninManager
13
30
  server, port = chunks[8].split(":") rescue []
14
31
  server_name = server.split("/")[1] rescue nil
15
32
  next if server_name.nil?
16
- timers = chunks[9].split("/") rescue []
17
- data[server_name][:client_connect] << timers[0].to_f
18
- data[server_name][:waiting_in_queue] << timers[1].to_f
19
- data[server_name][:server_connect] << timers[2].to_f
20
- data[server_name][:server_response] << timers[3].to_f
21
- data[server_name][:rails_action] << line.match(/\{([0-9.]+)\}/).captures[0].to_f rescue 0
22
- data[server_name][:total] << timers[4].to_f
33
+
34
+ data[server_name][@measure] << EXTRACTORS[@measure].call(line)
23
35
  end
24
36
  end
25
37
 
@@ -45,10 +57,11 @@ module MuninManager
45
57
  server_name = server.split("/")[1] rescue nil
46
58
  server_hash[server_name] = '' unless server_name.nil?
47
59
  end
48
- default = [:client_connect,:waiting_in_queue, :server_connect, :server_response, :rails_action, :total]
60
+
61
+ default = Array(@measure)
49
62
 
50
63
  config_text = <<-LABEL
51
- graph_title HAProxy Response Breakdown
64
+ graph_title HAProxy App Server #{@measure}
52
65
  graph_vlabel time (secs)
53
66
  graph_category Haproxy
54
67
  LABEL
@@ -67,7 +80,12 @@ graph_category Haproxy
67
80
  log_file = ENV['log_file'] || "/var/log/haproxy.log"
68
81
  allowed_commands = ['config']
69
82
 
70
- haproxy = new(log_file)
83
+ measure = ENV['measure']
84
+ # Try to figure out what we're trying to measure from the symlink name
85
+ measure ||= File.basename($0).split(".", 2).last
86
+ measure = nil unless EXTRACTORS.key?(measure.to_sym)
87
+
88
+ haproxy = new(log_file, :measure => measure || 'total')
71
89
 
72
90
  if cmd = ARGV[0] and allowed_commands.include? cmd then
73
91
  puts haproxy.send(cmd.to_sym)
@@ -77,7 +95,7 @@ graph_category Haproxy
77
95
  end
78
96
  end
79
97
 
80
- def self.help_text
98
+ def self.help_text(options = {})
81
99
  %Q{
82
100
  #{plugin_name.capitalize} Munin Plugin
83
101
  ===========================
@@ -85,7 +103,7 @@ graph_category Haproxy
85
103
  Please remember to add something like the lines below to /etc/munin/plugin-conf.d/munin-node
86
104
  if the haproxy log file is not at /var/log/haproxy.log
87
105
 
88
- [#{plugin_name}]
106
+ [#{options[:symlink]}]
89
107
  env.log_file /var/log/custom/haproxy.log
90
108
 
91
109
  Also, make sure that the '/var/lib/munin/plugin-state' is writable by munin.
@@ -60,7 +60,7 @@ total.label Total Response Time
60
60
  end
61
61
  end
62
62
 
63
- def self.help_text
63
+ def self.help_text(options = {})
64
64
  %Q{
65
65
  #{plugin_name.capitalize} Munin Plugin
66
66
  ===========================
@@ -68,7 +68,7 @@ total.label Total Response Time
68
68
  Please remember to add something like the lines below to /etc/munin/plugin-conf.d/munin-node
69
69
  if the haproxy log file is not at /var/log/haproxy.log
70
70
 
71
- [#{plugin_name}]
71
+ [#{options[:symlink]}]
72
72
  env.log_file /var/log/custom/haproxy.log
73
73
 
74
74
  Also, make sure that the '/var/lib/munin/plugin-state' is writable by munin.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: munin_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rohith Ravi