Class: Recmon::FilesizeSensor

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

Overview

Periodically checks the size of a designated file

Instance Method Summary collapse

Methods inherited from Sensor

#check

Constructor Details

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

The name is arbitrary (used in creating the log entries), and the path should be absolute (eg. /var/log/messages)



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

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

Instance Method Details

#senseObject

Called by Monitor. Determines the filesize in bytes.



17
18
19
20
# File 'lib/recmon/filesize-sensor.rb', line 17

def sense()
  size = File.stat(@path).size() || "unknown"
  return("#{@name} filesize=#{size} bytes")
end