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, #frequency, #metric_group, #name, #tags
Instance Method Summary collapse
- #metrics_schema ⇒ Object
- #monitor ⇒ Object
- #sanitize_queue_name(queue) ⇒ Object
- #with_resque_connection ⇒ Object
Methods inherited from Bipbip::Plugin
factory, factory_from_plugin, #initialize, #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
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bipbip/plugin/resque.rb', line 6 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' }, { name: 'num_failures', type: 'counter', unit: 'Jobs' } ] 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
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bipbip/plugin/resque.rb', line 41 def monitor data = {} with_resque_connection do data['num_workers'] = ::Resque.workers.count data['num_idle_workers'] = ::Resque.workers.count(&:idle?) data['num_active_workers'] = data['num_workers'] - data['num_idle_workers'] data['num_failures'] = ::Resque::Failure.count ::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
23 24 25 |
# File 'lib/bipbip/plugin/resque.rb', line 23 def sanitize_queue_name(queue) queue.gsub(/\s/, '-') end |
#with_resque_connection ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bipbip/plugin/resque.rb', line 27 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 |