From ae200c58f18b99fb8fe773f2558ba554768b1b99 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 12 Jul 2011 21:36:33 +0200 Subject: [PATCH] Fix window_size for monitoring --- src/acct/accounting.rb | 2 +- src/acct/monitoring.rb | 2 +- src/acct/watch_helper.rb | 30 ++++++++++++++++++------------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/acct/accounting.rb b/src/acct/accounting.rb index 1fd0c6b8ac..487c3e2895 100644 --- a/src/acct/accounting.rb +++ b/src/acct/accounting.rb @@ -56,7 +56,7 @@ module OneWatch # Upate the active VMs @active_vms = new_active_vms.sort - WatchHelper::Vm.flush + WatchHelper::Vm.flush(@timestamp) end private diff --git a/src/acct/monitoring.rb b/src/acct/monitoring.rb index 14bc5959b8..5b04a12614 100644 --- a/src/acct/monitoring.rb +++ b/src/acct/monitoring.rb @@ -12,7 +12,7 @@ module OneWatch } end - sql_elem.flush + sql_elem.flush(timestamp) end private diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index dca1b56070..5873211787 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -340,17 +340,20 @@ module WatchHelper @@deltas_cache << hash end - def self.flush + def self.flush(timestamp) DB.transaction do VmDelta.multi_insert(@@deltas_cache) VmSample.multi_insert(@@samples_cache) end - Vm.each { |vm| - if vm.samples.count > @@vm_window_size - vm.samples.first.destroy - end - } + step = WatchHelper::get_config(:STEP) + ws = WatchHelper::get_config(:VM_MONITORING,:WINDOW_SIZE) + vm_s = WatchHelper::get_config(:VM_MONITORING,:STEPS) + + t = step*ws*vm_s + tl = timestamp - t + + VmSample.filter('timestamp < ?', tl).destroy @@samples_cache = [] @@deltas_cache = [] @@ -396,16 +399,19 @@ module WatchHelper @@samples_cache << hash end - def self.flush + def self.flush(timestamp) DB.transaction do HostSample.multi_insert(@@samples_cache) end - Host.all.each { |host| - if host.samples.count > @@host_window_size - host.samples.first.destroy - end - } + step = WatchHelper::get_config(:STEP) + ws = WatchHelper::get_config(:HOST_MONITORING,:WINDOW_SIZE) + vm_s = WatchHelper::get_config(:HOST_MONITORING,:STEPS) + + t = step*ws*vm_s + tl = timestamp - t + + HostSample.filter('timestamp < ?', tl).destroy @@samples_cache = [] end