Class: Bipbip::Plugin::Resque
- Inherits:
-
Bipbip::Plugin
- Object
- Bipbip::Plugin
- Bipbip::Plugin::Resque
- Defined in:
- lib/bipbip/plugin/resque.rb
Instance Attribute Summary
Attributes inherited from Bipbip::Plugin
#config, #metric_group, #name, #pid
Instance Method Summary collapse
- #metrics_schema ⇒ Object
- #monitor ⇒ Object
- #sanitize_queue_name(queue) ⇒ Object
- #with_resque_connection ⇒ Object
Methods inherited from Bipbip::Plugin
factory, #frequency, #initialize, #interrupt, #interrupted?, #metrics_names, #run, #source_identifier
Methods included from InterruptibleSleep
#interrupt_sleep, #interruptible_sleep
Constructor Details
This class inherits a constructor from Bipbip::Plugin
Instance Method Details
#metrics_schema ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bipbip/plugin/resque.rb', line 8 def metrics_schema schema_list = [ {:name => 'num_workers', :type => 'counter', :unit => 'Workers'}, {:name => 'num_idle_workers', :type => 'counter', :unit => 'Workers'}, {:name => 'num_active_workers', :type => 'counter', :unit => 'Workers'}, ] with_resque_connection do ::Resque.queues.each do |queue| schema_list << {:name => "queue_size_#{sanitize_queue_name(queue)}", :type => 'gauge', :unit => 'Jobs'} end end schema_list end |
#monitor ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bipbip/plugin/resque.rb', line 42 def monitor data = {} with_resque_connection do data['num_workers'] = ::Resque.workers.count data['num_idle_workers'] = ::Resque.workers.select { |w| w.idle? }.count data['num_active_workers'] = data['num_workers'] - data['num_idle_workers'] ::Resque.queues.each do |queue| data["queue_size_#{sanitize_queue_name(queue)}"] = ::Resque.size(queue).to_i end end data end |
#sanitize_queue_name(queue) ⇒ Object
24 25 26 |
# File 'lib/bipbip/plugin/resque.rb', line 24 def sanitize_queue_name(queue) queue.gsub(/\s/, '-') end |
#with_resque_connection ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bipbip/plugin/resque.rb', line 28 def with_resque_connection redis = ::Redis.new( :host => config['hostname'] || 'localhost', :port => config['port'] || 6369 ) redis.select config['database'] ::Resque.redis = redis ::Resque.redis.namespace = config['namespace'] unless config['namespace'].nil? yield redis.quit end |