Class: Beaneater::Stats

Inherits:
PoolCommand show all
Defined in:
lib/beaneater/stats.rb

Overview

Represents stats related to the beanstalkd pool.

Instance Attribute Summary

Attributes inherited from PoolCommand

#pool

Instance Method Summary collapse

Methods inherited from PoolCommand

#combine_stats, #initialize, #sum_items, #transmit_to_all

Constructor Details

This class inherits a constructor from Beaneater::PoolCommand

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Defines a cached method for looking up data for specified key Protects against infinite loops by checking stacktrace


32
33
34
35
36
37
38
39
40
41
# File 'lib/beaneater/stats.rb', line 32

def method_missing(name, *args, &block)
  if caller.first !~ /`(method_missing|data')/ && data.keys.include?(name.to_s)
    self.class.class_eval <<-CODE, __FILE__, __LINE__
      def #{name}; data[#{name.inspect}]; end
    CODE
    data[name.to_s]
  else # no key matches or caught infinite loop
    super
  end
end

Instance Method Details

#[](key) ⇒ String, Integer

Returns value for specified key.

Examples:

@bp.stats['total_connections'] # => 4

Parameters:

  • key (String, Symbol)

    Name of key to retrieve

Returns:

  • (String, Integer)

    Value of specified key


25
26
27
# File 'lib/beaneater/stats.rb', line 25

def [](key)
  data[key]
end

#dataBeaneater::StatStruct (protected)

Returns struct based on stats data merged from all connections.

Examples:

self.data # => { 'version' : 1.7, 'total_connections' : 23 }
self.data.total_connections # => 23

Returns:


52
53
54
# File 'lib/beaneater/stats.rb', line 52

def data
  StatStruct.from_hash(transmit_to_all('stats', :merge => true)[:body])
end

#keysArray<String>

Returns keys for stats data

Examples:

@bp.stats.keys # => ["version", "total_connections"]

Returns:

  • (Array<String>)

    Set of keys for stats.


14
15
16
# File 'lib/beaneater/stats.rb', line 14

def keys
  data.keys
end