Class: Pimon::Probe::SystemMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/pimon/probe/system_memory.rb

Constant Summary collapse

TYPE_INDEX =
{
  mem: 1,
  swap: 2
}

Class Method Summary collapse

Class Method Details

.check(type) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/pimon/probe/system_memory.rb', line 9

def self.check(type)
  memory = `free -o -m`.split(/\n/)[TYPE_INDEX[type]].split(' ')

  return 0 if memory[1].to_i == 0
  # memory[1] holds total memory
  # memory[2] holds used memory
  ((memory[2].to_f / memory[1].to_f) * 100).to_i
end