mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Merge branch 'feature-696' of git.opennebula.org:one into feature-696
Conflicts: src/acct/watch_helper.rb
This commit is contained in:
commit
de286e6748
@ -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
|
||||
|
@ -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
|
||||
|
@ -98,6 +98,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
|
||||
@ -245,6 +254,11 @@ module WatchHelper
|
||||
@@samples_cache = []
|
||||
@@deltas_cache = []
|
||||
|
||||
@@vm_window_size = WatchHelper::get_config(
|
||||
:VM_MONITORING,
|
||||
:WINDOW_SIZE
|
||||
)
|
||||
|
||||
def self.info(vm)
|
||||
Vm.find_or_create(:id=>vm['ID']) { |v|
|
||||
v.name = vm['NAME']
|
||||
@ -324,14 +338,15 @@ module WatchHelper
|
||||
VmSample.multi_insert(@@samples_cache)
|
||||
|
||||
Vm.each { |vm|
|
||||
if vm.samples.count > CONF[:WINDOW_SIZE]
|
||||
vm.samples.first.delete
|
||||
if vm.samples.count > @@vm_window_size -1
|
||||
vm.samples.last.delete
|
||||
end
|
||||
}
|
||||
|
||||
@@samples_cache = []
|
||||
@@deltas_cache = []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Host < Sequel::Model
|
||||
@ -342,6 +357,12 @@ module WatchHelper
|
||||
|
||||
@@samples_cache = []
|
||||
|
||||
@@host_window_size = WatchHelper::get_config(
|
||||
:HOST_MONITORING,
|
||||
:WINDOW_SIZE
|
||||
)
|
||||
|
||||
|
||||
def self.info(host)
|
||||
Host.find_or_create(:id=>host['ID']) { |h|
|
||||
h.name = host['NAME']
|
||||
@ -371,7 +392,7 @@ module WatchHelper
|
||||
HostSample.multi_insert(@@samples_cache)
|
||||
|
||||
Host.all.each { |host|
|
||||
if host.samples.count > CONF[:WINDOW_SIZE]
|
||||
if host.samples.count > @@host_window_size
|
||||
host.samples.first.delete
|
||||
end
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user