Class: MuninManager::Plugins::StarlingQueue

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActsAsMuninPlugin

included

Constructor Details

#initialize(host, port) ⇒ StarlingQueue

Returns a new instance of StarlingQueue.



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

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

Class Method Details

.runObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/munin_manager/plugins/starling_queue.rb', line 61

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

#configObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/munin_manager/plugins/starling_queue.rb', line 37

def config
  graph_names = queues_stats.keys.map{|n| n.to_s.tr(':', '_')}
  graph_config = "    graph_title Starling queues\n    graph_args --base 1000\n    graph_vlabel items\n    graph_category \#{@category}\n    graph_order \#{graph_names.sort.join(' ')}\n  END\n\n  queues_stats.inject(graph_config) do |stat_config, stat|\n    stat[1].each do |var,value|\n      graph_config << \"\#{format_for_munin(stat[0])}.\#{var} \#{value}\\n\"\n    end\n    graph_config\n  end\nend\n".gsub(/  +/, '')

#queues_statsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/munin_manager/plugins/starling_queue.rb', line 18

def queues_stats
  defaults = {
    'type' => 'GAUGE',
    'draw' => 'LINE2'
  }
  stats = @starling.available_queues.inject({}) do |stats, queue_name|
    queue,item = queue_name.split(/:/, 2)
    stats["queue_#{queue_name}_items"] = defaults.merge({
      :label => "#{queue}[#{item}] items"
    })
    stats["queue_#{queue_name}_expired_items"] = defaults.merge({
      :label => "#{queue}[#{item}] expired"
    })
    stats
  end

  return stats
end

#valuesObject



55
56
57
58
59
# File 'lib/munin_manager/plugins/starling_queue.rb', line 55

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