From 4edcd9ffd8a7da17ab4d21e5883d7fe004a90e87 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 5 Jul 2011 16:13:20 +0200 Subject: [PATCH 01/26] feature #696: Fix CLI expected Integer error --- src/cli/one_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 5b734fb1fa..3c89e8a67d 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -294,7 +294,7 @@ EOT end def OpenNebulaHelper.name_to_id(name, poolname, user_flag=-2) - return 0, name if name.match(/^[0123456789]+$/) + return 0, name.to_i if name.match(/^[0123456789]+$/) client = OpenNebula::Client.new # TBD user_flag From d323748b321e042673a15d551b57701b4219da1b Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 5 Jul 2011 16:14:12 +0200 Subject: [PATCH 02/26] feature #696: Add support for accounting and monitoring --- src/acct/accounting.rb | 112 +++++++++ src/acct/examples/acct_client.rb | 75 ++++++ src/acct/monitoring.rb | 42 ++++ src/acct/test/1Vm1His.rb | 333 ++++++++++++++++++++++++++ src/acct/test/1VmXHis.rb | 99 ++++++++ src/acct/test/XVm1His.rb | 91 +++++++ src/acct/test/fixtures/empty_pool.xml | 1 + src/acct/test/fixtures/vm.xml | 46 ++++ src/acct/test/fixtures/vmpool.xml | 49 ++++ src/acct/test/helper/mock_client.rb | 49 ++++ src/acct/test/helper/test_helper.rb | 71 ++++++ src/acct/test/monitoring_spec.rb | 56 +++++ src/acct/watch_client.rb | 30 +++ src/acct/watch_helper.rb | 315 ++++++++++++++++++++++++ 14 files changed, 1369 insertions(+) create mode 100644 src/acct/accounting.rb create mode 100644 src/acct/examples/acct_client.rb create mode 100644 src/acct/monitoring.rb create mode 100644 src/acct/test/1Vm1His.rb create mode 100644 src/acct/test/1VmXHis.rb create mode 100644 src/acct/test/XVm1His.rb create mode 100644 src/acct/test/fixtures/empty_pool.xml create mode 100644 src/acct/test/fixtures/vm.xml create mode 100644 src/acct/test/fixtures/vmpool.xml create mode 100644 src/acct/test/helper/mock_client.rb create mode 100644 src/acct/test/helper/test_helper.rb create mode 100644 src/acct/test/monitoring_spec.rb create mode 100644 src/acct/watch_client.rb create mode 100644 src/acct/watch_helper.rb diff --git a/src/acct/accounting.rb b/src/acct/accounting.rb new file mode 100644 index 0000000000..b8f3e3e9df --- /dev/null +++ b/src/acct/accounting.rb @@ -0,0 +1,112 @@ +module OneWatch + require 'watch_helper' + + class Accounting + def initialize(client) + @client = client + @active_vms = Array.new + end + + def insert(hash) + @ptimestamp = @timestamp + @timestamp = generate_timestamp + + new_active_vms = Array.new + last_active_vm = @active_vms.empty? ? -1 : @active_vms.last + + if (vmpool_hash = hash['VM_POOL']) && !vmpool_hash.empty? + [vmpool_hash['VM']].flatten.each { |vm| + vm_id = vm['ID'].to_i + + if vm['STATE'] == 3 + new_active_vms << vm_id + end + + # ACTIVE VMs (including those that are stopped in this step) + # in the last step and NEW VMs + if @active_vms.include?(vm_id) || vm['STATE'].to_i == 3 + insert_vm(vm) + @active_vms.delete(vm_id) + else + # DONE/STOP VMs and non ACTIVE in the last step + next + end + } + end + + # DONE VMs that were ACTIVE in the last step + @active_vms.each { |id| + vm = OpenNebula::VirtualMachine.new_with_id(id, @client) + vm.info + + vm_hash = vm.to_hash + insert_vm(vm_hash) + } + + # DONE VMs that did not exist in the last step + vmpool = OpenNebula::VirtualMachinePool.new(@client) + vmpool.info(-2, last_active_vm, -1, 6) + done_hash = vmpool.to_hash + if (done_vm_hash = done_hash['VM_POOL']) && !done_vm_hash.empty? + [done_vm_hash['VM']].flatten.each { |vm| + insert_vm(vm) + } + end + + # Upate the active VMs + @active_vms = new_active_vms.sort + end + + private + + def generate_timestamp + Time.now.to_i + end + + def insert_register(vm, register, history) + if register && register.seq == history['SEQ'].to_i + register.update_from_history(history) + else + reg = WatchHelper::Register.create_from_history(history) + vm.add_register(reg) + end + end + + def update_history(vm, vm_sql) + last_register = vm_sql.registers.last + seq = last_register ? last_register.seq : 0 + + if hr = vm['HISTORY_RECORDS'] + unless hr['HISTORY'].instance_of?(Array) + if hr['HISTORY']['SEQ'] == seq + # The VM has not moved from the Host + insert_register(vm_sql, last_register, hr['HISTORY']) + return + else + # Get the full HISTORY + vm = OpenNebula::VirtualMachine.new_with_id(vm['ID'], @client) + vm.info + + vm_hash = vm.to_hash['VM'] + hr = vm_hash['HISTORY_RECORDS'] + + # Insert a new entry for each new history record + [hr['HISTORY']].flatten.each { |history| + if history['SEQ'].to_i < seq + next + else + insert_register(vm_sql, last_register, history) + end + } + end + end + end + end + + def insert_vm(vm) + vm_sql = WatchHelper::Vm.info(vm) + update_history(vm, vm_sql) + end + end +end + diff --git a/src/acct/examples/acct_client.rb b/src/acct/examples/acct_client.rb new file mode 100644 index 0000000000..565f3de816 --- /dev/null +++ b/src/acct/examples/acct_client.rb @@ -0,0 +1,75 @@ +require 'watch_helper' + +class AcctClient + def prolog_time(t1, t2, opts={}) + times(t1, t2, opts) { |reg| + calculate_time(t1, t2, reg.pstime, reg.petime) + } + end + + def running_time(t1, t2, opts={}) + # TBD Suspened VMs + + times(t1, t2, opts) { |reg| + calculate_time(t1, t2, reg.rstime, reg.retime) + } + end + + def epilog_time(t1, t2, opts={}) + times(t1, t2, opts) { |reg| + calculate_time(t1, t2, reg.estime, reg.eetime) + } + end + + private + + def times(t1, t2, opts={}, &block) + time = 0 + + vms = filter_vms(opts) + + if vms && !vms.empty? + vms.each { |vm| + vm.registers.each { |reg| + time += block.call(reg) + } + } + end + + time + end + + def calculate_time(t1, t2, stime, etime) + if etime < t1 && etime != 0 + return 0 + elsif stime < t2 && stime != 0 + if etime < t2 && etime != 0 + e = etime + else + e = t2 + end + + s = stime > t1 ? stime : t1 + return e - s + end + + return 0 + end + + def filter_vms(opts={}) + opts ||= {} + + if opts[:uid] + vms = WatchHelper::Vm.filter(:uid=>opts[:uid]) + elsif opts[:gid] + vms = WatchHelper::Vm.filter(:gid=>opts[:gid]) + elsif opts[:hid] + vms = WatchHelper::Vm.filter( + :registers=>WatchHelper::Register.filter(:hid => opts[:hid])) + elsif opts[:vmid] + vms = WatchHelper::Vm.filter(:id=>opts[:vmid]) + else + vms = WatchHelper::Vm + end + end +end diff --git a/src/acct/monitoring.rb b/src/acct/monitoring.rb new file mode 100644 index 0000000000..673335e92c --- /dev/null +++ b/src/acct/monitoring.rb @@ -0,0 +1,42 @@ +module OneWatch + require 'watch_helper' + + class Monitoring + def insert(hash) + timestamp = generate_timestamp + + if (pool_hash = hash["#{resource}_POOL"]) && !pool_hash.empty? + [pool_hash["#{resource}"]].flatten.each { |elem| + sql = sql_elem(elem) + sql.add_share(elem, timestamp) + } + end + end + + private + + def generate_timestamp + Time.now.to_i + end + end + + class VmMonitoring < Monitoring + def resource + 'VM' + end + + def sql_elem(elem) + WatchHelper::Vm.info(elem) + end + end + + class HostMonitoring < Monitoring + def resource + 'HOST' + end + + def sql_elem(elem) + WatchHelper::Host.info(elem) + end + end +end \ No newline at end of file diff --git a/src/acct/test/1Vm1His.rb b/src/acct/test/1Vm1His.rb new file mode 100644 index 0000000000..e1af738d60 --- /dev/null +++ b/src/acct/test/1Vm1His.rb @@ -0,0 +1,333 @@ +require 'helper/test_helper.rb' + +describe "1 Vm 1 History" do + before(:each) do + clean_db + + @mock_client = MockClient.new + @accounting = OneWatch::Accounting.new(@mock_client) + + @watch_client = AcctClient.new + + @db = WatchHelper::DB + check_lines(0,0) + end + + it "Prolog testing" do + ts1 = 100 + @accounting.set_mock_timestamp(ts1) + + @accounting.insert(create_vmpool_hash) + check_lines(0,0) + + ts2 = 200 + @accounting.set_mock_timestamp(ts2) + + values = { + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :pstime => 150, + :petime => 0, + :rstime => 0, + :retime => 0, + :estime => 0, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + + @accounting.insert(create_vmpool_hash) + check_lines(1,1) + + history = values[:history].first + sum = ts2 - history[:pstime] + + warn "* T1 PSTIME T2" + @watch_client.prolog_time(ts1, ts2).to_i.should eql(sum) + warn " - By User" + @watch_client.prolog_time(ts1, ts2, :uid => 2).to_i.should eql(sum) + warn " - By Host" + @watch_client.prolog_time(ts1, ts2, :hid => 7).to_i.should eql(sum) + warn " - By Vm" + @watch_client.prolog_time(ts1, ts2, :vmid => 1).to_i.should eql(sum) + + warn " - Non existent User" + @watch_client.prolog_time(ts1, ts2, :uid => 555).to_i.should eql(0) + warn " - Non existent Host" + @watch_client.prolog_time(ts1, ts2, :hid => 555).to_i.should eql(0) + warn " - Non existent Vm" + @watch_client.prolog_time(ts1, ts2, :vmid => 555).to_i.should eql(0) + + warn "* PSTIME T1 T2" + @watch_client.prolog_time(160, ts2).to_i.should eql(sum-10) + warn "* T1 PSTIME T2-10" + @watch_client.prolog_time(ts1, ts2-10).to_i.should eql(sum-10) + warn "* T1 T2 PSTIME" + @watch_client.prolog_time(110, 130).to_i.should eql(0) + + warn "* Non Epilog time" + @watch_client.epilog_time(ts1, ts2).to_i.should eql(0) + warn "* Non Running time" + @watch_client.running_time(ts1, ts2).to_i.should eql(0) + + ts3 = 300 + @accounting.set_mock_timestamp(ts2) + + values = { + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :pstime => 150, + :petime => 240, + :rstime => 0, + :retime => 0, + :estime => 0, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + + @accounting.insert(create_vmpool_hash) + check_lines(1,1) + + history = values[:history].first + sum = history[:petime] - history[:pstime] + + warn "* T1 PSTIME PETIME T3" + @watch_client.prolog_time(ts1, ts3).to_i.should eql(sum) + warn " - By User" + @watch_client.prolog_time(ts1, ts3, :uid => 2).to_i.should eql(sum) + warn " - By Host" + @watch_client.prolog_time(ts1, ts3, :hid => 7).to_i.should eql(sum) + warn " - By Vm" + @watch_client.prolog_time(ts1, ts3, :vmid => 1).to_i.should eql(sum) + + warn "* T1 PSTIME T3 PETIME" + @watch_client.prolog_time(ts1, 230).to_i.should eql(230 - history[:pstime]) + + warn "* PSTIME T1 PETIME T3" + @watch_client.prolog_time(160, ts3).to_i.should eql(history[:petime] - 160) + + warn "* PSTIME T1 T3 PETIME" + @watch_client.prolog_time(160, 230).to_i.should eql(230 - 160) + end + + it "Running testing" do + ts1 = 100 + @accounting.set_mock_timestamp(ts1) + + @accounting.insert(create_vmpool_hash) + check_lines(0,0) + + ts2 = 200 + @accounting.set_mock_timestamp(ts2) + + values = { + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :pstime => 150, + :petime => 155, + :rstime => 155, + :retime => 0, + :estime => 0, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + + @accounting.insert(create_vmpool_hash) + check_lines(1,1) + + history = values[:history].first + sum = ts2 - history[:rstime] + + warn "* T1 RSTIME T2" + @watch_client.running_time(ts1, ts2).to_i.should eql(sum) + warn " - By User" + @watch_client.running_time(ts1, ts2, :uid => 2).to_i.should eql(sum) + warn " - By Host" + @watch_client.running_time(ts1, ts2, :hid => 7).to_i.should eql(sum) + warn " - By Vm" + @watch_client.running_time(ts1, ts2, :vmid => 1).to_i.should eql(sum) + + warn " - Non existent User" + @watch_client.running_time(ts1, ts2, :uid => 555).to_i.should eql(0) + warn " - Non existent Host" + @watch_client.running_time(ts1, ts2, :hid => 555).to_i.should eql(0) + warn " - Non existent Vm" + @watch_client.running_time(ts1, ts2, :vmid => 555).to_i.should eql(0) + + warn "* RSTIME T1 T2" + @watch_client.running_time(160, ts2).to_i.should eql(ts2-160) + warn "* T1 RSTIME T2-10" + @watch_client.running_time(ts1, ts2-10).to_i.should eql(sum-10) + warn "* T1 T2 RSTIME" + @watch_client.running_time(110, 130).to_i.should eql(0) + + warn "* Non Epilog time" + @watch_client.epilog_time(ts1, ts2).to_i.should eql(0) + warn "* Non Prolog time" + @watch_client.prolog_time(ts1, ts2).to_i.should eql(5) + + ts3 = 300 + @accounting.set_mock_timestamp(ts2) + + values = { + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :pstime => 150, + :petime => 155, + :rstime => 155, + :retime => 230, + :estime => 0, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + + @accounting.insert(create_vmpool_hash) + check_lines(1,1) + + history = values[:history].first + sum = history[:retime] - history[:rstime] + + warn "* T1 PSTIME PETIME T3" + @watch_client.running_time(ts1, ts3).to_i.should eql(sum) + warn " - By User" + @watch_client.running_time(ts1, ts3, :uid => 2).to_i.should eql(sum) + warn " - By Host" + @watch_client.running_time(ts1, ts3, :hid => 7).to_i.should eql(sum) + warn " - By Vm" + @watch_client.running_time(ts1, ts3, :vmid => 1).to_i.should eql(sum) + + warn "* T1 PSTIME T3 PETIME" + @watch_client.running_time(ts1, 230).to_i.should eql(230 - history[:rstime]) + + warn "* PSTIME T1 PETIME T3" + @watch_client.running_time(160, ts3).to_i.should eql(history[:retime] - 160) + + warn "* PSTIME T1 T3 PETIME" + @watch_client.running_time(160, 230).to_i.should eql(230 - 160) + end + + it "Epilog testing" do + ts1 = 100 + @accounting.set_mock_timestamp(ts1) + + @accounting.insert(create_vmpool_hash) + check_lines(0,0) + + ts2 = 200 + @accounting.set_mock_timestamp(ts2) + + values = { + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :pstime => 150, + :petime => 155, + :rstime => 155, + :retime => 170, + :estime => 180, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + + @accounting.insert(create_vmpool_hash) + check_lines(1,1) + + history = values[:history].first + sum = ts2 - history[:estime] + + warn "* T1 ESTIME T2" + @watch_client.epilog_time(ts1, ts2).to_i.should eql(sum) + warn " - By User" + @watch_client.epilog_time(ts1, ts2, :uid => 2).to_i.should eql(sum) + warn " - By Host" + @watch_client.epilog_time(ts1, ts2, :hid => 7).to_i.should eql(sum) + warn " - By Vm" + @watch_client.epilog_time(ts1, ts2, :vmid => 1).to_i.should eql(sum) + + warn " - Non existent User" + @watch_client.epilog_time(ts1, ts2, :uid => 555).to_i.should eql(0) + warn " - Non existent Host" + @watch_client.epilog_time(ts1, ts2, :hid => 555).to_i.should eql(0) + warn " - Non existent Vm" + @watch_client.epilog_time(ts1, ts2, :vmid => 555).to_i.should eql(0) + + warn "* ESTIME T1 T2" + @watch_client.epilog_time(190, ts2).to_i.should eql(ts2-190) + warn "* T1 ESTIME T2-10" + @watch_client.epilog_time(ts1, ts2-10).to_i.should eql(sum-10) + warn "* T1 T2 ESTIME" + @watch_client.epilog_time(110, 130).to_i.should eql(0) + + warn "* Non Running time" + @watch_client.running_time(ts1, ts2).to_i.should eql(15) + warn "* Non Prolog time" + @watch_client.prolog_time(ts1, ts2).to_i.should eql(5) + + ts3 = 300 + @accounting.set_mock_timestamp(ts2) + + values = { + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :pstime => 150, + :petime => 155, + :rstime => 155, + :retime => 170, + :estime => 180, + :eetime => 230, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + + @accounting.insert(create_vmpool_hash) + check_lines(1,1) + + history = values[:history].first + sum = history[:eetime] - history[:estime] + + warn "* T1 PSTIME PETIME T3" + @watch_client.epilog_time(ts1, ts3).to_i.should eql(sum) + warn " - By User" + @watch_client.epilog_time(ts1, ts3, :uid => 2).to_i.should eql(sum) + warn " - By Host" + @watch_client.epilog_time(ts1, ts3, :hid => 7).to_i.should eql(sum) + warn " - By Vm" + @watch_client.epilog_time(ts1, ts3, :vmid => 1).to_i.should eql(sum) + + warn "* T1 PSTIME T3 PETIME" + @watch_client.epilog_time(ts1, 230).to_i.should eql(230 - history[:estime]) + + warn "* PSTIME T1 PETIME T3" + @watch_client.epilog_time(190, ts3).to_i.should eql(history[:eetime] - 190) + + warn "* PSTIME T1 T3 PETIME" + @watch_client.epilog_time(190, 220).to_i.should eql(220 - 190) + end +end \ No newline at end of file diff --git a/src/acct/test/1VmXHis.rb b/src/acct/test/1VmXHis.rb new file mode 100644 index 0000000000..13b1549dcc --- /dev/null +++ b/src/acct/test/1VmXHis.rb @@ -0,0 +1,99 @@ +require 'helper/test_helper.rb' + +describe "1 Vm X History" do + before(:each) do + clean_db + + @mock_client = MockClient.new + @accounting = OneWatch::Accounting.new(@mock_client) + + @watch_client = AcctClient.new + + @db = WatchHelper::DB + check_lines(0,0) + end + + it "Running testing" do + ts1 = 100 + @accounting.set_mock_timestamp(ts1) + + @accounting.insert(create_vmpool_hash) + check_lines(0,0) + + ts2 = 200 + @accounting.set_mock_timestamp(ts2) + + values = { + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :seq => 0, + :pstime => 150, + :petime => 155, + :rstime => 155, + :retime => 0, + :estime => 0, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + + @accounting.insert(create_vmpool_hash) + check_lines(1,1) + + history = values[:history].first + sum = ts2 - history[:rstime] + + warn "* T1 RSTIME T2" + @watch_client.running_time(ts1, ts2).to_i.should eql(sum) + + ts3 = 300 + @accounting.set_mock_timestamp(ts2) + + values = { + :uid => 2, + :gid => 4, + :history => [ + { + :hid => 7, + :seq => 0, + :pstime => 150, + :petime => 155, + :rstime => 155, + :retime => 230, + :estime => 230, + :eetime => 260, + :reason => 2 + }, + { + :hid => 8, + :seq => 1, + :pstime => 270, + :petime => 275, + :rstime => 275, + :retime => 0, + :estime => 0, + :eetime => 0, + :reason => 0 + } + ] + } + + @mock_client.add_vm(1, values) + + @accounting.insert(create_vmpool_hash) + check_lines(1,2) + + h1 = values[:history].first + sum1 = h1[:retime] - h1[:rstime] + + h2 = values[:history].last + sum2 = ts3 - h2[:rstime] + + warn "* T1 RSTIME1 RETIME1 RSTIME1 T2" + @watch_client.running_time(ts1, ts3).to_i.should eql(sum1 + sum2) + end +end \ No newline at end of file diff --git a/src/acct/test/XVm1His.rb b/src/acct/test/XVm1His.rb new file mode 100644 index 0000000000..faf17ab0b4 --- /dev/null +++ b/src/acct/test/XVm1His.rb @@ -0,0 +1,91 @@ +require 'helper/test_helper.rb' + +describe "X Vm 1 History" do + before(:each) do + clean_db + + @mock_client = MockClient.new + @accounting = OneWatch::Accounting.new(@mock_client) + + @watch_client = AcctClient.new + + @db = WatchHelper::DB + check_lines(0,0) + end + + it "Running testing" do + ts1 = 100 + @accounting.set_mock_timestamp(ts1) + + @accounting.insert(create_vmpool_hash) + check_lines(0,0) + + ts2 = 200 + @accounting.set_mock_timestamp(ts2) + + values = { + :uid => 2, + :gid => 4, + :history => [ + :hid => 6, + :seq => 0, + :pstime => 150, + :petime => 155, + :rstime => 155, + :retime => 0, + :estime => 0, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + + @accounting.insert(create_vmpool_hash) + check_lines(1,1) + + history = values[:history].first + sum = ts2 - history[:rstime] + + warn "* T1 RSTIME T2" + @watch_client.running_time(ts1, ts2).to_i.should eql(sum) + + ts3 = 300 + @accounting.set_mock_timestamp(ts3) + + values2 = { + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :seq => 0, + :pstime => 220, + :petime => 260, + :rstime => 260, + :retime => 0, + :estime => 0, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(2, values2) + + @accounting.insert(create_vmpool_hash) + check_lines(2,2) + + history1 = values[:history].first + sum1 = ts3 - history1[:rstime] + + history2 = values2[:history].first + sum2 = ts3 - history2[:rstime] + + warn "* T1 RSTIME T2" + @watch_client.running_time(ts1, ts3).to_i.should eql(sum1 + sum2) + @watch_client.running_time(ts1, ts3, :vmid=>1).to_i.should eql(sum1) + @watch_client.running_time(ts1, ts3, :vmid=>2).to_i.should eql(sum2) + @watch_client.running_time(ts1, ts3, :uid=>2).to_i.should eql(sum1 + sum2) + @watch_client.running_time(ts1, ts3, :hid=>6).to_i.should eql(sum1) + @watch_client.running_time(ts1, ts3, :hid=>7).to_i.should eql(sum2) + end +end \ No newline at end of file diff --git a/src/acct/test/fixtures/empty_pool.xml b/src/acct/test/fixtures/empty_pool.xml new file mode 100644 index 0000000000..2a8bcd37c2 --- /dev/null +++ b/src/acct/test/fixtures/empty_pool.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/acct/test/fixtures/vm.xml b/src/acct/test/fixtures/vm.xml new file mode 100644 index 0000000000..1560a16029 --- /dev/null +++ b/src/acct/test/fixtures/vm.xml @@ -0,0 +1,46 @@ + + <%= id %> + <%= vm[:uid] ? vm[:uid] : 0 %> + <%= vm[:gid] ? vm[:gid] : 0 %> + <%= vm[:name] ? vm[:uid] : 'pepe' %> + <%= vm[:last_poll] ? vm[:last_poll] : '1309275256' %> + <%= vm[:state] ? vm[:state] : 3 %> + 3 + 1309275252 + 0 + dummy + <%= vm[:memory] ? vm[:memory] : 128 %> + <%= vm[:cpu] ? vm[:cpu] : 1 %> + <%= vm[:net_tx] ? vm[:net_tx] : 0 %> + <%= vm[:net_rx] ? vm[:net_rx] : 0 %> + + <% if history = vm[:history] %> + + <% history.each do |h| %> + + <%= h[:seq] ? h[:seq] : 0 %> + <%= h[:hostname] ? h[:hostname] : "kvxen" %> + /Users/dmolina/trabajo/acctmoni/install/var/ + <%= h[:hid] ? h[:hid] : 0 %> + 1309275256 + 0 + vmm_dummy + tm_dummy + <%= h[:pstime] ? h[:pstime] : 0 %> + <%= h[:petime] ? h[:petime] : 0 %> + <%= h[:rstime] ? h[:rstime] : 0 %> + <%= h[:retime] ? h[:retime] : 0 %> + <%= h[:estime] ? h[:estime] : 0 %> + <%= h[:eetime] ? h[:eetime] : 0 %> + <%= h[:reason] ? h[:reason] : 0 %> + + <% end %> + + <% end %> + \ No newline at end of file diff --git a/src/acct/test/fixtures/vmpool.xml b/src/acct/test/fixtures/vmpool.xml new file mode 100644 index 0000000000..1ff7f5626e --- /dev/null +++ b/src/acct/test/fixtures/vmpool.xml @@ -0,0 +1,49 @@ + + <% vms.each do |id,vm| %> + + <%= id %> + <%= vm[:uid] ? vm[:uid] : 0 %> + <%= vm[:gid] ? vm[:gid] : 0 %> + <%= vm[:name] ? vm[:uid] : 'pepe' %> + <%= vm[:last_poll] ? vm[:last_poll] : '1309275256' %> + <%= vm[:state] ? vm[:state] : 3 %> + 3 + 1309275252 + 0 + dummy + <%= vm[:memory] ? vm[:memory] : 128 %> + <%= vm[:cpu] ? vm[:cpu] : 1 %> + <%= vm[:net_tx] ? vm[:net_tx] : 0 %> + <%= vm[:net_rx] ? vm[:net_rx] : 0 %> + + <% if history = vm[:history] %> + + <% h = history.last %> + + <%= h[:seq] ? h[:seq] : 0 %> + <%= h[:hostname] ? h[:hostname] : "kvxen" %> + /Users/dmolina/trabajo/acctmoni/install/var/ + <%= h[:hid] ? h[:hid] : 0 %> + 1309275256 + 0 + vmm_dummy + tm_dummy + <%= h[:pstime] ? h[:pstime] : 0 %> + <%= h[:petime] ? h[:petime] : 0 %> + <%= h[:rstime] ? h[:rstime] : 0 %> + <%= h[:retime] ? h[:retime] : 0 %> + <%= h[:estime] ? h[:estime] : 0 %> + <%= h[:eetime] ? h[:eetime] : 0 %> + <%= h[:reason] ? h[:reason] : 0 %> + + + <% end %> + + <% end %> + diff --git a/src/acct/test/helper/mock_client.rb b/src/acct/test/helper/mock_client.rb new file mode 100644 index 0000000000..53a560313f --- /dev/null +++ b/src/acct/test/helper/mock_client.rb @@ -0,0 +1,49 @@ +require 'erb' + +FPATH = "./fixtures/" + +class MockClient + def initialize + @vmpool = File.read("./fixtures/empty_pool.xml") + @done_vmpool = File.read("./fixtures/empty_pool.xml") + + @vms = Hash.new + @done_vms = Hash.new + end + + + def call(action, *args) + xmlrpc_action = "one."+action + + case xmlrpc_action + when "one.vm.info" + id = args[0] + vm = @vms[id] + return ERB.new(File.read(FPATH+'vm.xml')).result(binding) + when "one.vmpool.info" + case args[3] + when -1 + return File.read("./fixtures/empty_pool.xml") if @vms.empty? + vms = @vms + return ERB.new(File.read(FPATH+'vmpool.xml')).result(binding) + when 6 then + return File.read("./fixtures/empty_pool.xml") if @done_vms.empty? + vms = @done_vms + return ERB.new(File.read(FPATH+'vmpool.xml')).result(binding) + end + end + end + + def add_vm(id, values) + if values[:state] == 6 + @done_vms[id] = values + elsif + @vms[id] = values + end + end + + def delete_vm(id) + @vms.delete(id) + @vms_done.delete(id) + end +end \ No newline at end of file diff --git a/src/acct/test/helper/test_helper.rb b/src/acct/test/helper/test_helper.rb new file mode 100644 index 0000000000..bfef9dee6f --- /dev/null +++ b/src/acct/test/helper/test_helper.rb @@ -0,0 +1,71 @@ +require 'rubygems' +require 'sequel' + +ONE_LOCATION = ENV['ONE_LOCATION'] +if !ONE_LOCATION + RUBY_LIB_LOCATION="/usr/lib/one/ruby" +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" +end + +$: << RUBY_LIB_LOCATION + +require 'OpenNebula' + +$: << './helper' +$: << '.' +$: << '..' + + +require 'examples/acct_client' +require 'watch_client' +require 'mock_client' + +require 'accounting' +require 'monitoring' + +module OneWatch + class Accounting + def set_mock_timestamp(t) + @mock_timestamp = t + end + + def generate_timestamp + @mock_timestamp + end + end + + class Monitoring + def set_mock_timestamp(t) + @mock_timestamp = t + end + + def generate_timestamp + @mock_timestamp + end + end +end + +def create_vmpool_hash + @vm_pool = OpenNebula::VirtualMachinePool.new(@mock_client, -2) + @vm_pool.info + hash = @vm_pool.to_hash +end + +def clean_db + begin + WatchHelper::Register.destroy + WatchHelper::Metric.destroy + WatchHelper::VmShare.destroy + WatchHelper::HostShare.destroy + WatchHelper::Vm.destroy + WatchHelper::Host.destroy + rescue Exception => e + warn e.message + end +end + +def check_lines(*args) + @db[:vms].count.should eql(args[0]) + @db[:registers].count.should eql(args[1]) +end diff --git a/src/acct/test/monitoring_spec.rb b/src/acct/test/monitoring_spec.rb new file mode 100644 index 0000000000..d5d9eea094 --- /dev/null +++ b/src/acct/test/monitoring_spec.rb @@ -0,0 +1,56 @@ +require 'helper/test_helper.rb' + +describe "1 Vm 1 10 steps" do + before(:each) do + clean_db + + @mock_client = MockClient.new + @monitoring = OneWatch::VmMonitoring.new + + @watch_client = OneWatchClient::WatchClient.new + + @db = WatchHelper::DB + @db[:vms].count.should eql(0) + end + + it "CPU testing" do + ts1 = 100 + @monitoring.set_mock_timestamp(ts1) + + @monitoring.insert(create_vmpool_hash) + @db[:vms].count.should eql(0) + + 10.times { |i| + ts2 = 200+100*i + @monitoring.set_mock_timestamp(ts2) + + values = { + :cpu => 80+i, + :memory => 122+i, + :net_tx => 200+i, + :net_rx => 134+i, + :last_poll => 1309275256+i, + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :pstime => 150, + :petime => 0, + :rstime => 0, + :retime => 0, + :estime => 0, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + + @monitoring.insert(create_vmpool_hash) + @db[:vms].count.should eql(1) + @db[:vm_shares].count.should eql(1+i > 5 ? 5 : 1+i) + + pp @watch_client.vm_monitoring(1) + } + end +end \ No newline at end of file diff --git a/src/acct/watch_client.rb b/src/acct/watch_client.rb new file mode 100644 index 0000000000..427a7e43bc --- /dev/null +++ b/src/acct/watch_client.rb @@ -0,0 +1,30 @@ +module OneWatchClient + require 'watch_helper' + require 'json' + + class WatchClient + def vm_monitoring(id, opts=[]) + hash = Hash.new + hash[:resource] = "VM" + hash[:id] = id + + mon = Hash.new + opts.each { |opt| + next unless WatchHelper::VM_SHARE.has_key?(opt.to_sym) + mon[opt] = Array.new + } + + # TBD Check if VM exists + WatchHelper::Vm[id].vm_shares_dataset.map { |vm| + opts.each { |opt| + next unless WatchHelper::VM_SHARE.has_key?(opt.to_sym) + mon[opt] << [vm.last_poll, vm.send(opt.to_sym)] + } + } + + hash[:monitoring] = mon + + puts JSON.pretty_generate hash + end + end +end \ No newline at end of file diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb new file mode 100644 index 0000000000..7a98c9992b --- /dev/null +++ b/src/acct/watch_helper.rb @@ -0,0 +1,315 @@ +module WatchHelper + DB = Sequel.connect('sqlite:///tmp/test_one_acct.db') + + class Register < Sequel::Model + plugin :schema + + set_schema do + foreign_key :vm_id, :vms + Integer :hid + String :hostname + Integer :seq + Integer :pstime + Integer :petime + Integer :rstime + Integer :retime + Integer :estime + Integer :eetime + Integer :reason + + primary_key [:vm_id, :seq] + end + + create_table unless table_exists? + + unrestrict_primary_key + + many_to_one :vm + + def update_from_history(history) + self.seq = history['SEQ'] + self.hostname = history['HOSTNAME'] + self.hid = history['HID'] + self.pstime = history['PSTIME'] + self.petime = history['PETIME'] + self.rstime = history['RSTIME'] + self.retime = history['RETIME'] + self.estime = history['ESTIME'] + self.eetime = history['EETIME'] + self.reason = history['REASON'] + + self.save + end + + def self.create_from_history(history) + a = Register.create( + :seq => history['SEQ'], + :hostname => history['HOSTNAME'], + :hid => history['HID'], + :pstime => history['PSTIME'], + :petime => history['PETIME'], + :rstime => history['RSTIME'], + :retime => history['RETIME'], + :estime => history['ESTIME'], + :eetime => history['EETIME'], + :reason => history['REASON'] + ) + end + end + + class Metric < Sequel::Model + plugin :schema + + set_schema do + foreign_key :vm_id, :vms + Integer :timestamp + Integer :ptimestamp + Integer :net_rx + Integer :net_tx + + primary_key [:vm_id, :timestamp] + end + + create_table unless table_exists? + + unrestrict_primary_key + + many_to_one :vm + end + + class Vm < Sequel::Model + plugin :schema + + set_schema do + Integer :id, :primary_key=>true + String :name + Integer :uid + Integer :gid + Integer :mem + Integer :cpu + Integer :vcpu + Integer :stime + Integer :etime + end + + create_table unless table_exists? + + unrestrict_primary_key + + # Accounting + one_to_many :registers, :order=>:seq + one_to_many :metrics + + # Monitoring + one_to_many :vm_shares, :before_add=>:control_regs, :order=>:timestamp + + def self.info(vm) + Vm.find_or_create(:id=>vm['ID']) { |v| + v.uid = vm['UID'].to_i + v.name = vm['NAME'] + v.gid = vm['GID'].to_i + v.mem = vm['MEMORY'].to_i + v.cpu = vm['CPU'].to_i + v.vcpu = vm['VCPU'].to_i + v.stime = vm['STIME'].to_i + v.etime = vm['ETIME'].to_i + } + end + + def add_share(vm, timestamp) + vs = VmShare.create_from_vm(vm, timestamp) + self.add_vm_share(vs) + end + + private + + def control_regs(share) + if self.vm_shares.count > 4 + self.vm_shares.first.delete + end + end + end + + class Host < Sequel::Model + plugin :schema + + set_schema do + Integer :id, :primary_key=>true + String :name + Integer :im_mad + Integer :vm_mad + Integer :tm_mad + end + + create_table unless table_exists? + + unrestrict_primary_key + + # Monitoring + one_to_many :host_shares, :before_add=>:control_regs, :order=>:timestamp + + def add_share(host, timestamp) + hs = HostShare.create_from_host(host, timestamp) + self.add_host_share(hs) + end + + private + + def control_regs(share) + if self.host_shares.count > 4 + self.host_shares.first.delete + end + end + end + + HOST_SHARE = { + :disk_usage => { + :type => Integer, + :path => 'DISK_USAGE' + }, + :mem_usage => { + :type => Integer, + :path => 'MEM_USAGE' + }, + :cpu_usage => { + :type => Integer, + :path => 'CPU_USAGE' + }, + :max_disk => { + :type => Integer, + :path => 'MAX_DISK' + }, + :max_mem => { + :type => Integer, + :path => 'MAX_MEM' + }, + :mem_cpu => { + :type => Integer, + :path => 'MAX_CPU' + }, + :free_disk => { + :type => Integer, + :path => 'FREE_DISK' + }, + :free_mem => { + :type => Integer, + :path => 'FREE_MEM' + }, + :free_cpu => { + :type => Integer, + :path => 'FREE_CPU' + }, + :used_disk => { + :type => Integer, + :path => 'USED_DISK' + }, + :used_mem => { + :type => Integer, + :path => 'USED_MEM' + }, + :used_cpu => { + :type => Integer, + :path => 'USED_CPU' + }, + :rvms => { + :type => Integer, + :path => 'RUNNING_VMS' + } + } + + class HostShare < Sequel::Model + plugin :schema + + set_schema do + foreign_key :host_id, :hosts + Integer :last_poll + Integer :timestamp + + HOST_SHARE.each { |key,value| + column key, value[:type] + } + + primary_key [:host_id, :timestamp] + end + + create_table unless table_exists? + + unrestrict_primary_key + + many_to_one :host + + def self.create_from_host(host, timestamp) + hash = { + :timestamp => timestamp, + :last_poll => host['LAST_MON_TIME'], + :state => host['STATE'], + } + + host_share = host['HOST_SHARE'] + HOST_SHARE.each { |key,value| + hash[key] = host_share[value[:path]] + } + + HostShare.create(hash) + end + end + + VM_SHARE = { + :cpu => { + :type => Integer, + :path => 'CPU' + }, + :memory => { + :type => Integer, + :path => 'MEMORY' + }, + :net_tx => { + :type => Integer, + :path => 'NET_TX' + }, + :net_rx => { + :type => Integer, + :path => 'NET_RX' + } + } + + class VmShare < Sequel::Model + plugin :schema + + set_schema do + foreign_key :vm_id, :vms + Integer :state + Integer :lcm_state + Integer :last_poll + Integer :timestamp + + VM_SHARE.each { |key,value| + column key, value[:type] + } + + primary_key [:vm_id, :timestamp] + end + + create_table unless table_exists? + + unrestrict_primary_key + + many_to_one :vm + + def self.create_from_vm(vm, timestamp) + hash = { + :timestamp => timestamp, + :last_poll => vm['LAST_POLL'], + :state => vm['STATE'], + :lcm_state => vm['LCM_STATE'], + } + + VM_SHARE.each { |key,value| + hash[key] = vm[value[:path]] + } + + VmShare.create(hash) + end + end +end + \ No newline at end of file From d1de25dc2dd35c9c4a9e8d2459ea61b43484f4d8 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 5 Jul 2011 19:15:26 +0200 Subject: [PATCH 03/26] feature #696: Add monitoring resource client --- src/acct/accounting.rb | 34 +- src/acct/examples/acct_client.rb | 18 +- src/acct/monitoring.rb | 14 +- src/acct/test/1Vm1His.rb | 100 +++--- src/acct/test/1VmXHis.rb | 24 +- src/acct/test/XVm1His.rb | 28 +- src/acct/test/helper/mock_client.rb | 8 +- src/acct/test/helper/test_helper.rb | 20 +- src/acct/test/monitoring_spec.rb | 16 +- src/acct/watch_client.rb | 47 ++- src/acct/watch_helper.rb | 466 ++++++++++++++-------------- 11 files changed, 401 insertions(+), 374 deletions(-) diff --git a/src/acct/accounting.rb b/src/acct/accounting.rb index b8f3e3e9df..e6d17098d1 100644 --- a/src/acct/accounting.rb +++ b/src/acct/accounting.rb @@ -1,7 +1,7 @@ module OneWatch require 'watch_helper' - - class Accounting + + class Accounting def initialize(client) @client = client @active_vms = Array.new @@ -10,18 +10,18 @@ module OneWatch def insert(hash) @ptimestamp = @timestamp @timestamp = generate_timestamp - + new_active_vms = Array.new last_active_vm = @active_vms.empty? ? -1 : @active_vms.last - + if (vmpool_hash = hash['VM_POOL']) && !vmpool_hash.empty? [vmpool_hash['VM']].flatten.each { |vm| vm_id = vm['ID'].to_i - + if vm['STATE'] == 3 new_active_vms << vm_id end - + # ACTIVE VMs (including those that are stopped in this step) # in the last step and NEW VMs if @active_vms.include?(vm_id) || vm['STATE'].to_i == 3 @@ -33,16 +33,16 @@ module OneWatch end } end - + # DONE VMs that were ACTIVE in the last step @active_vms.each { |id| vm = OpenNebula::VirtualMachine.new_with_id(id, @client) vm.info - + vm_hash = vm.to_hash insert_vm(vm_hash) } - + # DONE VMs that did not exist in the last step vmpool = OpenNebula::VirtualMachinePool.new(@client) vmpool.info(-2, last_active_vm, -1, 6) @@ -52,17 +52,17 @@ module OneWatch insert_vm(vm) } end - + # Upate the active VMs @active_vms = new_active_vms.sort end - + private - + def generate_timestamp Time.now.to_i end - + def insert_register(vm, register, history) if register && register.seq == history['SEQ'].to_i register.update_from_history(history) @@ -71,7 +71,7 @@ module OneWatch vm.add_register(reg) end end - + def update_history(vm, vm_sql) last_register = vm_sql.registers.last seq = last_register ? last_register.seq : 0 @@ -86,7 +86,7 @@ module OneWatch # Get the full HISTORY vm = OpenNebula::VirtualMachine.new_with_id(vm['ID'], @client) vm.info - + vm_hash = vm.to_hash['VM'] hr = vm_hash['HISTORY_RECORDS'] @@ -102,11 +102,11 @@ module OneWatch end end end - + def insert_vm(vm) vm_sql = WatchHelper::Vm.info(vm) update_history(vm, vm_sql) end - end + end end diff --git a/src/acct/examples/acct_client.rb b/src/acct/examples/acct_client.rb index 565f3de816..73ebbee8b5 100644 --- a/src/acct/examples/acct_client.rb +++ b/src/acct/examples/acct_client.rb @@ -9,20 +9,20 @@ class AcctClient def running_time(t1, t2, opts={}) # TBD Suspened VMs - + times(t1, t2, opts) { |reg| calculate_time(t1, t2, reg.rstime, reg.retime) } end - + def epilog_time(t1, t2, opts={}) times(t1, t2, opts) { |reg| calculate_time(t1, t2, reg.estime, reg.eetime) } end - + private - + def times(t1, t2, opts={}, &block) time = 0 @@ -35,10 +35,10 @@ class AcctClient } } end - + time end - + def calculate_time(t1, t2, stime, etime) if etime < t1 && etime != 0 return 0 @@ -52,13 +52,13 @@ class AcctClient s = stime > t1 ? stime : t1 return e - s end - + return 0 end - + def filter_vms(opts={}) opts ||= {} - + if opts[:uid] vms = WatchHelper::Vm.filter(:uid=>opts[:uid]) elsif opts[:gid] diff --git a/src/acct/monitoring.rb b/src/acct/monitoring.rb index 673335e92c..c9637318ad 100644 --- a/src/acct/monitoring.rb +++ b/src/acct/monitoring.rb @@ -1,20 +1,20 @@ module OneWatch require 'watch_helper' - + class Monitoring def insert(hash) timestamp = generate_timestamp - + if (pool_hash = hash["#{resource}_POOL"]) && !pool_hash.empty? [pool_hash["#{resource}"]].flatten.each { |elem| sql = sql_elem(elem) - sql.add_share(elem, timestamp) + sql.add_sample_from_resource(elem, timestamp) } end end - + private - + def generate_timestamp Time.now.to_i end @@ -24,7 +24,7 @@ module OneWatch def resource 'VM' end - + def sql_elem(elem) WatchHelper::Vm.info(elem) end @@ -34,7 +34,7 @@ module OneWatch def resource 'HOST' end - + def sql_elem(elem) WatchHelper::Host.info(elem) end diff --git a/src/acct/test/1Vm1His.rb b/src/acct/test/1Vm1His.rb index e1af738d60..0eb0284875 100644 --- a/src/acct/test/1Vm1His.rb +++ b/src/acct/test/1Vm1His.rb @@ -6,20 +6,20 @@ describe "1 Vm 1 History" do @mock_client = MockClient.new @accounting = OneWatch::Accounting.new(@mock_client) - + @watch_client = AcctClient.new - + @db = WatchHelper::DB check_lines(0,0) end - + it "Prolog testing" do ts1 = 100 @accounting.set_mock_timestamp(ts1) - + @accounting.insert(create_vmpool_hash) check_lines(0,0) - + ts2 = 200 @accounting.set_mock_timestamp(ts2) @@ -37,15 +37,15 @@ describe "1 Vm 1 History" do :reason => 0 ] } - + @mock_client.add_vm(1, values) @accounting.insert(create_vmpool_hash) check_lines(1,1) - + history = values[:history].first sum = ts2 - history[:pstime] - + warn "* T1 PSTIME T2" @watch_client.prolog_time(ts1, ts2).to_i.should eql(sum) warn " - By User" @@ -54,26 +54,26 @@ describe "1 Vm 1 History" do @watch_client.prolog_time(ts1, ts2, :hid => 7).to_i.should eql(sum) warn " - By Vm" @watch_client.prolog_time(ts1, ts2, :vmid => 1).to_i.should eql(sum) - + warn " - Non existent User" @watch_client.prolog_time(ts1, ts2, :uid => 555).to_i.should eql(0) warn " - Non existent Host" @watch_client.prolog_time(ts1, ts2, :hid => 555).to_i.should eql(0) warn " - Non existent Vm" @watch_client.prolog_time(ts1, ts2, :vmid => 555).to_i.should eql(0) - + warn "* PSTIME T1 T2" @watch_client.prolog_time(160, ts2).to_i.should eql(sum-10) warn "* T1 PSTIME T2-10" @watch_client.prolog_time(ts1, ts2-10).to_i.should eql(sum-10) warn "* T1 T2 PSTIME" @watch_client.prolog_time(110, 130).to_i.should eql(0) - + warn "* Non Epilog time" @watch_client.epilog_time(ts1, ts2).to_i.should eql(0) warn "* Non Running time" @watch_client.running_time(ts1, ts2).to_i.should eql(0) - + ts3 = 300 @accounting.set_mock_timestamp(ts2) @@ -91,15 +91,15 @@ describe "1 Vm 1 History" do :reason => 0 ] } - + @mock_client.add_vm(1, values) @accounting.insert(create_vmpool_hash) check_lines(1,1) - + history = values[:history].first sum = history[:petime] - history[:pstime] - + warn "* T1 PSTIME PETIME T3" @watch_client.prolog_time(ts1, ts3).to_i.should eql(sum) warn " - By User" @@ -108,24 +108,24 @@ describe "1 Vm 1 History" do @watch_client.prolog_time(ts1, ts3, :hid => 7).to_i.should eql(sum) warn " - By Vm" @watch_client.prolog_time(ts1, ts3, :vmid => 1).to_i.should eql(sum) - + warn "* T1 PSTIME T3 PETIME" @watch_client.prolog_time(ts1, 230).to_i.should eql(230 - history[:pstime]) - + warn "* PSTIME T1 PETIME T3" @watch_client.prolog_time(160, ts3).to_i.should eql(history[:petime] - 160) - + warn "* PSTIME T1 T3 PETIME" @watch_client.prolog_time(160, 230).to_i.should eql(230 - 160) end - + it "Running testing" do ts1 = 100 @accounting.set_mock_timestamp(ts1) - + @accounting.insert(create_vmpool_hash) check_lines(0,0) - + ts2 = 200 @accounting.set_mock_timestamp(ts2) @@ -143,15 +143,15 @@ describe "1 Vm 1 History" do :reason => 0 ] } - + @mock_client.add_vm(1, values) @accounting.insert(create_vmpool_hash) check_lines(1,1) - + history = values[:history].first sum = ts2 - history[:rstime] - + warn "* T1 RSTIME T2" @watch_client.running_time(ts1, ts2).to_i.should eql(sum) warn " - By User" @@ -160,26 +160,26 @@ describe "1 Vm 1 History" do @watch_client.running_time(ts1, ts2, :hid => 7).to_i.should eql(sum) warn " - By Vm" @watch_client.running_time(ts1, ts2, :vmid => 1).to_i.should eql(sum) - + warn " - Non existent User" @watch_client.running_time(ts1, ts2, :uid => 555).to_i.should eql(0) warn " - Non existent Host" @watch_client.running_time(ts1, ts2, :hid => 555).to_i.should eql(0) warn " - Non existent Vm" @watch_client.running_time(ts1, ts2, :vmid => 555).to_i.should eql(0) - + warn "* RSTIME T1 T2" @watch_client.running_time(160, ts2).to_i.should eql(ts2-160) warn "* T1 RSTIME T2-10" @watch_client.running_time(ts1, ts2-10).to_i.should eql(sum-10) warn "* T1 T2 RSTIME" @watch_client.running_time(110, 130).to_i.should eql(0) - + warn "* Non Epilog time" @watch_client.epilog_time(ts1, ts2).to_i.should eql(0) warn "* Non Prolog time" @watch_client.prolog_time(ts1, ts2).to_i.should eql(5) - + ts3 = 300 @accounting.set_mock_timestamp(ts2) @@ -197,15 +197,15 @@ describe "1 Vm 1 History" do :reason => 0 ] } - + @mock_client.add_vm(1, values) @accounting.insert(create_vmpool_hash) check_lines(1,1) - + history = values[:history].first sum = history[:retime] - history[:rstime] - + warn "* T1 PSTIME PETIME T3" @watch_client.running_time(ts1, ts3).to_i.should eql(sum) warn " - By User" @@ -214,24 +214,24 @@ describe "1 Vm 1 History" do @watch_client.running_time(ts1, ts3, :hid => 7).to_i.should eql(sum) warn " - By Vm" @watch_client.running_time(ts1, ts3, :vmid => 1).to_i.should eql(sum) - + warn "* T1 PSTIME T3 PETIME" @watch_client.running_time(ts1, 230).to_i.should eql(230 - history[:rstime]) - + warn "* PSTIME T1 PETIME T3" @watch_client.running_time(160, ts3).to_i.should eql(history[:retime] - 160) - + warn "* PSTIME T1 T3 PETIME" @watch_client.running_time(160, 230).to_i.should eql(230 - 160) end - + it "Epilog testing" do ts1 = 100 @accounting.set_mock_timestamp(ts1) - + @accounting.insert(create_vmpool_hash) check_lines(0,0) - + ts2 = 200 @accounting.set_mock_timestamp(ts2) @@ -249,15 +249,15 @@ describe "1 Vm 1 History" do :reason => 0 ] } - + @mock_client.add_vm(1, values) @accounting.insert(create_vmpool_hash) check_lines(1,1) - + history = values[:history].first sum = ts2 - history[:estime] - + warn "* T1 ESTIME T2" @watch_client.epilog_time(ts1, ts2).to_i.should eql(sum) warn " - By User" @@ -266,26 +266,26 @@ describe "1 Vm 1 History" do @watch_client.epilog_time(ts1, ts2, :hid => 7).to_i.should eql(sum) warn " - By Vm" @watch_client.epilog_time(ts1, ts2, :vmid => 1).to_i.should eql(sum) - + warn " - Non existent User" @watch_client.epilog_time(ts1, ts2, :uid => 555).to_i.should eql(0) warn " - Non existent Host" @watch_client.epilog_time(ts1, ts2, :hid => 555).to_i.should eql(0) warn " - Non existent Vm" @watch_client.epilog_time(ts1, ts2, :vmid => 555).to_i.should eql(0) - + warn "* ESTIME T1 T2" @watch_client.epilog_time(190, ts2).to_i.should eql(ts2-190) warn "* T1 ESTIME T2-10" @watch_client.epilog_time(ts1, ts2-10).to_i.should eql(sum-10) warn "* T1 T2 ESTIME" @watch_client.epilog_time(110, 130).to_i.should eql(0) - + warn "* Non Running time" @watch_client.running_time(ts1, ts2).to_i.should eql(15) warn "* Non Prolog time" @watch_client.prolog_time(ts1, ts2).to_i.should eql(5) - + ts3 = 300 @accounting.set_mock_timestamp(ts2) @@ -303,15 +303,15 @@ describe "1 Vm 1 History" do :reason => 0 ] } - + @mock_client.add_vm(1, values) @accounting.insert(create_vmpool_hash) check_lines(1,1) - + history = values[:history].first sum = history[:eetime] - history[:estime] - + warn "* T1 PSTIME PETIME T3" @watch_client.epilog_time(ts1, ts3).to_i.should eql(sum) warn " - By User" @@ -320,13 +320,13 @@ describe "1 Vm 1 History" do @watch_client.epilog_time(ts1, ts3, :hid => 7).to_i.should eql(sum) warn " - By Vm" @watch_client.epilog_time(ts1, ts3, :vmid => 1).to_i.should eql(sum) - + warn "* T1 PSTIME T3 PETIME" @watch_client.epilog_time(ts1, 230).to_i.should eql(230 - history[:estime]) - + warn "* PSTIME T1 PETIME T3" @watch_client.epilog_time(190, ts3).to_i.should eql(history[:eetime] - 190) - + warn "* PSTIME T1 T3 PETIME" @watch_client.epilog_time(190, 220).to_i.should eql(220 - 190) end diff --git a/src/acct/test/1VmXHis.rb b/src/acct/test/1VmXHis.rb index 13b1549dcc..76c8855bc5 100644 --- a/src/acct/test/1VmXHis.rb +++ b/src/acct/test/1VmXHis.rb @@ -6,20 +6,20 @@ describe "1 Vm X History" do @mock_client = MockClient.new @accounting = OneWatch::Accounting.new(@mock_client) - + @watch_client = AcctClient.new - + @db = WatchHelper::DB check_lines(0,0) end - + it "Running testing" do ts1 = 100 @accounting.set_mock_timestamp(ts1) - + @accounting.insert(create_vmpool_hash) check_lines(0,0) - + ts2 = 200 @accounting.set_mock_timestamp(ts2) @@ -38,18 +38,18 @@ describe "1 Vm X History" do :reason => 0 ] } - + @mock_client.add_vm(1, values) @accounting.insert(create_vmpool_hash) check_lines(1,1) - + history = values[:history].first sum = ts2 - history[:rstime] - + warn "* T1 RSTIME T2" @watch_client.running_time(ts1, ts2).to_i.should eql(sum) - + ts3 = 300 @accounting.set_mock_timestamp(ts2) @@ -81,18 +81,18 @@ describe "1 Vm X History" do } ] } - + @mock_client.add_vm(1, values) @accounting.insert(create_vmpool_hash) check_lines(1,2) - + h1 = values[:history].first sum1 = h1[:retime] - h1[:rstime] h2 = values[:history].last sum2 = ts3 - h2[:rstime] - + warn "* T1 RSTIME1 RETIME1 RSTIME1 T2" @watch_client.running_time(ts1, ts3).to_i.should eql(sum1 + sum2) end diff --git a/src/acct/test/XVm1His.rb b/src/acct/test/XVm1His.rb index faf17ab0b4..1aa11c2d7c 100644 --- a/src/acct/test/XVm1His.rb +++ b/src/acct/test/XVm1His.rb @@ -6,20 +6,20 @@ describe "X Vm 1 History" do @mock_client = MockClient.new @accounting = OneWatch::Accounting.new(@mock_client) - + @watch_client = AcctClient.new - + @db = WatchHelper::DB check_lines(0,0) end - + it "Running testing" do ts1 = 100 @accounting.set_mock_timestamp(ts1) - + @accounting.insert(create_vmpool_hash) check_lines(0,0) - + ts2 = 200 @accounting.set_mock_timestamp(ts2) @@ -38,21 +38,21 @@ describe "X Vm 1 History" do :reason => 0 ] } - + @mock_client.add_vm(1, values) @accounting.insert(create_vmpool_hash) check_lines(1,1) - + history = values[:history].first sum = ts2 - history[:rstime] - + warn "* T1 RSTIME T2" @watch_client.running_time(ts1, ts2).to_i.should eql(sum) - + ts3 = 300 @accounting.set_mock_timestamp(ts3) - + values2 = { :uid => 2, :gid => 4, @@ -68,18 +68,18 @@ describe "X Vm 1 History" do :reason => 0 ] } - + @mock_client.add_vm(2, values2) @accounting.insert(create_vmpool_hash) check_lines(2,2) - + history1 = values[:history].first sum1 = ts3 - history1[:rstime] - + history2 = values2[:history].first sum2 = ts3 - history2[:rstime] - + warn "* T1 RSTIME T2" @watch_client.running_time(ts1, ts3).to_i.should eql(sum1 + sum2) @watch_client.running_time(ts1, ts3, :vmid=>1).to_i.should eql(sum1) diff --git a/src/acct/test/helper/mock_client.rb b/src/acct/test/helper/mock_client.rb index 53a560313f..87086ed8da 100644 --- a/src/acct/test/helper/mock_client.rb +++ b/src/acct/test/helper/mock_client.rb @@ -6,12 +6,12 @@ class MockClient def initialize @vmpool = File.read("./fixtures/empty_pool.xml") @done_vmpool = File.read("./fixtures/empty_pool.xml") - + @vms = Hash.new @done_vms = Hash.new end - + def call(action, *args) xmlrpc_action = "one."+action @@ -33,7 +33,7 @@ class MockClient end end end - + def add_vm(id, values) if values[:state] == 6 @done_vms[id] = values @@ -41,7 +41,7 @@ class MockClient @vms[id] = values end end - + def delete_vm(id) @vms.delete(id) @vms_done.delete(id) diff --git a/src/acct/test/helper/test_helper.rb b/src/acct/test/helper/test_helper.rb index bfef9dee6f..91a11dc67c 100644 --- a/src/acct/test/helper/test_helper.rb +++ b/src/acct/test/helper/test_helper.rb @@ -15,8 +15,8 @@ require 'OpenNebula' $: << './helper' $: << '.' $: << '..' - - + + require 'examples/acct_client' require 'watch_client' require 'mock_client' @@ -28,18 +28,18 @@ module OneWatch class Accounting def set_mock_timestamp(t) @mock_timestamp = t - end - + end + def generate_timestamp @mock_timestamp end end - + class Monitoring def set_mock_timestamp(t) @mock_timestamp = t - end - + end + def generate_timestamp @mock_timestamp end @@ -55,9 +55,9 @@ end def clean_db begin WatchHelper::Register.destroy - WatchHelper::Metric.destroy - WatchHelper::VmShare.destroy - WatchHelper::HostShare.destroy + WatchHelper::Delta.destroy + WatchHelper::VmSample.destroy + WatchHelper::HostSample.destroy WatchHelper::Vm.destroy WatchHelper::Host.destroy rescue Exception => e diff --git a/src/acct/test/monitoring_spec.rb b/src/acct/test/monitoring_spec.rb index d5d9eea094..d66dfa578b 100644 --- a/src/acct/test/monitoring_spec.rb +++ b/src/acct/test/monitoring_spec.rb @@ -6,20 +6,20 @@ describe "1 Vm 1 10 steps" do @mock_client = MockClient.new @monitoring = OneWatch::VmMonitoring.new - + @watch_client = OneWatchClient::WatchClient.new - + @db = WatchHelper::DB @db[:vms].count.should eql(0) end - + it "CPU testing" do ts1 = 100 @monitoring.set_mock_timestamp(ts1) - + @monitoring.insert(create_vmpool_hash) @db[:vms].count.should eql(0) - + 10.times { |i| ts2 = 200+100*i @monitoring.set_mock_timestamp(ts2) @@ -48,9 +48,9 @@ describe "1 Vm 1 10 steps" do @monitoring.insert(create_vmpool_hash) @db[:vms].count.should eql(1) - @db[:vm_shares].count.should eql(1+i > 5 ? 5 : 1+i) - - pp @watch_client.vm_monitoring(1) + @db[:vm_samples].count.should eql(1+i > 5 ? 5 : 1+i) + + pp @watch_client.vm_monitoring(1, ['cpu', 'net_tx']) } end end \ No newline at end of file diff --git a/src/acct/watch_client.rb b/src/acct/watch_client.rb index 427a7e43bc..b0b6a4524d 100644 --- a/src/acct/watch_client.rb +++ b/src/acct/watch_client.rb @@ -1,29 +1,48 @@ module OneWatchClient require 'watch_helper' require 'json' - + class WatchClient def vm_monitoring(id, opts=[]) + if resource = WatchHelper::Vm[id] + monitoring(resource, "VM", WatchHelper::VM_SAMPLE, opts) + else + return nil + end + end + + def host_monitoring(id, opts=[]) + if resource = WatchHelper::Host[id] + monitoring(resource, "HOST", WatchHelper::HOST_SAMPLE, opts) + else + return nil + end + end + + private + + def monitoring(rsql, kind, allowed_sample, monitoring_resources) hash = Hash.new - hash[:resource] = "VM" - hash[:id] = id - + hash[:resource] = kind + hash[:id] = rsql.id + mon = Hash.new - opts.each { |opt| - next unless WatchHelper::VM_SHARE.has_key?(opt.to_sym) - mon[opt] = Array.new + monitoring_resources.each { |mr| + if allowed_sample.has_key?(mr.to_sym) + mon[mr] = Array.new + else + opts.remove(opt) + end } - # TBD Check if VM exists - WatchHelper::Vm[id].vm_shares_dataset.map { |vm| - opts.each { |opt| - next unless WatchHelper::VM_SHARE.has_key?(opt.to_sym) - mon[opt] << [vm.last_poll, vm.send(opt.to_sym)] + rsql.samples_dataset.map { |sample| + monitoring_resources.each { |mr| + mon[mr] << [sample.last_poll, sample.send(mr.to_sym)] } } - + hash[:monitoring] = mon - + puts JSON.pretty_generate hash end end diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index 7a98c9992b..e355f9df35 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -1,168 +1,26 @@ module WatchHelper DB = Sequel.connect('sqlite:///tmp/test_one_acct.db') - class Register < Sequel::Model - plugin :schema - - set_schema do - foreign_key :vm_id, :vms - Integer :hid - String :hostname - Integer :seq - Integer :pstime - Integer :petime - Integer :rstime - Integer :retime - Integer :estime - Integer :eetime - Integer :reason - - primary_key [:vm_id, :seq] - end + VM_SAMPLE = { + :cpu => { + :type => Integer, + :path => 'CPU' + }, + :memory => { + :type => Integer, + :path => 'MEMORY' + }, + :net_tx => { + :type => Integer, + :path => 'NET_TX' + }, + :net_rx => { + :type => Integer, + :path => 'NET_RX' + } + } - create_table unless table_exists? - - unrestrict_primary_key - - many_to_one :vm - - def update_from_history(history) - self.seq = history['SEQ'] - self.hostname = history['HOSTNAME'] - self.hid = history['HID'] - self.pstime = history['PSTIME'] - self.petime = history['PETIME'] - self.rstime = history['RSTIME'] - self.retime = history['RETIME'] - self.estime = history['ESTIME'] - self.eetime = history['EETIME'] - self.reason = history['REASON'] - - self.save - end - - def self.create_from_history(history) - a = Register.create( - :seq => history['SEQ'], - :hostname => history['HOSTNAME'], - :hid => history['HID'], - :pstime => history['PSTIME'], - :petime => history['PETIME'], - :rstime => history['RSTIME'], - :retime => history['RETIME'], - :estime => history['ESTIME'], - :eetime => history['EETIME'], - :reason => history['REASON'] - ) - end - end - - class Metric < Sequel::Model - plugin :schema - - set_schema do - foreign_key :vm_id, :vms - Integer :timestamp - Integer :ptimestamp - Integer :net_rx - Integer :net_tx - - primary_key [:vm_id, :timestamp] - end - - create_table unless table_exists? - - unrestrict_primary_key - - many_to_one :vm - end - - class Vm < Sequel::Model - plugin :schema - - set_schema do - Integer :id, :primary_key=>true - String :name - Integer :uid - Integer :gid - Integer :mem - Integer :cpu - Integer :vcpu - Integer :stime - Integer :etime - end - - create_table unless table_exists? - - unrestrict_primary_key - - # Accounting - one_to_many :registers, :order=>:seq - one_to_many :metrics - - # Monitoring - one_to_many :vm_shares, :before_add=>:control_regs, :order=>:timestamp - - def self.info(vm) - Vm.find_or_create(:id=>vm['ID']) { |v| - v.uid = vm['UID'].to_i - v.name = vm['NAME'] - v.gid = vm['GID'].to_i - v.mem = vm['MEMORY'].to_i - v.cpu = vm['CPU'].to_i - v.vcpu = vm['VCPU'].to_i - v.stime = vm['STIME'].to_i - v.etime = vm['ETIME'].to_i - } - end - - def add_share(vm, timestamp) - vs = VmShare.create_from_vm(vm, timestamp) - self.add_vm_share(vs) - end - - private - - def control_regs(share) - if self.vm_shares.count > 4 - self.vm_shares.first.delete - end - end - end - - class Host < Sequel::Model - plugin :schema - - set_schema do - Integer :id, :primary_key=>true - String :name - Integer :im_mad - Integer :vm_mad - Integer :tm_mad - end - - create_table unless table_exists? - - unrestrict_primary_key - - # Monitoring - one_to_many :host_shares, :before_add=>:control_regs, :order=>:timestamp - - def add_share(host, timestamp) - hs = HostShare.create_from_host(host, timestamp) - self.add_host_share(hs) - end - - private - - def control_regs(share) - if self.host_shares.count > 4 - self.host_shares.first.delete - end - end - end - - HOST_SHARE = { + HOST_SAMPLE = { :disk_usage => { :type => Integer, :path => 'DISK_USAGE' @@ -217,85 +75,29 @@ module WatchHelper } } - class HostShare < Sequel::Model + class VmSample < Sequel::Model plugin :schema - - set_schema do - foreign_key :host_id, :hosts - Integer :last_poll - Integer :timestamp - HOST_SHARE.each { |key,value| - column key, value[:type] - } - - primary_key [:host_id, :timestamp] - end - - create_table unless table_exists? - - unrestrict_primary_key - - many_to_one :host - - def self.create_from_host(host, timestamp) - hash = { - :timestamp => timestamp, - :last_poll => host['LAST_MON_TIME'], - :state => host['STATE'], - } - - host_share = host['HOST_SHARE'] - HOST_SHARE.each { |key,value| - hash[key] = host_share[value[:path]] - } - - HostShare.create(hash) - end - end - - VM_SHARE = { - :cpu => { - :type => Integer, - :path => 'CPU' - }, - :memory => { - :type => Integer, - :path => 'MEMORY' - }, - :net_tx => { - :type => Integer, - :path => 'NET_TX' - }, - :net_rx => { - :type => Integer, - :path => 'NET_RX' - } - } - - class VmShare < Sequel::Model - plugin :schema - set_schema do foreign_key :vm_id, :vms Integer :state Integer :lcm_state Integer :last_poll Integer :timestamp - - VM_SHARE.each { |key,value| + + VM_SAMPLE.each { |key,value| column key, value[:type] } - + primary_key [:vm_id, :timestamp] end create_table unless table_exists? - + unrestrict_primary_key - + many_to_one :vm - + def self.create_from_vm(vm, timestamp) hash = { :timestamp => timestamp, @@ -303,13 +105,219 @@ module WatchHelper :state => vm['STATE'], :lcm_state => vm['LCM_STATE'], } - - VM_SHARE.each { |key,value| + + VM_SAMPLE.each { |key,value| hash[key] = vm[value[:path]] } - - VmShare.create(hash) + + VmSample.create(hash) + end + end + + class HostSample < Sequel::Model + plugin :schema + + set_schema do + foreign_key :host_id, :hosts + Integer :last_poll + Integer :timestamp + + HOST_SAMPLE.each { |key,value| + column key, value[:type] + } + + primary_key [:host_id, :timestamp] + end + + create_table unless table_exists? + + unrestrict_primary_key + + many_to_one :host + + def self.create_from_host(host, timestamp) + hash = { + :timestamp => timestamp, + :last_poll => host['LAST_MON_TIME'], + :state => host['STATE'], + } + + host_share = host['HOST_SHARE'] + HOST_SAMPLE.each { |key,value| + hash[key] = host_share[value[:path]] + } + + HostSample.create(hash) + end + end + + class Register < Sequel::Model + plugin :schema + + set_schema do + foreign_key :vm_id, :vms + Integer :hid + String :hostname + Integer :seq + Integer :pstime + Integer :petime + Integer :rstime + Integer :retime + Integer :estime + Integer :eetime + Integer :reason + + primary_key [:vm_id, :seq] + end + + create_table unless table_exists? + + unrestrict_primary_key + + many_to_one :vm + + def update_from_history(history) + self.seq = history['SEQ'] + self.hostname = history['HOSTNAME'] + self.hid = history['HID'] + self.pstime = history['PSTIME'] + self.petime = history['PETIME'] + self.rstime = history['RSTIME'] + self.retime = history['RETIME'] + self.estime = history['ESTIME'] + self.eetime = history['EETIME'] + self.reason = history['REASON'] + + self.save + end + + def self.create_from_history(history) + a = Register.create( + :seq => history['SEQ'], + :hostname => history['HOSTNAME'], + :hid => history['HID'], + :pstime => history['PSTIME'], + :petime => history['PETIME'], + :rstime => history['RSTIME'], + :retime => history['RETIME'], + :estime => history['ESTIME'], + :eetime => history['EETIME'], + :reason => history['REASON'] + ) + end + end + + class Delta < Sequel::Model + plugin :schema + + set_schema do + foreign_key :vm_id, :vms + Integer :timestamp + Integer :ptimestamp + Integer :net_rx + Integer :net_tx + + primary_key [:vm_id, :timestamp] + end + + create_table unless table_exists? + + unrestrict_primary_key + + many_to_one :vm + end + + class Vm < Sequel::Model + plugin :schema + + set_schema do + Integer :id, :primary_key=>true + String :name + Integer :uid + Integer :gid + Integer :mem + Integer :cpu + Integer :vcpu + Integer :stime + Integer :etime + end + + create_table unless table_exists? + + unrestrict_primary_key + + # Accounting + one_to_many :registers, :order=>:seq + one_to_many :deltas + + # Monitoring + one_to_many :samples, :before_add=>:control_regs, :order=>:timestamp, :class=>VmSample + + def self.info(vm) + Vm.find_or_create(:id=>vm['ID']) { |v| + v.name = vm['NAME'] + v.uid = vm['UID'].to_i + v.gid = vm['GID'].to_i + v.mem = vm['MEMORY'].to_i + v.cpu = vm['CPU'].to_i + v.vcpu = vm['VCPU'].to_i + v.stime = vm['STIME'].to_i + v.etime = vm['ETIME'].to_i + } + end + + def add_sample_from_resource(vm, timestamp) + vs = VmSample.create_from_vm(vm, timestamp) + self.add_sample(vs) + end + + private + + def control_regs(sample) + if self.samples.count > 4 + self.samples.first.delete + end + end + end + + class Host < Sequel::Model + plugin :schema + + set_schema do + Integer :id, :primary_key=>true + String :name + Integer :im_mad + Integer :vm_mad + Integer :tm_mad + end + + create_table unless table_exists? + + unrestrict_primary_key + + # Monitoring + one_to_many :samples, :before_add=>:control_regs, :order=>:timestamp, :class=>HostSample + + def self.info(host) + Host.find_or_create(:id=>host['ID']) { |h| + h.name = host['NAME'] + h.im_mad = host['IM_MAD'] + h.vm_mad = host['VM_MAD'] + h.tm_nad = host['TM_MAD'] + } + end + + def add_sample_from_resource(host, timestamp) + hs = HostSample.create_from_host(host, timestamp) + self.add_sample(hs) + end + + private + + def control_regs(sample) + if self.samples.count > 4 + self.samples.first.delete + end end end end - \ No newline at end of file From 4bbd7aa5290891e84a74d19400f626069933ef2d Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 6 Jul 2011 13:01:39 +0200 Subject: [PATCH 04/26] feature #696: Add a bash script to launch the acctd ruby daemon --- src/acct/acctd | 66 +++++++++++++++++++++ src/acct/acctd.rb | 124 ++++++++++++++++++++++++++++++++++++++++ src/acct/etc/acctd.conf | 27 +++++++++ 3 files changed, 217 insertions(+) create mode 100755 src/acct/acctd create mode 100755 src/acct/acctd.rb create mode 100644 src/acct/etc/acctd.conf diff --git a/src/acct/acctd b/src/acct/acctd new file mode 100755 index 0000000000..52b7382767 --- /dev/null +++ b/src/acct/acctd @@ -0,0 +1,66 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +if [ -z "$ONE_LOCATION" ]; then + ACCTD_CMD=/usr/lib/one/ruby/acct/acctd.rb + ACCTD_LOG=/var/log/one/acctd.log + ACCTD_PID_FILE=/var/run/one/acctd.pid +else + ACCTD_CMD=$ONE_LOCATION/lib/ruby/acct/acctd.rb + ACCTD_LOG=$ONE_LOCATION/var/acctd.log + ACCTD_PID_FILE=$ONE_LOCATION/var/acctd.pid +fi + +function acctd_running { + ACCTD_PID=`cat $ACCTD_PID_FILE 2>/dev/null` + ps "$ACCTD_PID" &> /dev/null +} + +COMMAND=$1 + +case $COMMAND in +start) + # check if running + acctd_running + if [ "$?" = "0" ]; then + echo "acctd already running." + exit 1 + fi + + # acctd not running, safe to start + $ACCTD_CMD &> $ACCTD_LOG & + echo $! > $ACCTD_PID_FILE + ;; +stop) + # check if running + acctd_running + if [ "$?" != "0" ]; then + echo "acctd not running." + exit 1 + fi + + # acctd running, safe to stop + ACCTD_PID=`cat $ACCTD_PID_FILE 2>/dev/null` + kill $ACCTD_PID &> /dev/null + rm -f $ACCTD_PID_FILE &> /dev/null + ;; +*) + echo "Usage: acctd {start|stop}" >&2 + exit 3 + ;; +esac diff --git a/src/acct/acctd.rb b/src/acct/acctd.rb new file mode 100755 index 0000000000..0b83239a83 --- /dev/null +++ b/src/acct/acctd.rb @@ -0,0 +1,124 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +ONE_LOCATION=ENV["ONE_LOCATION"] + +if !ONE_LOCATION + RUBY_LIB_LOCATION="/usr/lib/one/ruby" + ACCTD_CONF="/etc/one/acctd.conf" +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" + ACCTD_CONF=ONE_LOCATION+"/etc/acctd.conf" +end + +$: << RUBY_LIB_LOCATION +$: << RUBY_LIB_LOCATION+"/acct" + +require 'yaml' + +require 'OpenNebula' +require 'sequel' +require 'watch_helper' + +CONF = YAML.load_file(ACCTD_CONF) + +class Watcher + def initialize + @monitors = Array.new + end + + def add(resource, steps, pools) + @monitors << { :resource => resource, + :steps => steps, + :pools => [pools].flatten + } + end + + def log(resource,msg=nil) + msg ||= "watched" + STDERR.puts "#{Time.now} [#{resource.class}] #{msg}" + end + + def update(step) + # clear pool cache + @pool_cache = Hash.new + + @monitors.each do |monitor| + if monitor[:steps] > 0 and step % monitor[:steps] == 0 + monitor[:pools].each do |pool| + if pool_hash = @pool_cache[pool] + else + pool.info + pool_hash = pool.to_hash + @pool_cache[pool] = pool_hash + end + + resource = monitor[:resource] + resource.insert(pool_hash) + log(resource) + end + end + end + end +end + +watcher = Watcher.new + +# OpenNebula variables +one_client = OpenNebula::Client.new +vm_pool = nil # common for accounting and monitoring +host_pool = nil + +# Initialize accounting +if CONF[: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) +end + +# Initialize monitoring +if CONF[:MONITORING_STEPS] > 0 + require 'monitoring' + + vm_monitoring = OneWatch::VmMonitoring.new(one_client) + host_monitoring = OneWatch::HostMonitoring.new(one_client) + + vm_pool ||= OpenNebula::VirtualMachinePool.new(one_client, -2) + host_pool ||= OpenNebula::HostPool.new(one_client) + + watcher.add(vm_monitoring, CONF[:MONITORING_STEPS], vm_pool) + #watcher.add(host_monitoring, CONF[:MONITORING_STEPS], host_pool) +end + +step = 0 +loop do + start_time = Time.now + step = step + 1 + + watcher.update(step) + + diff_time = Time.now - start_time + + if diff_time < CONF[:STEP] + sleep (CONF[:STEP] - diff_time) + end +end diff --git a/src/acct/etc/acctd.conf b/src/acct/etc/acctd.conf new file mode 100644 index 0000000000..1eb11c4a58 --- /dev/null +++ b/src/acct/etc/acctd.conf @@ -0,0 +1,27 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +# Duration of each daemon loop in seconds +:STEP: 1 + +# Number of daemon loops until an accounting watch +:ACCOUNTING_STEPS: 1 + +# Number of daemon loops until a monitiroing watch +:MONITORING_STEPS: 1 + +# Number of records to preserve +:WINDOW_SIZE: 5 From 3fe28c5dd2bce7497176323d3fdf14c4688e2ef8 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 6 Jul 2011 13:14:14 +0200 Subject: [PATCH 05/26] feature #696: enable host monitoring and fix minor bugs in watch_helper --- src/acct/acctd.rb | 2 +- src/acct/watch_helper.rb | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/acct/acctd.rb b/src/acct/acctd.rb index 0b83239a83..265d2925ae 100755 --- a/src/acct/acctd.rb +++ b/src/acct/acctd.rb @@ -106,7 +106,7 @@ if CONF[:MONITORING_STEPS] > 0 host_pool ||= OpenNebula::HostPool.new(one_client) watcher.add(vm_monitoring, CONF[:MONITORING_STEPS], vm_pool) - #watcher.add(host_monitoring, CONF[:MONITORING_STEPS], host_pool) + watcher.add(host_monitoring, CONF[:MONITORING_STEPS], host_pool) end step = 0 diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index e355f9df35..a04e7301fc 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -121,6 +121,7 @@ module WatchHelper foreign_key :host_id, :hosts Integer :last_poll Integer :timestamp + Integer :state HOST_SAMPLE.each { |key,value| column key, value[:type] @@ -286,9 +287,9 @@ module WatchHelper set_schema do Integer :id, :primary_key=>true String :name - Integer :im_mad - Integer :vm_mad - Integer :tm_mad + String :im_mad + String :vm_mad + String :tm_mad end create_table unless table_exists? @@ -303,7 +304,7 @@ module WatchHelper h.name = host['NAME'] h.im_mad = host['IM_MAD'] h.vm_mad = host['VM_MAD'] - h.tm_nad = host['TM_MAD'] + h.tm_mad = host['TM_MAD'] } end From c4b15d56fb3d90d5a40a98c0c7362ffab91c2215 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 6 Jul 2011 18:48:44 +0200 Subject: [PATCH 06/26] feature #696: Add monitoring client --- src/acct/test/monitoring_spec.rb | 49 +++++++++++++++++- src/acct/watch_client.rb | 88 ++++++++++++++++++++++++++++++-- src/acct/watch_helper.rb | 16 ++++++ 3 files changed, 147 insertions(+), 6 deletions(-) diff --git a/src/acct/test/monitoring_spec.rb b/src/acct/test/monitoring_spec.rb index d66dfa578b..34e7d76915 100644 --- a/src/acct/test/monitoring_spec.rb +++ b/src/acct/test/monitoring_spec.rb @@ -50,7 +50,54 @@ describe "1 Vm 1 10 steps" do @db[:vms].count.should eql(1) @db[:vm_samples].count.should eql(1+i > 5 ? 5 : 1+i) - pp @watch_client.vm_monitoring(1, ['cpu', 'net_tx']) + @watch_client.vm_monitoring(1, ['cpu', 'net_tx']) + + @watch_client.vm_total + } + end + + it "Total testing" do + ts1 = 100 + @monitoring.set_mock_timestamp(ts1) + + @monitoring.insert(create_vmpool_hash) + @db[:vms].count.should eql(0) + + 10.times { |i| + ts2 = 200+100*i + @monitoring.set_mock_timestamp(ts2) + + values = { + :cpu => 80+i, + :memory => 122+i, + :net_tx => 200+i, + :net_rx => 134+i, + :state => 7, + :last_poll => 1309275256+i, + :uid => 2, + :gid => 4, + :history => [ + :hid => 7, + :pstime => 150, + :petime => 0, + :rstime => 0, + :retime => 0, + :estime => 0, + :eetime => 0, + :reason => 0 + ] + } + + @mock_client.add_vm(1, values) + @mock_client.add_vm(2, values) + + @monitoring.insert(create_vmpool_hash) + #@db[:vms].count.should eql(1) + #@db[:vm_samples].count.should eql(1+i > 5 ? 5 : 1+i) + + #pp @watch_client.vm_monitoring(1, ['cpu', 'net_tx']) + # "total" + pp @watch_client.vm_total('total') } end end \ No newline at end of file diff --git a/src/acct/watch_client.rb b/src/acct/watch_client.rb index b0b6a4524d..4fbd9552de 100644 --- a/src/acct/watch_client.rb +++ b/src/acct/watch_client.rb @@ -1,11 +1,15 @@ module OneWatchClient require 'watch_helper' - require 'json' class WatchClient def vm_monitoring(id, opts=[]) if resource = WatchHelper::Vm[id] - monitoring(resource, "VM", WatchHelper::VM_SAMPLE, opts) + resource_monitoring( + resource, + "VM", + WatchHelper::VM_SAMPLE, + opts + ) else return nil end @@ -13,15 +17,89 @@ module OneWatchClient def host_monitoring(id, opts=[]) if resource = WatchHelper::Host[id] - monitoring(resource, "HOST", WatchHelper::HOST_SAMPLE, opts) + resource_monitoring( + resource, + "HOST", + WatchHelper::HOST_SAMPLE, + opts + ) else return nil end end + def vm_total(opts=[]) + total_monitoring( + WatchHelper::VmSample, + "VM", + WatchHelper::VM_SAMPLE, + opts + ) + end + + def host_total(opts=[]) + total_monitoring( + WatchHelper::HostSample, + "HOST", + WatchHelper::HOST_SAMPLE, + opts + ) + end + private - def monitoring(rsql, kind, allowed_sample, monitoring_resources) + def total_monitoring(rsql, kind, allowed_samples, monitoring_resources) + hash = Hash.new + hash[:resource] = "#{kind.upcase}_POOL" + + mon = Hash.new + monitoring_resources.each { |opt| + mon[opt] = case opt + when allowed_samples.include?(opt) + sum_monitoring(rsql, kind, opt) + when "total", "active", "error" + count_monitoring(rsql, opt) + end + } + + hash[:monitoring] = mon + + hash + end + + def sum_monitoring(rsql, kind, mr) + a = Array.new + + WatchHelper::DB.fetch( + "SELECT last_poll,sum(u#{mr}) AS sum_#{mr} FROM " << + "(SELECT last_poll, max(#{mr}) AS u#{mr} " << + "FROM #{kind.downcase}_samples " << + "GROUP BY #{kind.downcase}_id, last_poll) " << + "GROUP BY last_poll;" + ) do |row| + a << [row[:last_poll], row["sum_#{mr}"]] + end + + a + end + + def count_monitoring(rsql, opt) + resources = case opt + when "total" then rsql + when "active" then rsql.active + when "error" then rsql.error + else return nil + end + + a = Array.new + resources.group_and_count(:timestamp).collect { |row| + a << [row[:timestamp], row[:count]] + } + + a + end + + def resource_monitoring(rsql, kind, allowed_sample, monitoring_resources) hash = Hash.new hash[:resource] = kind hash[:id] = rsql.id @@ -43,7 +121,7 @@ module OneWatchClient hash[:monitoring] = mon - puts JSON.pretty_generate hash + hash end end end \ No newline at end of file diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index e355f9df35..747ec0194a 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -112,6 +112,14 @@ module WatchHelper VmSample.create(hash) end + + def self.active + self.filter(:state=>3) + end + + def self.error + self.filter(:state=>7) + end end class HostSample < Sequel::Model @@ -149,6 +157,14 @@ module WatchHelper HostSample.create(hash) end + + def self.active + self.filter(:state<3) + end + + def self.error + self.filter(:state=>3) + end end class Register < Sequel::Model From ff9e27ec5dd94474f6d0ca11ce186b9e2f87110e Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 6 Jul 2011 18:49:42 +0200 Subject: [PATCH 07/26] feature #696: Update Sunstone for the new acct/monitoring --- src/sunstone/models/SunstoneServer.rb | 34 ++++++++++++++++----------- src/sunstone/sunstone-server.rb | 11 +++++++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index d654f50649..70c915798a 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -17,7 +17,7 @@ require 'OpenNebulaJSON' include OpenNebulaJSON -require 'OneMonitorClient' +require 'acct/WatchClient' class SunstoneServer def initialize(username, password) @@ -280,22 +280,28 @@ class SunstoneServer # ############################################################################ - def get_log(params) - resource = params[:resource] - id = params[:id] - id = "global" unless id + def get_monitoring(id, resource, monitoring_resources) + watch_client = OneWatchClient::WatchClient.new columns = params['monitor_resources'].split(',') - history_length = params['history_length'] - log_file_folder = case resource - when "vm","VM" - VM_LOG_FOLDER - when "host","HOST" - HOST_LOG_FOLDER - end + rc = case resource + when "vm","VM" + if id + watch_client.vm_monitoring(id, columns) + else + watch_client.vm_total(columns) + end + when "host","HOST" + if id + watch_client.host_monitoring(id, columns) + else + watch_client.host_total(columns) + end + else + return [200, nil] + end - monitor_client = OneMonitorClient.new(id,log_file_folder) - return monitor_client.get_data_for_id(id,columns,history_length).to_json + return [200, rc.to_json] end ############################################################################ diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index e941bb6cfa..9207e677e4 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -167,11 +167,18 @@ end ############################################################################## get '/:resource/monitor' do - @SunstoneServer.get_log(params) + @SunstoneServer.get_monitoring( + params[:id], + params[:resource], + params[:monitoring_resources] + ) end get '/:resource/:id/monitor' do - @SunstoneServer.get_log(params) + @SunstoneServer.get_monitoring( + params[:resource], + params[:monitoring_resources] + ) end From bc3f69c3d04c1d425f95fb644c3700b291243d6d Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 6 Jul 2011 19:01:02 +0200 Subject: [PATCH 08/26] feature #696: use configuration file for window size and db uri --- src/acct/etc/acctd.conf | 16 +++++++++++----- src/acct/watch_helper.rb | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/acct/etc/acctd.conf b/src/acct/etc/acctd.conf index 1eb11c4a58..c1c968a084 100644 --- a/src/acct/etc/acctd.conf +++ b/src/acct/etc/acctd.conf @@ -14,14 +14,20 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -# Duration of each daemon loop in seconds -:STEP: 1 +# Database URI +:DB: sqlite:///tmp/test_one_acct.db + +# Duration of each daemon loop in seconds +:STEP: 2 # Number of daemon loops until an accounting watch :ACCOUNTING_STEPS: 1 -# Number of daemon loops until a monitiroing watch -:MONITORING_STEPS: 1 +# Number of daemon loops until a VM monitoring watch +:VM_MONITORING_STEPS: 1 + +# Number of daemon loops until a Hosts monitoring watch +:HOST_MONITORING_STEPS: 1 # Number of records to preserve -:WINDOW_SIZE: 5 +:WINDOW_SIZE: 10 diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index a04e7301fc..ef0e5bca5d 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -1,5 +1,17 @@ module WatchHelper - DB = Sequel.connect('sqlite:///tmp/test_one_acct.db') + require 'yaml' + + ONE_LOCATION=ENV["ONE_LOCATION"] + + if !ONE_LOCATION + ACCTD_CONF="/etc/one/acctd.conf" + else + ACCTD_CONF=ONE_LOCATION+"/etc/acctd.conf" + end + + CONF = YAML.load_file(ACCTD_CONF) + + DB = Sequel.connect(CONF[:DB]) VM_SAMPLE = { :cpu => { @@ -275,7 +287,7 @@ module WatchHelper private def control_regs(sample) - if self.samples.count > 4 + if self.samples.count > CONF[:WINDOW_SIZE] - 1 self.samples.first.delete end end @@ -316,7 +328,7 @@ module WatchHelper private def control_regs(sample) - if self.samples.count > 4 + if self.samples.count > CONF[:WINDOW_SIZE] - 1 self.samples.first.delete end end From fd322638bff182f6cdb4918137bfe15c84836f37 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 7 Jul 2011 13:12:27 +0200 Subject: [PATCH 09/26] feature #696: Fix string or symbol error --- src/acct/watch_client.rb | 16 ++++++++-------- src/acct/watch_helper.rb | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/acct/watch_client.rb b/src/acct/watch_client.rb index 4fbd9552de..bcceb40d66 100644 --- a/src/acct/watch_client.rb +++ b/src/acct/watch_client.rb @@ -54,11 +54,11 @@ module OneWatchClient mon = Hash.new monitoring_resources.each { |opt| - mon[opt] = case opt - when allowed_samples.include?(opt) - sum_monitoring(rsql, kind, opt) - when "total", "active", "error" - count_monitoring(rsql, opt) + opt = opt.to_sym + if allowed_samples.has_key?(opt) + mon[opt] = sum_monitoring(rsql, kind, opt) + elsif [:total, :active, :error].include?(opt) + mon[opt] = count_monitoring(rsql, opt) end } @@ -85,9 +85,9 @@ module OneWatchClient def count_monitoring(rsql, opt) resources = case opt - when "total" then rsql - when "active" then rsql.active - when "error" then rsql.error + when :total then rsql + when :active then rsql.active + when :error then rsql.error else return nil end diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index 7204d73231..c527b5b9ba 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -103,7 +103,7 @@ module WatchHelper :timestamp => timestamp, :last_poll => vm['LAST_POLL'], :state => vm['STATE'], - :lcm_state => vm['LCM_STATE'], + :lcm_state => vm['LCM_STATE'] } VM_SAMPLE.each { |key,value| From 059d4aa535da2dd8b2320f1febc98f76847802e1 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 7 Jul 2011 13:38:18 +0200 Subject: [PATCH 10/26] feature #696: check if opennebula is running --- src/acct/acctd | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/acct/acctd b/src/acct/acctd index 52b7382767..5b0a8283bc 100755 --- a/src/acct/acctd +++ b/src/acct/acctd @@ -17,15 +17,28 @@ #--------------------------------------------------------------------------- # if [ -z "$ONE_LOCATION" ]; then + ONE_PID=/var/run/one/oned.pid + LOCK_FILE=/var/lock/one/one ACCTD_CMD=/usr/lib/one/ruby/acct/acctd.rb ACCTD_LOG=/var/log/one/acctd.log ACCTD_PID_FILE=/var/run/one/acctd.pid else + ONE_PID=$ONE_LOCATION/var/oned.pid + LOCK_FILE=$ONE_LOCATION/var/.lock ACCTD_CMD=$ONE_LOCATION/lib/ruby/acct/acctd.rb ACCTD_LOG=$ONE_LOCATION/var/acctd.log ACCTD_PID_FILE=$ONE_LOCATION/var/acctd.pid fi +function oned_running { + ONEPID=`cat $ONE_PID 2> /dev/null` + ps $ONEPID > /dev/null 2>&1 + if [ ! -f "$LOCK_FILE" -o ! -f "$ONE_PID" -o $? -ne 0 ]; then + echo not running + exit 1 + fi +} + function acctd_running { ACCTD_PID=`cat $ACCTD_PID_FILE 2>/dev/null` ps "$ACCTD_PID" &> /dev/null @@ -35,7 +48,10 @@ COMMAND=$1 case $COMMAND in start) - # check if running + # check if OpenNebula running + oned_running + + # check if acct already running acctd_running if [ "$?" = "0" ]; then echo "acctd already running." From 947cf3fe616ce559cd956f327ff592755f331de1 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 7 Jul 2011 13:39:08 +0200 Subject: [PATCH 11/26] feature #696: change logging style. --- src/acct/acctd.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/acct/acctd.rb b/src/acct/acctd.rb index 265d2925ae..3264b50592 100755 --- a/src/acct/acctd.rb +++ b/src/acct/acctd.rb @@ -49,9 +49,8 @@ class Watcher } end - def log(resource,msg=nil) - msg ||= "watched" - STDERR.puts "#{Time.now} [#{resource.class}] #{msg}" + def log(msg) + STDERR.puts "#{Time.now} #{msg}" end def update(step) From 8772a16ff5d0b8e4f18c65ed688c4badfcf60722 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 7 Jul 2011 13:39:32 +0200 Subject: [PATCH 12/26] feature #696: check for errors in info xmlrpc method --- src/acct/acctd.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/acct/acctd.rb b/src/acct/acctd.rb index 3264b50592..c2bb46d734 100755 --- a/src/acct/acctd.rb +++ b/src/acct/acctd.rb @@ -60,16 +60,24 @@ class Watcher @monitors.each do |monitor| if monitor[:steps] > 0 and step % monitor[:steps] == 0 monitor[:pools].each do |pool| + resource = monitor[:resource] + + log "#{resource.class}" + if pool_hash = @pool_cache[pool] else - pool.info + rc = pool.info + if OpenNebula.is_error?(rc) + log "Error: " + rc.message + log "Shutting down" + exit 1 + end + pool_hash = pool.to_hash @pool_cache[pool] = pool_hash end - resource = monitor[:resource] resource.insert(pool_hash) - log(resource) end end end From 73b25c2a27189ad963d7a9ec71a0d12ad61798a4 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 7 Jul 2011 13:40:22 +0200 Subject: [PATCH 13/26] feature #696: separate Host and VM monitoring. Avoid race condition. --- src/acct/acctd.rb | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/acct/acctd.rb b/src/acct/acctd.rb index c2bb46d734..ad43193135 100755 --- a/src/acct/acctd.rb +++ b/src/acct/acctd.rb @@ -91,41 +91,45 @@ one_client = OpenNebula::Client.new vm_pool = nil # common for accounting and monitoring host_pool = nil +# Initialize VM monitoring +if CONF[:VM_MONITORING_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) +end + +# Initialize Host monitoring +if CONF[:HOST_MONITORING_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) +end + # Initialize accounting if CONF[: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) end -# Initialize monitoring -if CONF[:MONITORING_STEPS] > 0 - require 'monitoring' - - vm_monitoring = OneWatch::VmMonitoring.new(one_client) - host_monitoring = OneWatch::HostMonitoring.new(one_client) - - vm_pool ||= OpenNebula::VirtualMachinePool.new(one_client, -2) - host_pool ||= OpenNebula::HostPool.new(one_client) - - watcher.add(vm_monitoring, CONF[:MONITORING_STEPS], vm_pool) - watcher.add(host_monitoring, CONF[:MONITORING_STEPS], host_pool) -end step = 0 loop do start_time = Time.now - step = step + 1 + expected_end_time = start_time + CONF[:STEP] + step += 1 watcher.update(step) - diff_time = Time.now - start_time + end_time = Time.now + sleep_time = start_time + CONF[:STEP] - end_time - if diff_time < CONF[:STEP] - sleep (CONF[:STEP] - diff_time) + if sleep_time >= 1 + sleep sleep_time + else + sleep 1 end end From fbf9c94e49336eb37e6f072bee6911a4ff51c5e6 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 7 Jul 2011 13:54:00 +0200 Subject: [PATCH 14/26] feature #696: Fix Sunstone requires --- src/acct/acctd.rb | 2 -- src/acct/watch_client.rb | 2 +- src/acct/watch_helper.rb | 1 + src/sunstone/models/SunstoneServer.rb | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/acct/acctd.rb b/src/acct/acctd.rb index ad43193135..bb895f1984 100755 --- a/src/acct/acctd.rb +++ b/src/acct/acctd.rb @@ -32,7 +32,6 @@ $: << RUBY_LIB_LOCATION+"/acct" require 'yaml' require 'OpenNebula' -require 'sequel' require 'watch_helper' CONF = YAML.load_file(ACCTD_CONF) @@ -115,7 +114,6 @@ if CONF[:ACCOUNTING_STEPS] > 0 watcher.add(accounting, CONF[:ACCOUNTING_STEPS], vm_pool) end - step = 0 loop do start_time = Time.now diff --git a/src/acct/watch_client.rb b/src/acct/watch_client.rb index bcceb40d66..aea2d0c34a 100644 --- a/src/acct/watch_client.rb +++ b/src/acct/watch_client.rb @@ -1,5 +1,5 @@ module OneWatchClient - require 'watch_helper' + require 'acct/watch_helper' class WatchClient def vm_monitoring(id, opts=[]) diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index cb2ce20410..ff94671e32 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -1,4 +1,5 @@ module WatchHelper + require 'sequel' require 'yaml' ONE_LOCATION=ENV["ONE_LOCATION"] diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index 70c915798a..99b3d5c147 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -17,7 +17,7 @@ require 'OpenNebulaJSON' include OpenNebulaJSON -require 'acct/WatchClient' +require 'acct/watch_client' class SunstoneServer def initialize(username, password) From d911df188989d1678a1a624b19045eb7e3b7e84e Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 7 Jul 2011 16:02:45 +0200 Subject: [PATCH 15/26] feature #696: update install.sh --- install.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index c66d986469..5fe289e233 100755 --- a/install.sh +++ b/install.sh @@ -193,7 +193,8 @@ LIB_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/mads \ $LIB_LOCATION/sh \ $LIB_LOCATION/ruby/cli \ - $LIB_LOCATION/ruby/cli/one_helper" + $LIB_LOCATION/ruby/cli/one_helper \ + $LIB_LOCATION/ruby/acct" VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/im \ @@ -298,6 +299,8 @@ INSTALL_FILES=( MAN_FILES:$MAN_LOCATION CLI_LIB_FILES:$LIB_LOCATION/ruby/cli ONE_CLI_LIB_FILES:$LIB_LOCATION/ruby/cli/one_helper + ACCT_LIB_FILES:$LIB_LOCATION/ruby/acct + ACCT_BIN_FILES:$BIN_LOCATION ) INSTALL_CLIENT_FILES=( @@ -359,6 +362,7 @@ INSTALL_ETC_FILES=( OCCI_ETC_FILES:$ETC_LOCATION OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates CLI_CONF_FILES:$ETC_LOCATION/cli + ACCT_ETC_FILES:$ETC_LOCATION ) #------------------------------------------------------------------------------- @@ -898,6 +902,20 @@ SUNSTONE_PUBLIC_IMAGES_FILES="src/sunstone/public/images/ajax-loader.gif \ src/sunstone/public/images/vnc_off.png \ src/sunstone/public/images/vnc_on.png" +#----------------------------------------------------------------------------- +# ACCT files +#----------------------------------------------------------------------------- + +ACCT_BIN_FILES="src/acct/acctd" + +ACCT_LIB_FILES="src/acct/monitoring.rb \ + src/acct/accounting.rb \ + src/acct/acctd.rb \ + src/acct/watch_helper.rb \ + src/acct/watch_client.rb" + +ACCT_ETC_FILES="src/acct/etc/acctd.conf" + #----------------------------------------------------------------------------- # MAN files #----------------------------------------------------------------------------- From d71a13492da6a2a4e35f2ff3e670725578f37e54 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 7 Jul 2011 16:13:07 +0200 Subject: [PATCH 16/26] feature #696: Fix code for mysql --- src/acct/accounting.rb | 3 +- src/acct/watch_helper.rb | 246 ++++++++++++++++++--------------------- 2 files changed, 112 insertions(+), 137 deletions(-) diff --git a/src/acct/accounting.rb b/src/acct/accounting.rb index e6d17098d1..bbc154ebb2 100644 --- a/src/acct/accounting.rb +++ b/src/acct/accounting.rb @@ -67,8 +67,7 @@ module OneWatch if register && register.seq == history['SEQ'].to_i register.update_from_history(history) else - reg = WatchHelper::Register.create_from_history(history) - vm.add_register(reg) + vm.add_register_from_resource(history) end end diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index cb2ce20410..8557c05bd7 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -87,11 +87,29 @@ module WatchHelper } } - class VmSample < Sequel::Model - plugin :schema + def self.bootstrap + DB.create_table? :vms do + Integer :id, :primary_key=>true + String :name + Integer :uid + Integer :gid + Integer :mem + Integer :cpu + Integer :vcpu + Integer :stime + Integer :etime + end - set_schema do - foreign_key :vm_id, :vms + DB.create_table? :hosts do + Integer :id, :primary_key=>true + String :name + String :im_mad + String :vm_mad + String :tm_mad + end + + DB.create_table? :vm_samples do + foreign_key :vm_id, :vms, :key=>:id Integer :state Integer :lcm_state Integer :last_poll @@ -104,41 +122,8 @@ module WatchHelper primary_key [:vm_id, :timestamp] end - create_table unless table_exists? - - unrestrict_primary_key - - many_to_one :vm - - def self.create_from_vm(vm, timestamp) - hash = { - :timestamp => timestamp, - :last_poll => vm['LAST_POLL'], - :state => vm['STATE'], - :lcm_state => vm['LCM_STATE'] - } - - VM_SAMPLE.each { |key,value| - hash[key] = vm[value[:path]] - } - - VmSample.create(hash) - end - - def self.active - self.filter(:state=>3) - end - - def self.error - self.filter(:state=>7) - end - end - - class HostSample < Sequel::Model - plugin :schema - - set_schema do - foreign_key :host_id, :hosts + DB.create_table? :host_samples do + foreign_key :host_id, :hosts, :key=>:id Integer :last_poll Integer :timestamp Integer :state @@ -150,41 +135,8 @@ module WatchHelper primary_key [:host_id, :timestamp] end - create_table unless table_exists? - - unrestrict_primary_key - - many_to_one :host - - def self.create_from_host(host, timestamp) - hash = { - :timestamp => timestamp, - :last_poll => host['LAST_MON_TIME'], - :state => host['STATE'], - } - - host_share = host['HOST_SHARE'] - HOST_SAMPLE.each { |key,value| - hash[key] = host_share[value[:path]] - } - - HostSample.create(hash) - end - - def self.active - self.filter(:state<3) - end - - def self.error - self.filter(:state=>3) - end - end - - class Register < Sequel::Model - plugin :schema - - set_schema do - foreign_key :vm_id, :vms + DB.create_table? :registers do + foreign_key :vm_id, :vms, :key=>:id Integer :hid String :hostname Integer :seq @@ -199,8 +151,48 @@ module WatchHelper primary_key [:vm_id, :seq] end - create_table unless table_exists? + DB.create_table? :deltas do + foreign_key :vm_id, :vms, :key=>:id + Integer :timestamp + Integer :ptimestamp + Integer :net_rx + Integer :net_tx + primary_key [:vm_id, :timestamp] + end + end + + self.bootstrap + + class VmSample < Sequel::Model + unrestrict_primary_key + + many_to_one :vm + + def self.active + self.filter(:state=>3) + end + + def self.error + self.filter(:state=>7) + end + end + + class HostSample < Sequel::Model + unrestrict_primary_key + + many_to_one :host + + def self.active + self.filter(:state<3) + end + + def self.error + self.filter(:state=>3) + end + end + + class Register < Sequel::Model unrestrict_primary_key many_to_one :vm @@ -219,65 +211,20 @@ module WatchHelper self.save end - - def self.create_from_history(history) - a = Register.create( - :seq => history['SEQ'], - :hostname => history['HOSTNAME'], - :hid => history['HID'], - :pstime => history['PSTIME'], - :petime => history['PETIME'], - :rstime => history['RSTIME'], - :retime => history['RETIME'], - :estime => history['ESTIME'], - :eetime => history['EETIME'], - :reason => history['REASON'] - ) - end end class Delta < Sequel::Model - plugin :schema - - set_schema do - foreign_key :vm_id, :vms - Integer :timestamp - Integer :ptimestamp - Integer :net_rx - Integer :net_tx - - primary_key [:vm_id, :timestamp] - end - - create_table unless table_exists? - unrestrict_primary_key many_to_one :vm end class Vm < Sequel::Model - plugin :schema - - set_schema do - Integer :id, :primary_key=>true - String :name - Integer :uid - Integer :gid - Integer :mem - Integer :cpu - Integer :vcpu - Integer :stime - Integer :etime - end - - create_table unless table_exists? - unrestrict_primary_key # Accounting one_to_many :registers, :order=>:seq - one_to_many :deltas + one_to_many :deltas, :order=>:timestamp # Monitoring one_to_many :samples, :before_add=>:control_regs, :order=>:timestamp, :class=>VmSample @@ -295,7 +242,38 @@ module WatchHelper } end + def add_register_from_resource(history) + self.add_register( + :seq => history['SEQ'], + :hostname => history['HOSTNAME'], + :hid => history['HID'], + :pstime => history['PSTIME'], + :petime => history['PETIME'], + :rstime => history['RSTIME'], + :retime => history['RETIME'], + :estime => history['ESTIME'], + :eetime => history['EETIME'], + :reason => history['REASON'] + ) + end + def add_sample_from_resource(vm, timestamp) + hash = { + :timestamp => timestamp, + :last_poll => vm['LAST_POLL'], + :state => vm['STATE'], + :lcm_state => vm['LCM_STATE'] + } + + VM_SAMPLE.each { |key,value| + hash[key] = vm[value[:path]] + } + + self.add_sample(hash) + end + + def add_delta_from_resource(vm, timestamp) + self.deltas vs = VmSample.create_from_vm(vm, timestamp) self.add_sample(vs) end @@ -310,18 +288,6 @@ module WatchHelper end class Host < Sequel::Model - plugin :schema - - set_schema do - Integer :id, :primary_key=>true - String :name - String :im_mad - String :vm_mad - String :tm_mad - end - - create_table unless table_exists? - unrestrict_primary_key # Monitoring @@ -337,8 +303,18 @@ module WatchHelper end def add_sample_from_resource(host, timestamp) - hs = HostSample.create_from_host(host, timestamp) - self.add_sample(hs) + hash = { + :timestamp => timestamp, + :last_poll => host['LAST_MON_TIME'], + :state => host['STATE'], + } + + host_share = host['HOST_SHARE'] + HOST_SAMPLE.each { |key,value| + hash[key] = host_share[value[:path]] + } + + self.add_sample(hash) end private From b781f1095187ec6e365b0940f7231e4d6887343b Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 8 Jul 2011 12:57:29 +0200 Subject: [PATCH 17/26] feature #696: Fix Sunstone bugs and delete old monitoring samples --- src/acct/monitoring.rb | 20 +++++++++++---- src/acct/watch_client.rb | 10 +++++--- src/acct/watch_helper.rb | 37 +++++++++++++++++++++++---- src/sunstone/models/SunstoneServer.rb | 9 +++++-- src/sunstone/sunstone-server.rb | 7 ++--- 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/acct/monitoring.rb b/src/acct/monitoring.rb index c9637318ad..14bc5959b8 100644 --- a/src/acct/monitoring.rb +++ b/src/acct/monitoring.rb @@ -11,6 +11,8 @@ module OneWatch sql.add_sample_from_resource(elem, timestamp) } end + + sql_elem.flush end private @@ -25,8 +27,12 @@ module OneWatch 'VM' end - def sql_elem(elem) - WatchHelper::Vm.info(elem) + def sql_elem(elem=nil) + if elem + WatchHelper::Vm.info(elem) + else + WatchHelper::Vm + end end end @@ -35,8 +41,12 @@ module OneWatch 'HOST' end - def sql_elem(elem) - WatchHelper::Host.info(elem) + def sql_elem(elem=nil) + if elem + WatchHelper::Host.info(elem) + else + WatchHelper::Host + end end end -end \ No newline at end of file +end diff --git a/src/acct/watch_client.rb b/src/acct/watch_client.rb index aea2d0c34a..5710b83a98 100644 --- a/src/acct/watch_client.rb +++ b/src/acct/watch_client.rb @@ -77,7 +77,9 @@ module OneWatchClient "GROUP BY #{kind.downcase}_id, last_poll) " << "GROUP BY last_poll;" ) do |row| - a << [row[:last_poll], row["sum_#{mr}"]] + if row[:last_poll] && row[:last_poll] != 0 + a << [row[:last_poll], row["sum_#{mr}"].to_i] + end end a @@ -109,13 +111,15 @@ module OneWatchClient if allowed_sample.has_key?(mr.to_sym) mon[mr] = Array.new else - opts.remove(opt) + monitoring_resources.delete(mr) end } rsql.samples_dataset.map { |sample| monitoring_resources.each { |mr| - mon[mr] << [sample.last_poll, sample.send(mr.to_sym)] + if sample.last_poll && sample.last_poll != 0 + mon[mr] << [sample.last_poll, sample.send(mr.to_sym)] + end } } diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index 5021dec06a..e70a34b733 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -54,7 +54,7 @@ module WatchHelper :type => Integer, :path => 'MAX_MEM' }, - :mem_cpu => { + :max_cpu => { :type => Integer, :path => 'MAX_CPU' }, @@ -185,7 +185,7 @@ module WatchHelper many_to_one :host def self.active - self.filter(:state<3) + self.filter('state < 3') end def self.error @@ -229,7 +229,9 @@ module WatchHelper # Monitoring one_to_many :samples, :before_add=>:control_regs, :order=>:timestamp, :class=>VmSample + one_to_many :samples, :order=>:timestamp, :class=>VmSample + @@samples_cache = [] def self.info(vm) Vm.find_or_create(:id=>vm['ID']) { |v| v.name = vm['NAME'] @@ -270,13 +272,23 @@ module WatchHelper hash[key] = vm[value[:path]] } - self.add_sample(hash) + @@samples_cache << hash end def add_delta_from_resource(vm, timestamp) self.deltas vs = VmSample.create_from_vm(vm, timestamp) self.add_sample(vs) + def self.flush + VmSample.multi_insert(@@samples_cache) + + Vm.each { |vm| + if vm.samples.count > CONF[:WINDOW_SIZE] -1 + vm.samples.last.delete + end + } + + @@samples_cache = [] end private @@ -292,7 +304,9 @@ module WatchHelper unrestrict_primary_key # Monitoring - one_to_many :samples, :before_add=>:control_regs, :order=>:timestamp, :class=>HostSample + one_to_many :samples, :order=>:timestamp, :class=>HostSample + + @@samples_cache = [] def self.info(host) Host.find_or_create(:id=>host['ID']) { |h| @@ -303,8 +317,21 @@ module WatchHelper } end + def self.flush + HostSample.multi_insert(@@samples_cache) + + Host.each { |host| + if host.samples.count > CONF[:WINDOW_SIZE] -1 + host.samples.last.delete + end + } + + @@samples_cache = [] + end + def add_sample_from_resource(host, timestamp) hash = { + :host_id => host['ID'], :timestamp => timestamp, :last_poll => host['LAST_MON_TIME'], :state => host['STATE'], @@ -315,7 +342,7 @@ module WatchHelper hash[key] = host_share[value[:path]] } - self.add_sample(hash) + @@samples_cache << hash end private diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index 99b3d5c147..4d4f81ce9f 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -280,9 +280,9 @@ class SunstoneServer # ############################################################################ - def get_monitoring(id, resource, monitoring_resources) + def get_monitoring(id, resource, monitor_resources) watch_client = OneWatchClient::WatchClient.new - columns = params['monitor_resources'].split(',') + columns = monitor_resources.split(',') rc = case resource when "vm","VM" @@ -301,6 +301,11 @@ class SunstoneServer return [200, nil] end + if rc.nil? + error = Error.new("There is no monitoring information for #{resource} #{id}") + return [500, error.to_json] + end + return [200, rc.to_json] end diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 9207e677e4..0149b7c142 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -168,16 +168,17 @@ end get '/:resource/monitor' do @SunstoneServer.get_monitoring( - params[:id], + nil, params[:resource], - params[:monitoring_resources] + params[:monitor_resources] ) end get '/:resource/:id/monitor' do @SunstoneServer.get_monitoring( + params[:id], params[:resource], - params[:monitoring_resources] + params[:monitor_resources] ) end From 98f7badde0d326437563b2cb509b9cfa453ef2b5 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 8 Jul 2011 16:48:29 +0200 Subject: [PATCH 18/26] 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 From 757c7735039ab0c48b238cbf1b2835f69edafd97 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 8 Jul 2011 17:29:07 +0200 Subject: [PATCH 19/26] feature #696: Add VM Deltas support --- src/acct/accounting.rb | 1 + src/acct/test/helper/test_helper.rb | 2 +- src/acct/watch_helper.rb | 96 ++++++++++++++++++----------- 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/src/acct/accounting.rb b/src/acct/accounting.rb index bbc154ebb2..55816ae6a8 100644 --- a/src/acct/accounting.rb +++ b/src/acct/accounting.rb @@ -104,6 +104,7 @@ module OneWatch def insert_vm(vm) vm_sql = WatchHelper::Vm.info(vm) + vm_sql.add_delta_from_resource(vm, @timestamp) update_history(vm, vm_sql) end end diff --git a/src/acct/test/helper/test_helper.rb b/src/acct/test/helper/test_helper.rb index 91a11dc67c..eab69fbf94 100644 --- a/src/acct/test/helper/test_helper.rb +++ b/src/acct/test/helper/test_helper.rb @@ -55,7 +55,7 @@ end def clean_db begin WatchHelper::Register.destroy - WatchHelper::Delta.destroy + WatchHelper::VmDelta.destroy WatchHelper::VmSample.destroy WatchHelper::HostSample.destroy WatchHelper::Vm.destroy diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index e70a34b733..90532fdf73 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -13,6 +13,16 @@ module WatchHelper CONF = YAML.load_file(ACCTD_CONF) DB = Sequel.connect(CONF[:DB]) + VM_DELTA = { + :net_rx => { + :type => Integer, + :path => 'NET_RX' + }, + :net_tx => { + :type => Integer, + :path => 'NET_TX' + } + } VM_SAMPLE = { :cpu => { @@ -152,12 +162,14 @@ module WatchHelper primary_key [:vm_id, :seq] end - DB.create_table? :deltas do + DB.create_table? :vm_deltas do foreign_key :vm_id, :vms, :key=>:id Integer :timestamp Integer :ptimestamp - Integer :net_rx - Integer :net_tx + + VM_DELTA.each { |key,value| + column key, value[:type] + } primary_key [:vm_id, :timestamp] end @@ -214,7 +226,7 @@ module WatchHelper end end - class Delta < Sequel::Model + class VmDelta < Sequel::Model unrestrict_primary_key many_to_one :vm @@ -225,13 +237,14 @@ module WatchHelper # Accounting one_to_many :registers, :order=>:seq - one_to_many :deltas, :order=>:timestamp + one_to_many :deltas, :order=>:timestamp, :class=>VmDelta # Monitoring - one_to_many :samples, :before_add=>:control_regs, :order=>:timestamp, :class=>VmSample one_to_many :samples, :order=>:timestamp, :class=>VmSample @@samples_cache = [] + @@deltas_cache = [] + def self.info(vm) Vm.find_or_create(:id=>vm['ID']) { |v| v.name = vm['NAME'] @@ -262,6 +275,7 @@ module WatchHelper def add_sample_from_resource(vm, timestamp) hash = { + :vm_id => vm['ID'], :timestamp => timestamp, :last_poll => vm['LAST_POLL'], :state => vm['STATE'], @@ -276,27 +290,47 @@ module WatchHelper end def add_delta_from_resource(vm, timestamp) - self.deltas - vs = VmSample.create_from_vm(vm, timestamp) - self.add_sample(vs) + hash = Hash.new + + hash[:vm_id] = vm['ID'] + hash[:timestamp] = timestamp + + if last_delta = self.deltas.first + hash[:ptimestamp] = last_delta.send(:timestamp) + + VM_DELTA.each { |key,value| + old_value = last_delta.send("#{key}".to_sym) + new_value = vm[value[:path]].to_i + + if old_value > new_value + hash[key] = new_value + else + hash[key] = new_value - old_value + end + } + else + hash[:ptimestamp] = 0 + + VM_DELTA.each { |key,value| + hash[key] = vm[value[:path]] + } + end + + @@deltas_cache << hash + end + def self.flush + VmDelta.multi_insert(@@deltas_cache) VmSample.multi_insert(@@samples_cache) Vm.each { |vm| if vm.samples.count > CONF[:WINDOW_SIZE] -1 - vm.samples.last.delete + vm.samples.first.delete end } @@samples_cache = [] - end - - private - - def control_regs(sample) - if self.samples.count > CONF[:WINDOW_SIZE] - 1 - self.samples.first.delete - end + @@deltas_cache = [] end end @@ -317,18 +351,6 @@ module WatchHelper } end - def self.flush - HostSample.multi_insert(@@samples_cache) - - Host.each { |host| - if host.samples.count > CONF[:WINDOW_SIZE] -1 - host.samples.last.delete - end - } - - @@samples_cache = [] - end - def add_sample_from_resource(host, timestamp) hash = { :host_id => host['ID'], @@ -345,12 +367,16 @@ module WatchHelper @@samples_cache << hash end - private + def self.flush + HostSample.multi_insert(@@samples_cache) - def control_regs(sample) - if self.samples.count > CONF[:WINDOW_SIZE] - 1 - self.samples.first.delete - end + Host.all.each { |host| + if host.samples.count > CONF[:WINDOW_SIZE] -1 + host.samples.first.delete + end + } + + @@samples_cache = [] end end end From f5dde30ce83ebcb349e92311762faecbe0eb304c Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 8 Jul 2011 18:30:12 +0200 Subject: [PATCH 20/26] feature #696: Fix monitoring tests --- src/acct/test/helper/mock_client.rb | 6 +++--- src/acct/test/monitoring_spec.rb | 13 ++++++------- src/acct/watch_helper.rb | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/acct/test/helper/mock_client.rb b/src/acct/test/helper/mock_client.rb index 87086ed8da..1f04f5c098 100644 --- a/src/acct/test/helper/mock_client.rb +++ b/src/acct/test/helper/mock_client.rb @@ -36,9 +36,9 @@ class MockClient def add_vm(id, values) if values[:state] == 6 - @done_vms[id] = values - elsif - @vms[id] = values + @done_vms[id] = values.clone + else + @vms[id] = values.clone end end diff --git a/src/acct/test/monitoring_spec.rb b/src/acct/test/monitoring_spec.rb index 34e7d76915..f3f7272a17 100644 --- a/src/acct/test/monitoring_spec.rb +++ b/src/acct/test/monitoring_spec.rb @@ -88,16 +88,15 @@ describe "1 Vm 1 10 steps" do ] } - @mock_client.add_vm(1, values) - @mock_client.add_vm(2, values) + values[:state] = 7 + @mock_client.add_vm(i+100, values) + values[:state] = 3 + @mock_client.add_vm(i+10, values) @monitoring.insert(create_vmpool_hash) - #@db[:vms].count.should eql(1) - #@db[:vm_samples].count.should eql(1+i > 5 ? 5 : 1+i) - #pp @watch_client.vm_monitoring(1, ['cpu', 'net_tx']) - # "total" - pp @watch_client.vm_total('total') + @db[:vm_samples].count + total = @watch_client.vm_total([:total, :error, :active]) } end end \ No newline at end of file diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index 90532fdf73..367e7211bf 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -324,7 +324,7 @@ module WatchHelper VmSample.multi_insert(@@samples_cache) Vm.each { |vm| - if vm.samples.count > CONF[:WINDOW_SIZE] -1 + if vm.samples.count > CONF[:WINDOW_SIZE] vm.samples.first.delete end } @@ -371,7 +371,7 @@ module WatchHelper HostSample.multi_insert(@@samples_cache) Host.all.each { |host| - if host.samples.count > CONF[:WINDOW_SIZE] -1 + if host.samples.count > CONF[:WINDOW_SIZE] host.samples.first.delete end } From f6493e1f2bd736d897ea59c5605e1472c063f8a0 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 8 Jul 2011 18:57:55 +0200 Subject: [PATCH 21/26] feature #696: Add flush method for accounting --- src/acct/accounting.rb | 2 ++ src/acct/etc/acctd.conf | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/acct/accounting.rb b/src/acct/accounting.rb index 55816ae6a8..1fd0c6b8ac 100644 --- a/src/acct/accounting.rb +++ b/src/acct/accounting.rb @@ -55,6 +55,8 @@ module OneWatch # Upate the active VMs @active_vms = new_active_vms.sort + + WatchHelper::Vm.flush end private diff --git a/src/acct/etc/acctd.conf b/src/acct/etc/acctd.conf index 50f0f56582..7b4e099817 100644 --- a/src/acct/etc/acctd.conf +++ b/src/acct/etc/acctd.conf @@ -30,7 +30,7 @@ :STEPS: 1 # Number of VM records to preserve - :WINDOW_SIZE: 100 + :WINDOW_SIZE: 5 #------------------------------------------------------------------------------- # HOST Monitoring @@ -42,7 +42,7 @@ :STEPS: 3 # Number of HOST records to preserve - :WINDOW_SIZE: 100 + :WINDOW_SIZE: 5 #------------------------------------------------------------------------------- # Accounting From 1d4df9ef55af776224bcb60027be8e3831357873 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 8 Jul 2011 16:27:25 +0200 Subject: [PATCH 22/26] Feature #696: Sunstone client side update to support new graphic data format --- src/sunstone/models/SunstoneServer.rb | 3 +- .../public/js/plugins/dashboard-tab.js | 17 +++++---- src/sunstone/public/js/sunstone-util.js | 36 ++++++++++++++----- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index 4d4f81ce9f..835c5d8779 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -298,7 +298,8 @@ class SunstoneServer watch_client.host_total(columns) end else - return [200, nil] + error = Error.new("Monitoring not supported for this resource: #{resource}") + return [200, error.to_json] end if rc.nil? diff --git a/src/sunstone/public/js/plugins/dashboard-tab.js b/src/sunstone/public/js/plugins/dashboard-tab.js index ac5b375c36..623fb3a18b 100644 --- a/src/sunstone/public/js/plugins/dashboard-tab.js +++ b/src/sunstone/public/js/plugins/dashboard-tab.js @@ -168,30 +168,33 @@ Sunstone.addMainTab('dashboard_tab',dashboard_tab); function plot_global_graph(data,info){ var id = info.title; - var labels_arr = info.monitor_resources.split(','); + var monitoring = data.monitoring; var serie; var series = []; var width = ($(window).width()-129)*45/100; + var mon_count = 0; $('#'+id).html('
'); - for (var i = 0; i< labels_arr.length; i++) { + for (var label in monitoring) { serie = { - label: labels_arr[i], - data: data[i] + label: label, + data: monitoring[label] }; series.push(serie); + mon_count++; }; var options = { legend : { show : true, - noColumns: labels_arr.length, + noColumns: mon_count, container: $('#'+id+'_legend') }, xaxis : { - mode: "time", - timeformat: "%h:%M" + tickFormatter: function(val,axis){ + return pretty_time_axis(val); + }, }, yaxis : { labelWidth: 40 } } diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 8c43b26883..37087f89f4 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -46,6 +46,20 @@ function pretty_time(time_seconds) return hour + ":" + mins +":" + secs + " " + month + "/" + day + "/" + year; } +function pretty_time_axis(time){ + var d = new Date(); + d.setTime(time*1000); + + var secs = pad(d.getSeconds(),2); + var hour = pad(d.getHours(),2); + var mins = pad(d.getMinutes(),2); + var day = pad(d.getDate(),2); + var month = pad(d.getMonth()+1,2); //getMonths returns 0-11 + var year = d.getFullYear(); + + return hour + ":" + mins + ":" + secs;// + " " + month + "/" + day; +} + //returns a human readable size in Kilo, Mega, Giga or Tera bytes function humanize_size(value) { if (typeof(value) === "undefined") { @@ -512,27 +526,31 @@ function plot_graph(data,context,id_prefix,info){ var labels = info.monitor_resources; var humanize = info.humanize_figures ? humanize_size : function(val){ return val }; - var labels_arr = labels.split(','); var id_suffix = labels.replace(/,/g,'_'); + var monitoring = data.monitoring var series = []; - var serie = null; + var serie; + var mon_count = 0; - for (var i = 0; i< labels_arr.length; i++) { + for (var label in monitoring) { serie = { - label: labels_arr[i], - data: data[i] + label: label, + data: monitoring[label] }; series.push(serie); + mon_count++; }; var options = { legend : { show : true, - noColumns: labels_arr.length, + noColumns: mon_count++, container: $('#legend_'+id_suffix) }, - xaxis : { mode: "time", - timeformat: "%h:%M" - }, + xaxis : { + tickFormatter: function(val,axis){ + return pretty_time_axis(val); + }, + }, yaxis : { labelWidth: 40, tickFormatter: function(val, axis) { return humanize(val); From d2a11a7be2b4d232ce8b3d3fb9bd993502ea2fab Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 8 Jul 2011 19:04:55 +0200 Subject: [PATCH 23/26] feature #696: Fix typo --- src/acct/watch_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index 60ca866411..93ab3d56d3 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -346,7 +346,6 @@ module WatchHelper @@samples_cache = [] @@deltas_cache = [] end - end end class Host < Sequel::Model From 3f124aa53710ff10bf2ada32569a7e37b2a363c3 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 8 Jul 2011 19:13:40 +0200 Subject: [PATCH 24/26] feature #696: Fix timestamp value for tests --- src/acct/etc/acctd.conf | 40 +++++++++------------------------------- src/acct/test/1Vm1His.rb | 6 +++--- src/acct/test/1VmXHis.rb | 2 +- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/acct/etc/acctd.conf b/src/acct/etc/acctd.conf index 7b4e099817..c1c968a084 100644 --- a/src/acct/etc/acctd.conf +++ b/src/acct/etc/acctd.conf @@ -18,38 +18,16 @@ :DB: sqlite:///tmp/test_one_acct.db # Duration of each daemon loop in seconds -:STEP: 300 # 5 minutes +:STEP: 2 -#------------------------------------------------------------------------------- -# VM Monitoring -#------------------------------------------------------------------------------- +# 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 - # Number of daemon loops until a VM monitoring watch - :STEPS: 1 - - # Number of VM records to preserve - :WINDOW_SIZE: 5 - -#------------------------------------------------------------------------------- -# HOST Monitoring -#------------------------------------------------------------------------------- - -:HOST_MONITORING: - - # Number of daemon loops until a Hosts monitoring watch - :STEPS: 3 - - # Number of HOST records to preserve - :WINDOW_SIZE: 5 - -#------------------------------------------------------------------------------- -# Accounting -#------------------------------------------------------------------------------- - -:ACCOUNTING: - - # Number of daemon loops until an accounting watch - :STEPS: 10 +# Number of daemon loops until a Hosts monitoring watch +:HOST_MONITORING_STEPS: 1 +# Number of records to preserve +:WINDOW_SIZE: 10 diff --git a/src/acct/test/1Vm1His.rb b/src/acct/test/1Vm1His.rb index 0eb0284875..0dad640a1c 100644 --- a/src/acct/test/1Vm1His.rb +++ b/src/acct/test/1Vm1His.rb @@ -75,7 +75,7 @@ describe "1 Vm 1 History" do @watch_client.running_time(ts1, ts2).to_i.should eql(0) ts3 = 300 - @accounting.set_mock_timestamp(ts2) + @accounting.set_mock_timestamp(ts3) values = { :uid => 2, @@ -181,7 +181,7 @@ describe "1 Vm 1 History" do @watch_client.prolog_time(ts1, ts2).to_i.should eql(5) ts3 = 300 - @accounting.set_mock_timestamp(ts2) + @accounting.set_mock_timestamp(ts3) values = { :uid => 2, @@ -287,7 +287,7 @@ describe "1 Vm 1 History" do @watch_client.prolog_time(ts1, ts2).to_i.should eql(5) ts3 = 300 - @accounting.set_mock_timestamp(ts2) + @accounting.set_mock_timestamp(ts3) values = { :uid => 2, diff --git a/src/acct/test/1VmXHis.rb b/src/acct/test/1VmXHis.rb index 76c8855bc5..d0a94a0840 100644 --- a/src/acct/test/1VmXHis.rb +++ b/src/acct/test/1VmXHis.rb @@ -51,7 +51,7 @@ describe "1 Vm X History" do @watch_client.running_time(ts1, ts2).to_i.should eql(sum) ts3 = 300 - @accounting.set_mock_timestamp(ts2) + @accounting.set_mock_timestamp(ts3) values = { :uid => 2, From f046695c03072e3eb5ecbd8cca4fa9e603251ece Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 8 Jul 2011 19:15:16 +0200 Subject: [PATCH 25/26] feature #696: Fix vm window size --- src/acct/watch_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index 93ab3d56d3..4cc5ab9c98 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -338,7 +338,7 @@ module WatchHelper VmSample.multi_insert(@@samples_cache) Vm.each { |vm| - if vm.samples.count > @@vm_window_size -1 + if vm.samples.count > @@vm_window_size vm.samples.last.delete end } From 03df3f22c5365a2b3267e80d161b6d1b176bc1e2 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 8 Jul 2011 19:16:50 +0200 Subject: [PATCH 26/26] feature #696: Change acctd.conf --- src/acct/etc/acctd.conf | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/acct/etc/acctd.conf b/src/acct/etc/acctd.conf index c1c968a084..7b4e099817 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: 5 + +#------------------------------------------------------------------------------- +# HOST Monitoring +#------------------------------------------------------------------------------- + +:HOST_MONITORING: + + # Number of daemon loops until a Hosts monitoring watch + :STEPS: 3 + + # Number of HOST records to preserve + :WINDOW_SIZE: 5 + +#------------------------------------------------------------------------------- +# Accounting +#------------------------------------------------------------------------------- + +:ACCOUNTING: + + # Number of daemon loops until an accounting watch + :STEPS: 10 -# Number of records to preserve -:WINDOW_SIZE: 10