Class: Bipbip::Plugin::Redis

Inherits:
Bipbip::Plugin show all
Defined in:
lib/bipbip/plugin/redis.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

#float_roundingsObject



18
19
20
21
22
# File 'lib/bipbip/plugin/redis.rb', line 18

def float_roundings
  {
    'mem_fragmentation_ratio' => 2
  }
end

#metrics_schemaObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/bipbip/plugin/redis.rb', line 7

def metrics_schema
  [
    { name: 'total_commands_processed', type: 'counter', unit: 'Commands' },
    { name: 'used_memory', type: 'gauge', unit: 'b' },
    { name: 'used_memory_rss', type: 'gauge', unit: 'b' },
    { name: 'mem_fragmentation_ratio', type: 'gauge', unit: 'Frag' },
    { name: 'connected_clients', type: 'gauge', unit: 'Clients' },
    { name: 'blocked_clients', type: 'gauge', unit: 'BlockedClients' }
  ]
end

#monitorObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bipbip/plugin/redis.rb', line 24

def monitor
  redis = RedisClient.new(
    host: config['hostname'],
    port: config['port']
  )
  stats = redis.info
  redis.quit

  roundings = float_roundings
  data = {}

  metrics_names.each do |key|
    data[key] = roundings[key].nil? ? stats[key].to_i : stats[key].to_f.round(roundings[key])
  end

  data
end