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, #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

#float_roundingsObject



20
21
22
23
24
# File 'lib/bipbip/plugin/redis.rb', line 20

def float_roundings
  {
      'mem_fragmentation_ratio' => 2
  }
end

#metrics_schemaObject



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

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bipbip/plugin/redis.rb', line 26

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|
    if !roundings[key].nil?
      data[key] = stats[key].to_f.round(roundings[key])
    else
      data[key] = stats[key].to_i
    end
  end
  data
end