Class: SysWatch::Runner
- Inherits:
-
Object
- Object
- SysWatch::Runner
- Defined in:
- lib/syswatch/runner.rb
Instance Method Summary collapse
- #examine(mountpoint) ⇒ Object
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
- #notify(mountpoint, percent_left) ⇒ Object
- #read_config ⇒ Object
Constructor Details
#initialize(options) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/syswatch/runner.rb', line 7 def initialize @options = { :foreground => false, :verbose => false, :config => SysWatch::DEFAULTS[:config] }.merge!() if read_config Process.daemon unless @options[:foreground] if @options[:test] notify "/foo", 0.1 return end begin @configuration[:mountpoints].each do |mp| examine mp end end while sleep(@configuration[:delay]) end end |
Instance Method Details
#examine(mountpoint) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/syswatch/runner.rb', line 30 def examine mountpoint stat = Sys::Filesystem.stat(mountpoint) percent_left = stat.blocks_available.to_f / stat.blocks.to_f puts percent_left if percent_left < @configuration[:treshold]/100.0 notify mountpoint, percent_left end end |
#notify(mountpoint, percent_left) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/syswatch/runner.rb', line 39 def notify mountpoint, percent_left mail = { :subject => "[SysWatch - #{@configuration[:label]}] Alert", :body => ("Mountpoint %s has only %d%% space left!" % [mountpoint, percent_left*100]) } Pony.mail(mail.merge(@configuration[:mail])) end |
#read_config ⇒ Object
47 48 49 50 51 52 |
# File 'lib/syswatch/runner.rb', line 47 def read_config @configuration = YAML.load_file(@options[:config]) rescue $stderr.puts "Unable to open config file #{@options[:config]}. Exiting." false end |