Class: Recmon::DiskfreeSensor
- Defined in:
- lib/recmon/diskfree-sensor.rb
Overview
Periodically check the diskspace usage for a folder
Instance Method Summary collapse
-
#initialize(name, freq = 1200) ⇒ DiskfreeSensor
constructor
create a DiskfreeSensor to check the usage of a disk partition.
-
#sense ⇒ Object
Called by Monitor.
Methods inherited from Sensor
Constructor Details
#initialize(name, freq = 1200) ⇒ DiskfreeSensor
create a DiskfreeSensor to check the usage of a disk partition.
-
nameis 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
#sense ⇒ Object
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 |