Class: Starling

Inherits:
Object
  • Object
show all
Defined in:
lib/munin_manager/starling/starling_stats.rb

Instance Method Summary collapse

Instance Method Details

#queue_namesObject



63
64
65
# File 'lib/munin_manager/starling/starling_stats.rb', line 63

def queue_names
  return available_queues
end

#sizeof(queue, statistics = nil) ⇒ Object

returns the number of items in queue. If queue is :all, a hash of all queue sizes will be returned.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/munin_manager/starling/starling_stats.rb', line 49

def sizeof(queue, statistics = nil)
  statistics ||= stats

  if queue == :all
    queue_sizes = {}
    available_queues(statistics).each do |queue|
      queue_sizes[queue] = sizeof(queue, statistics)
    end
    return queue_sizes
  end

  statistics.inject(0) { |m,(k,v)| m + v["queue_#{make_cache_key(queue)}_items"].to_i }
end

#statsObject

Raises:

  • (MemCacheError)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/munin_manager/starling/starling_stats.rb', line 2

def stats
  raise MemCacheError, "No active servers" unless active?
  server_stats = {}

  @servers.each do |server|
    sock = server.socket
    raise MemCacheError, "No connection to server" if sock.nil?

    value = nil
    begin
      sock.write "stats\r\n"
      stats = {}
      while line = sock.gets do
        break if line == "END\r\n"
        if line =~ /^STAT/ then
          stat, name, value = line.split
          stats[name] = case name
                        when 'version'
                          value
                        when 'rusage_user', 'rusage_system' then
                          seconds, microseconds = value.split(/:/, 2)
                          microseconds ||= 0
                          Float(seconds) + (Float(microseconds) / 1_000_000)
                        else
                          if value =~ /^\d+$/ then
                            value.to_i
                          else
                            value
                          end
                        end
        end
      end
      server_stats["#{server.host}:#{server.port}"] = stats
    rescue SocketError, SystemCallError, IOError => err
      puts err.inspect
      server.close
      raise MemCacheError, err.message
    end
  end

  server_stats
end