Class: MuninManager::Plugins::HaproxyRps

Inherits:
Object
  • Object
show all
Includes:
ActsAsMuninPlugin
Defined in:
lib/munin_manager/plugins/haproxy_rps.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActsAsMuninPlugin

included

Constructor Details

#initialize(url, user, pass) ⇒ HaproxyRps

Returns a new instance of HaproxyRps.



10
11
12
13
14
15
16
17
# File 'lib/munin_manager/plugins/haproxy_rps.rb', line 10

def initialize(url, user, pass)
  @url = url
  @user = user
  @pass = pass
  @data = Hash.new{|h,k|h[k] = 0}
  @category = 'Haproxy'
  parse_csv
end

Class Method Details

.runObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/munin_manager/plugins/haproxy_rps.rb', line 73

def self.run
  url = ENV['URL'] || 'http://lb01.ffs.seriousops.com/haproxy?stats;csv'
  user = ENV['USERNAME'] || 'admin'
  pass = ENV['PASSWORD'] || 'pass'
  haproxy = new(url, user, pass)

  allowed_commands = ['config']

  if cmd = ARGV[0] and allowed_commands.include? cmd then
    puts haproxy.send(cmd.to_sym)
  else
    puts haproxy.values
  end
end

Instance Method Details

#configObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/munin_manager/plugins/haproxy_rps.rb', line 47

def config
  graph_config = <<-END.gsub(/  +/, '')
  graph_title Haproxy RPS / App Server
  graph_args --base 1000
  graph_vlabel ops/${graph_period}
  graph_category #{@category}
  graph_order #{@data.keys.sort.join(" ")}
  END
        
  stat_config = []
  ops_stats.each do |stat,config|
    config.each do |var,value|
      stat_config << "#{stat}.#{var} #{value}\n"
    end
  end
  return graph_config + stat_config.sort.join
end

#ops_statsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/munin_manager/plugins/haproxy_rps.rb', line 30

def ops_stats
  defaults = {
  'min' => 0,
  'type' => 'DERIVE',
  'draw' => 'LINE2',
  }

  stats = {
    
  }
  
  @data.each_key do |k|
    stats[k] = defaults.merge({:label => k})
  end
  return stats
end

#parse_csvObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/munin_manager/plugins/haproxy_rps.rb', line 19

def parse_csv
  base64 = Base64.encode64("#{@user}:#{@pass}")
  file = open(@url, {"Authorization" => "Basic #{base64}"})
  file.readline #skip first line
  file.each_line do |line|
    data_ary = line.split(",")
    host,port = data_ary[1].split(":")
    @data[host] += data_ary[7].to_i
  end
end

#valuesObject



65
66
67
68
69
70
71
# File 'lib/munin_manager/plugins/haproxy_rps.rb', line 65

def values
  ret = ''
  @data.each do |key, stat|
    ret << "#{key}.value #{stat}\n"
  end
  return ret
end