aboutsummaryrefslogtreecommitdiff
path: root/monitor.rb
diff options
context:
space:
mode:
Diffstat (limited to 'monitor.rb')
-rw-r--r--monitor.rb50
1 files changed, 46 insertions, 4 deletions
diff --git a/monitor.rb b/monitor.rb
index 249e2a3..09f9e59 100644
--- a/monitor.rb
+++ b/monitor.rb
@@ -4,6 +4,8 @@ require "time"
4require "ncurses" 4require "ncurses"
5require "inifile" 5require "inifile"
6require "open3" 6require "open3"
7require 'optparse'
8require 'ostruct'
7 9
8class IO 10class IO
9 def readline_nonblock 11 def readline_nonblock
@@ -18,6 +20,26 @@ class IO
18 end 20 end
19end 21end
20 22
23class OptParse
24 def parse(args)
25
26 options = OpenStruct.new()
27 options.inifile = nil
28
29 opt_parser = OptionParser.new() do |opts|
30
31 opts.banner = "Usage: monitor [options]"
32 opts.separator ""
33
34 opts.on( '-f', "-f ini_file", "chose a different initialization file") do |ini|
35 options.inifile = ini
36 end
37 end
38 opt_parser.parse!(args)
39 return options
40 end
41end
42
21class List_Win 43class List_Win
22 def initialize(inifile) 44 def initialize(inifile)
23 @params = inifile 45 @params = inifile
@@ -194,6 +216,7 @@ class Buff_Win
194 if(force or (Time.now - @last_update > @params['Periodic'].to_i)) 216 if(force or (Time.now - @last_update > @params['Periodic'].to_i))
195 @buffer.clear() 217 @buffer.clear()
196 spawn_proc() 218 spawn_proc()
219 clear()
197 end 220 end
198 end 221 end
199 print_buffer() 222 print_buffer()
@@ -287,8 +310,25 @@ class Buffer
287 end 310 end
288end 311end
289 312
290def read_ini() 313def find_ini(option_inifile)
291 inifile = IniFile.load('monitorrc') 314 if(not option_inifile.nil?)
315 inifile = option_inifile
316 elsif(ENV.has_key?('MONITOR_RC'))
317 inifile = ENV['MONITOR_RC']
318 elsif(Process.uid == 0)
319 inifile = "/etc/monitor.rc"
320 else
321 inifile = ENV['HOME']+"/.monitorrc"
322 end
323 return inifile
324end
325
326def read_ini(ini)
327 inifile = IniFile.load(ini)
328 if(inifile.nil?)
329 puts "Initialization file not found or not readable"
330 exit
331 end
292 return inifile 332 return inifile
293end 333end
294 334
@@ -352,6 +392,10 @@ def redraw_all(list,bufwins,curr_bufwin)
352 list.refresh() 392 list.refresh()
353 curr_bufwin.refresh() 393 curr_bufwin.refresh()
354end 394end
395
396
397options = OptParse.new().parse(ARGV)
398inifile = read_ini(find_ini(options.inifile))
355begin 399begin
356 # initialize ncurses 400 # initialize ncurses
357 Ncurses.initscr 401 Ncurses.initscr
@@ -365,8 +409,6 @@ begin
365 Ncurses.init_pair(10, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK) 409 Ncurses.init_pair(10, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK)
366 410
367 411
368 inifile = read_ini()
369
370 list = List_Win.new(inifile) 412 list = List_Win.new(inifile)
371 bufwins = make_bufwins(inifile) 413 bufwins = make_bufwins(inifile)
372 entry = 0 414 entry = 0