Class: Bipbip::Plugin::Mongodb
- Inherits:
-
Bipbip::Plugin
- Object
- Bipbip::Plugin
- Bipbip::Plugin::Mongodb
- Defined in:
- lib/bipbip/plugin/mongodb.rb
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_schema ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bipbip/plugin/mongodb.rb', line 5 def metrics_schema [ { 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' }, { name: 'total_index_size', type: 'gauge', unit: 'MB' }, { name: 'total_index_size_percentage_of_memory', type: 'gauge', unit: '%' } ] end |
#monitor ⇒ Object
27 28 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 |
# File 'lib/bipbip/plugin/mongodb.rb', line 27 def monitor status = fetch_server_status all_index_size = total_index_size data = {} 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 if status['repl'] && status['repl']['ismaster'] == true slow_queries_status = fetch_slow_queries_status data['slow_queries_count'] = slow_queries_status['total']['count'] data['slow_queries_time_avg'] = slow_queries_status['total']['time'].to_f / (slow_queries_status['total']['count'].to_f.nonzero? || 1) data['slow_queries_time_max'] = slow_queries_status['max']['time'] end unless router? data['total_index_size'] = all_index_size / (1024 * 1024) data['total_index_size_percentage_of_memory'] = (all_index_size.to_f / total_system_memory.to_f) * 100 end data end |