Class: Bipbip::Plugin::Gearman

Inherits:
Bipbip::Plugin show all
Defined in:
lib/bipbip/plugin/gearman.rb

Constant Summary collapse

JOB_PRIORITY_HIGH =
0
JOB_PRIORITY_NORMAL =
1
JOB_PRIORITY_LOW =
2

Instance Attribute Summary

Attributes inherited from Bipbip::Plugin

#config, #frequency, #metric_group, #name, #tags

Instance Method Summary collapse

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_schemaObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bipbip/plugin/gearman.rb', line 12

def metrics_schema
  [
    { name: 'jobs_queued_total', type: 'gauge', unit: 'Jobs' },
    { name: 'jobs_active_total', type: 'gauge', unit: 'Jobs' },
    { name: 'jobs_waiting_total', type: 'gauge', unit: 'Jobs' },

    { name: 'jobs_queued_total_low', type: 'gauge', unit: 'Jobs' },
    { name: 'jobs_queued_total_normal', type: 'gauge', unit: 'Jobs' },
    { name: 'jobs_queued_total_high', type: 'gauge', unit: 'Jobs' }
  ]
end

#monitorObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bipbip/plugin/gearman.rb', line 24

def monitor
  stats = _fetch_gearman_status

  jobs_queued_total = 0
  jobs_active_total = 0
  stats.each do |_function_name, data|
    jobs_queued_total += data[:queue].to_i
    jobs_active_total += data[:active].to_i
  end

  priority_stats = {}
  if config['persistence'] == 'mysql'
    stats = _fetch_mysql_priority_stats(config)
    priority_stats = {
      jobs_queued_total_high: stats[JOB_PRIORITY_HIGH],
      jobs_queued_total_normal: stats[JOB_PRIORITY_NORMAL],
      jobs_queued_total_low: stats[JOB_PRIORITY_LOW]
    }
  end

  {
    jobs_queued_total: jobs_queued_total,
    jobs_active_total: jobs_active_total,
    jobs_waiting_total: (jobs_queued_total - jobs_active_total)
  }.merge(priority_stats)
end