Class: What::Modules::Disk

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

Constant Summary collapse

DEFAULTS =
{
  'regexp' => '/$',
  'warning' => '90%',
  'alert'   => '99%'
}

Instance Attribute Summary

Attributes inherited from Base

#interval

Instance Method Summary collapse

Methods inherited from Base

#initialize, #name, #status

Constructor Details

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

Instance Method Details

#check!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/what/modules/disk.rb', line 13

def check!
  line = `df -h`.split("\n").grep(@regexp).first
  @info = if line
            fields = line.split(/\s+/)
            {
              'size'     => fields[1],
              'used'     => fields[2],
              'avail'    => fields[3],
              'use%'     => fields[4].to_i,
              'warning%' => @config['warning'].to_i,
              'alert%'   => @config['alert'].to_i,
              'regexp'   => @config['regexp']
            }
          end
end

#detailsObject



41
42
43
# File 'lib/what/modules/disk.rb', line 41

def details
  @info
end

#healthObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/what/modules/disk.rb', line 29

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

#initialize_moduleObject



9
10
11
# File 'lib/what/modules/disk.rb', line 9

def initialize_module
  @regexp = Regexp.new(@config['regexp'])
end