Class: MuninManager::Plugins::StarlingAge

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActsAsMuninPlugin

included

Constructor Details

#initialize(host, port) ⇒ StarlingAge

Returns a new instance of StarlingAge.



12
13
14
15
16
# File 'lib/munin_manager/plugins/starling_age.rb', line 12

def initialize(host, port)
  @host = "#{host}:#{port}"
  @starling = Starling.new(@host)
  @category = 'starling'
end

Class Method Details

.runObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/munin_manager/plugins/starling_age.rb', line 56

def self.run
  host = ENV['HOST'] || '127.0.0.1';
  port = ENV['PORT'] || 22122;
  starling = new(host, port)


  allowed_commands = ['config']

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

Instance Method Details

#age_statsObject



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

def age_stats
  defaults = {
    :type => 'GAUGE',
    :draw => 'AREA'
  }
  stats = @starling.available_queues.inject({}) do |stats, queue_name|
    queue,item = queue_name.split(/:/, 2)
    stats["queue_#{queue_name}_age"] = defaults.merge({
      :label => "#{queue}[#{item}] age"
    })
    stats
  end
end

#configObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/munin_manager/plugins/starling_age.rb', line 33

def config
  graph_names = age_stats.keys.map{|n| n.to_s.tr(':', '_')}
  graph_config = <<-END.gsub(/  +/, '')
    graph_title Starling Queues Age
    graph_vlabel seconds in queue
    graph_category #{@category}
    graph_order #{graph_names.sort.join(' ')}
  END

  age_stats.inject(graph_config) do |stat_config, stat|
    stat[1].each do |var,value|
      graph_config << "#{format_for_munin(stat[0])}.#{var} #{value}\n"
    end
    graph_config
  end
end

#valuesObject



50
51
52
53
54
# File 'lib/munin_manager/plugins/starling_age.rb', line 50

def values
  age_stats.inject("") do |ret, stat|
    ret << "#{format_for_munin(stat[0])}.value #{@starling.stats[@host][stat[0]]/1000.0}\n"
  end
end