Class: Riemann::Tools::Valkey

Inherits:
Object
  • Object
show all
Includes:
Riemann::Tools
Defined in:
lib/riemann/tools/valkey.rb,
lib/riemann/tools/valkey/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValkey

Returns a new instance of Valkey.



14
15
16
# File 'lib/riemann/tools/valkey.rb', line 14

def initialize
  @redis = Redis.new
end

Instance Attribute Details

#redisObject (readonly)

Returns the value of attribute redis.



12
13
14
# File 'lib/riemann/tools/valkey.rb', line 12

def redis
  @redis
end

Instance Method Details

#memory_state(metric) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/riemann/tools/valkey.rb', line 33

def memory_state(metric)
  if metric > 0.95
    "critical"
  elsif metric > 0.8
    "warning"
  else
    "ok"
  end
end

#tickObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/riemann/tools/valkey.rb', line 18

def tick
  redis = Redis.new
  memory_info = redis.info("MEMORY")
  used_memory = memory_info["used_memory"].to_i
  maxmemory = memory_info["maxmemory"].to_i

  memory_usage = used_memory.to_f / maxmemory
  report({
    service: "valkey memory",
    metric: memory_usage,
    state: memory_state(memory_usage),
    description: format("%.2f %%", memory_usage * 100)
  })
end