Class: Recmon::DiskfreeSensor

Inherits:
Sensor
  • Object
show all
Defined in:
lib/recmon/diskfree-sensor.rb

Overview

Periodically check the diskspace usage for a folder

Instance Method Summary collapse

Methods inherited from Sensor

#check

Constructor Details

#initialize(name, freq = 1200) ⇒ DiskfreeSensor

create a DiskfreeSensor to check the usage of a disk partition.

  • name is a name of the mounted partition (eg. “/var”)



10
11
12
13
# File 'lib/recmon/diskfree-sensor.rb', line 10

def initialize(name, freq=1200)
  super(name.strip(), freq)
  raise "Partition not found: #{@name}" unless File.directory?(@name)
end

Instance Method Details

#senseObject

Called by Monitor. Executes df(1) to determine the disk %usage.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/recmon/diskfree-sensor.rb', line 16

def sense()
  begin
    lines = `/bin/df #{@name}`.split("\n")
    line = lines[1]
    usage = "unknown"
    if line
      parts = line.split(/\s+/)
      avail = parts[3].to_i()/1024
    end
  end
  return("mountpoint=#{@name} available=#{avail} MB")
end