mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #696: more human friendly configuration
This commit is contained in:
parent
7265eca027
commit
98f7badde0
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user