Class: Bipbip::Plugin::Mongodb

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

Instance Attribute Summary

Attributes inherited from Bipbip::Plugin

#config, #metric_group, #name, #pid

Instance Method Summary collapse

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_schemaObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bipbip/plugin/mongodb.rb', line 7

def metrics_schema
  [
      {:name => 'flushing_last_ms', :type => 'gauge', :unit => 'ms'},
      {:name => 'btree_misses', :type => 'gauge', :unit => 'misses'},
      {:name => 'op_inserts', :type => 'counter'},
      {:name => 'op_queries', :type => 'counter'},
      {:name => 'op_updates', :type => 'counter'},
      {:name => 'op_deletes', :type => 'counter'},
      {:name => 'op_getmores', :type => 'counter'},
      {:name => 'op_commands', :type => 'counter'},
      {:name => 'connections_current', :type => 'gauge'},
      {:name => 'mem_resident', :type => 'gauge', :unit => 'MB'},
      {:name => 'mem_mapped', :type => 'gauge', :unit => 'MB'},
      {:name => 'mem_pagefaults', :type => 'counter', :unit => 'faults'},
      {:name => 'globalLock_currentQueue', :type => 'gauge'},
      {:name => 'replication_lag', :type => 'gauge', :unit => 'Seconds'},
      {:name => 'slow_queries_count', :type => 'gauge_f', :unit => 'Queries'},
      {:name => 'slow_queries_time_avg', :type => 'gauge_f', :unit => 'Seconds'},
      {:name => 'slow_queries_time_max', :type => 'gauge_f', :unit => 'Seconds'},
  ]
end

#monitorObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/bipbip/plugin/mongodb.rb', line 29

def monitor
  @mongodb_client = nil

  status = fetch_server_status
  slow_queries_status = fetch_slow_queries_status

  data = {}

  if status['indexCounters']
    data['btree_misses'] = status['indexCounters']['misses'].to_i
  end
  if status['backgroundFlushing']
    data['flushing_last_ms'] = status['backgroundFlushing']['last_ms'].to_i
  end
  if status['opcounters']
    data['op_inserts'] = status['opcounters']['insert'].to_i
    data['op_queries'] = status['opcounters']['query'].to_i
    data['op_updates'] = status['opcounters']['update'].to_i
    data['op_deletes'] = status['opcounters']['delete'].to_i
    data['op_getmores'] = status['opcounters']['getmore'].to_i
    data['op_commands'] = status['opcounters']['command'].to_i
  end
  if status['connections']
    data['connections_current'] = status['connections']['current'].to_i
  end
  if status['mem']
    data['mem_resident'] = status['mem']['resident'].to_i
    data['mem_mapped'] = status['mem']['mapped'].to_i
  end
  if status['extra_info']
    data['mem_pagefaults'] = status['extra_info']['page_faults'].to_i
  end
  if status['globalLock'] && status['globalLock']['currentQueue']
    data['globalLock_currentQueue'] = status['globalLock']['currentQueue']['total'].to_i
  end
  if status['repl'] && status['repl']['secondary'] == true
    data['replication_lag'] = replication_lag
  end

  data['slow_queries_count'] = slow_queries_status['total']['count']
  data['slow_queries_time_avg'] = slow_queries_status['total']['count'] > 0 ? (slow_queries_status['total']['time'].to_f/slow_queries_status['total']['count'].to_f) : 0
  data['slow_queries_time_max'] = slow_queries_status['max']['time']

  data
end