271b1a48 |
require_relative "rubysermon/version" |
def91ab1 |
require_relative "rubysermon/mod_loader"
require_relative "rubysermon/mod_template" |
c61af953 |
require_relative "rubysermon/configurator" |
958dd062 |
require_relative "rubysermon/db" |
5e777af5 |
require_relative "rubysermon/output_driver_template" |
d8a5adb0 |
require_relative "rubysermon/result_grabber" |
fb5f2bce |
|
271b1a48 |
module Rubysermon |
8cbb7fe5 |
LIB_PATH = File.expand_path(File.dirname(__FILE__))
APP_PATH = "#{LIB_PATH}/.." |
f0d38088 |
MOD_PATH = "#{LIB_PATH}/rubysermon/mod" |
8cbb7fe5 |
|
def91ab1 |
class App |
5e777af5 |
#todo: refactor |
def91ab1 |
def initialize |
c8be27d8 |
@config = { repeat: 60,
config_path: "#{LIB_PATH}/rubysermon/config.json", |
945a52d0 |
db_path: "/tmp/rubysermon_history.db", |
5e777af5 |
history_size: 90,
output: "Dummy" |
c8be27d8 |
}
|
71bcfce4 |
@running_mods = []
@enabled_mods = [] |
958dd062 |
@db = nil |
e5c1300f |
|
5e777af5 |
require "#{LIB_PATH}/rubysermon/output_drivers/#{@config[:output].downcase}"
@output_driver = (Rubysermon.const_get(@config[:output])).new
|
92546c22 |
check_args() |
71bcfce4 |
end |
fb5f2bce |
|
71bcfce4 |
def run
read_config()
enable_and_start_mods()
if (msg = cannot_start_fetch_process_sleep_cycle?)
abort(msg)
end |
fb5f2bce |
|
92546c22 |
#start_db() |
d8a5adb0 |
start_result_processor() |
def91ab1 |
end
|
d8a5adb0 |
#TODO destructor na ukoncenie threadov
|
def91ab1 |
private |
c61af953 |
|
92546c22 |
def check_args
if not ARGV.empty?
config_path = ARGV.first
if File.exists?(config_path)
@config[:config_path] = config_path
else
abort("Wrong config file path. Exiting.")
end
end
end
|
71bcfce4 |
def read_config |
c8be27d8 |
configurator = Configurator.new(@config[:config_path]) |
e9310bd3 |
config = configurator.get_settings() |
c196a26b |
@config.merge!(config) |
c61af953 |
end
|
71bcfce4 |
def enable_and_start_mods
@enabled_mods = @config[:modules].to_a |
fb5f2bce |
@enabled_mods.each do |mod| load_mod(mod) end
end
|
def91ab1 |
def load_mod(mod_name)
begin |
945a52d0 |
#prekonvertovat na symbol |
fb5f2bce |
mod = ModLoader.load(mod_name)
@running_mods.push(mod) |
def91ab1 |
rescue ModLoaderException => e |
71bcfce4 |
$stderr.puts e.message |
def91ab1 |
end
end |
fb5f2bce |
|
71bcfce4 |
def cannot_start_fetch_process_sleep_cycle?
if @config[:repeat].to_i < 1
return "Repeat cycle is too short"
elsif @running_mods.empty?
return "There are no enabled modules" |
fb5f2bce |
end
|
71bcfce4 |
false
end
|
958dd062 |
def start_db |
c8be27d8 |
@db = DB.new(@config[:db_path]) |
958dd062 |
end
|
d8a5adb0 |
def start_result_processor
@result_grabber = ResultGrabber.new(@running_mods, @config[:repeat])
@result_grabber.run() |
945a52d0 |
|
d8a5adb0 |
#TODO spravit event machine na pytanie sa, ci netreba poslat notify
#Kazdy cas interval sa dozadovat grabbera na vysledky. |
945a52d0 |
end
def notify
end
def make_output |
5e777af5 |
@results.each do |mod, mod_results|
@output_driver.log(mod, mod_results)
end |
945a52d0 |
end |
def91ab1 |
end |
271b1a48 |
end |