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