Class: Recmon::DiskspaceSensor

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

Overview

Periodically check the diskspace usage for a folder

Instance Method Summary collapse

Methods inherited from Sensor

#check

Constructor Details

#initialize(name, path, freq = 1200) ⇒ DiskspaceSensor

create a DiskspaceSensor to check the diskspace usage of a folder.

  • name is a descriptive name for the folder

  • path should be absolute



11
12
13
14
15
# File 'lib/recmon/diskspace-sensor.rb', line 11

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

Instance Method Details

#senseObject

Called by Monitor. Executes du(1) to determine the disk usage in Megabytes.



18
19
20
21
22
23
24
25
# File 'lib/recmon/diskspace-sensor.rb', line 18

def sense()
  begin
    size = `/usr/bin/du -sk #{@path}`.to_i()/1024
  rescue
    size = "unknown"
  end
  return("#{@name} usage=#{size} MB")
end