Class: What::Modules::Memory

Inherits:
Base
  • Object
show all
Defined in:
lib/what/modules/memory.rb

Constant Summary collapse

DEFAULTS =
{
  'warning' => '80%',
  'alert'   => '90%'
}

Instance Attribute Summary

Attributes inherited from Base

#interval

Instance Method Summary collapse

Methods inherited from Base

#identifier, #initialize, #initialize_module, #name, #shared_status, #start_monitoring, #status

Constructor Details

This class inherits a constructor from What::Modules::Base

Instance Method Details

#checkObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/what/modules/memory.rb', line 8

def check
  fields = self.memory_details
  @info = if fields.size == 2
            {
              'size'     => fields[0],
              'used'     => fields[0] - fields[1],
              'avail'    => fields[1],
              'use%'     => ((1.0 - (fields[1].to_f / fields[0])) * 100).round,
              'warning%' => @config['warning'].to_i,
              'alert%'   => @config['alert'].to_i
            }
          end
end

#detailsObject



34
35
36
# File 'lib/what/modules/memory.rb', line 34

def details
  @info
end

#healthObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/what/modules/memory.rb', line 22

def health
  if @info.nil?
    'alert'
  elsif @info['use%'] >= @info['alert%']
    'alert'
  elsif @info['use%'] >= @info['warning%']
    'warning'
  else
    'ok'
  end
end