From 98f7badde0d326437563b2cb509b9cfa453ef2b5 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 8 Jul 2011 16:48:29 +0200 Subject: [PATCH] feature #696: more human friendly configuration --- src/acct/acctd.rb | 26 ++++++++++++++++---------- src/acct/etc/acctd.conf | 40 +++++++++++++++++++++++++++++++--------- src/acct/watch_helper.rb | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/src/acct/acctd.rb b/src/acct/acctd.rb index bb895f1984..3134e07976 100755 --- a/src/acct/acctd.rb +++ b/src/acct/acctd.rb @@ -34,8 +34,6 @@ require 'yaml' require 'OpenNebula' require 'watch_helper' -CONF = YAML.load_file(ACCTD_CONF) - class Watcher def initialize @monitors = Array.new @@ -91,39 +89,47 @@ vm_pool = nil # common for accounting and monitoring host_pool = nil # Initialize VM monitoring -if CONF[:VM_MONITORING_STEPS] > 0 +if vm_steps = WatchHelper::get_config(:VM_MONITORING, :STEPS) and + vm_steps > 0 + require 'monitoring' vm_monitoring = OneWatch::VmMonitoring.new vm_pool ||= OpenNebula::VirtualMachinePool.new(one_client, -2) - watcher.add(vm_monitoring, CONF[:VM_MONITORING_STEPS], vm_pool) + watcher.add(vm_monitoring, vm_steps, vm_pool) end # Initialize Host monitoring -if CONF[:HOST_MONITORING_STEPS] > 0 +if host_steps = WatchHelper::get_config(:HOST_MONITORING, :STEPS) and + host_steps > 0 + require 'monitoring' host_monitoring = OneWatch::HostMonitoring.new host_pool ||= OpenNebula::HostPool.new(one_client) - watcher.add(host_monitoring, CONF[:HOST_MONITORING_STEPS], host_pool) + watcher.add(host_monitoring, host_steps, host_pool) end # Initialize accounting -if CONF[:ACCOUNTING_STEPS] > 0 +if accounting_steps = WatchHelper::get_config(:ACCOUNTING, :STEPS) and + accounting_steps > 0 + require 'accounting' accounting = OneWatch::Accounting.new(one_client) vm_pool ||= OpenNebula::VirtualMachinePool.new(one_client, -2) - watcher.add(accounting, CONF[:ACCOUNTING_STEPS], vm_pool) + watcher.add(accounting, accounting_steps, vm_pool) end +step_time = WatchHelper::get_config(:STEP) + step = 0 loop do start_time = Time.now - expected_end_time = start_time + CONF[:STEP] + expected_end_time = start_time + step_time step += 1 watcher.update(step) end_time = Time.now - sleep_time = start_time + CONF[:STEP] - end_time + sleep_time = start_time + step_time - end_time if sleep_time >= 1 sleep sleep_time diff --git a/src/acct/etc/acctd.conf b/src/acct/etc/acctd.conf index c1c968a084..50f0f56582 100644 --- a/src/acct/etc/acctd.conf +++ b/src/acct/etc/acctd.conf @@ -18,16 +18,38 @@ :DB: sqlite:///tmp/test_one_acct.db # Duration of each daemon loop in seconds -:STEP: 2 +:STEP: 300 # 5 minutes -# Number of daemon loops until an accounting watch -:ACCOUNTING_STEPS: 1 +#------------------------------------------------------------------------------- +# VM Monitoring +#------------------------------------------------------------------------------- -# Number of daemon loops until a VM monitoring watch -:VM_MONITORING_STEPS: 1 +:VM_MONITORING: -# Number of daemon loops until a Hosts monitoring watch -:HOST_MONITORING_STEPS: 1 + # Number of daemon loops until a VM monitoring watch + :STEPS: 1 + + # Number of VM records to preserve + :WINDOW_SIZE: 100 + +#------------------------------------------------------------------------------- +# HOST Monitoring +#------------------------------------------------------------------------------- + +:HOST_MONITORING: + + # Number of daemon loops until a Hosts monitoring watch + :STEPS: 3 + + # Number of HOST records to preserve + :WINDOW_SIZE: 100 + +#------------------------------------------------------------------------------- +# Accounting +#------------------------------------------------------------------------------- + +:ACCOUNTING: + + # Number of daemon loops until an accounting watch + :STEPS: 10 -# Number of records to preserve -:WINDOW_SIZE: 10 diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index 5021dec06a..90d118e4dc 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -88,6 +88,15 @@ module WatchHelper } } + def self.get_config(*params) + conf = CONF + while param = params.shift + conf = conf[param] + break if conf.nil? + end + conf + end + def self.bootstrap DB.create_table? :vms do Integer :id, :primary_key=>true @@ -228,7 +237,15 @@ module WatchHelper one_to_many :deltas, :order=>:timestamp # Monitoring - one_to_many :samples, :before_add=>:control_regs, :order=>:timestamp, :class=>VmSample + one_to_many :samples, + :before_add=>:control_regs, + :order=>:timestamp, + :class=>VmSample + + @@vm_window_size = WatchHelper::get_config( + :VM_MONITORING, + :WINDOW_SIZE + ) def self.info(vm) Vm.find_or_create(:id=>vm['ID']) { |v| @@ -282,7 +299,7 @@ module WatchHelper private def control_regs(sample) - if self.samples.count > CONF[:WINDOW_SIZE] - 1 + if self.samples.count > @@vm_window_size - 1 self.samples.first.delete end end @@ -292,7 +309,15 @@ module WatchHelper unrestrict_primary_key # Monitoring - one_to_many :samples, :before_add=>:control_regs, :order=>:timestamp, :class=>HostSample + one_to_many :samples, + :before_add=>:control_regs, + :order=>:timestamp, + :class=>HostSample + + @@host_window_size = WatchHelper::get_config( + :HOST_MONITORING, + :WINDOW_SIZE + ) def self.info(host) Host.find_or_create(:id=>host['ID']) { |h| @@ -321,7 +346,8 @@ module WatchHelper private def control_regs(sample) - if self.samples.count > CONF[:WINDOW_SIZE] - 1 + + if self.samples.count > @@host_window_size - 1 self.samples.first.delete end end