From 944f9ab7cf6fdb9da3e477a9a49fff2fc7db2149 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 24 Mar 2020 13:24:22 +0100 Subject: [PATCH] L #-: Monitor probes --- src/im_mad/remotes/common.d/monitord-client.rb | 10 ++++++++-- .../remotes/dummy-probes.d/vm/monitor/monitor.rb | 14 +++++++------- src/im_mad/remotes/lxd-probes.d/vm/status/state.rb | 1 + src/im_mad/remotes/node-probes.d/numa_host.rb | 2 +- src/im_mad/remotes/node-probes.d/numa_usage.rb | 3 +++ src/vmm_mad/remotes/lib/firecracker/microvm.rb | 4 ++-- src/vmm_mad/remotes/vcenter/deploy | 9 +++++++-- 7 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/im_mad/remotes/common.d/monitord-client.rb b/src/im_mad/remotes/common.d/monitord-client.rb index adfecd881d..57f4c47e19 100644 --- a/src/im_mad/remotes/common.d/monitord-client.rb +++ b/src/im_mad/remotes/common.d/monitord-client.rb @@ -125,6 +125,8 @@ class ProbeRunner # @return[Array] rc, data. rc 0 for success and data is the output of # probes. If rc is -1 it signal failure and data is the error message of # the failing probe + # + # rubocop:disable Lint/SuppressedException def run_probes data = '' dpro = Dir.new(@path) @@ -167,6 +169,7 @@ class ProbeRunner [0, data] end + # rubocop:enable Lint/SuppressedException # Singleton call for run_probes method def self.run_once(hyperv, path, stdin) @@ -301,11 +304,14 @@ threads = [] probes.each do |msg_type, conf| threads << Thread.new do - ProbeRunner.monitor_loop(hyperv, conf[:path], conf[:period], xml_txt) do |rc, da| + ProbeRunner.monitor_loop(hyperv, + conf[:path], + conf[:period], + xml_txt) do |result, da| da.strip! next if da.empty? - client.send(msg_type, rc == 0, da) + client.send(msg_type, result == 0, da) end end end diff --git a/src/im_mad/remotes/dummy-probes.d/vm/monitor/monitor.rb b/src/im_mad/remotes/dummy-probes.d/vm/monitor/monitor.rb index a338997108..65fd23e07b 100755 --- a/src/im_mad/remotes/dummy-probes.d/vm/monitor/monitor.rb +++ b/src/im_mad/remotes/dummy-probes.d/vm/monitor/monitor.rb @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # # limitations under the License. # # -------------------------------------------------------------------------- # - +# rubocop:disable Layout/ArgumentAlignment ONE_LOCATION = ENV['ONE_LOCATION'] if !ONE_LOCATION @@ -42,12 +42,12 @@ def unindent(s) end hid = ARGV[1] -hname = ARGV[2] +_hname = ARGV[2] client = OpenNebula::Client.new vmpool = OpenNebula::VirtualMachinePool.new(client, - OpenNebula::VirtualMachinePool::INFO_ALL_VM) + OpenNebula::VirtualMachinePool::INFO_ALL_VM) rc = vmpool.info @@ -71,10 +71,10 @@ vmpool.each do |vm| base_net = Time.now.to_i % 10000 mon_s = unindent(<<-EOS) - NETTX=#{base_net+(50*rand(3))} - NETRX=#{base_net+(100*rand(4))} - MEMORY=#{max_memory * (rand(80)+20)/100} - CPU=#{max_cpu * (rand(95)+5)/100} + NETTX=#{base_net + (50 * rand(3))} + NETRX=#{base_net + (100 * rand(4))} + MEMORY=#{max_memory * rand(20..100)/100} + CPU=#{max_cpu * rand(5..100)/100} DISKRDBYTES=#{rand(1000)} DISKWRBYTES=#{rand(1000)} DISKRDIOPS=#{rand(1000)} diff --git a/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb b/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb index 7acac3f88c..c66216f9cf 100755 --- a/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb +++ b/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb @@ -9,6 +9,7 @@ require_relative '../../../lib/lxd' # This module implements the functions needed by probe_db.rb # ----------------------------------------------------------- module DomainList + # LXD to OpenNebula state mapping STATE_MAP = { 'RUNNING' => 'RUNNING', diff --git a/src/im_mad/remotes/node-probes.d/numa_host.rb b/src/im_mad/remotes/node-probes.d/numa_host.rb index 4e890727f7..309ffb46f0 100755 --- a/src/im_mad/remotes/node-probes.d/numa_host.rb +++ b/src/im_mad/remotes/node-probes.d/numa_host.rb @@ -78,7 +78,7 @@ module NUMA core_id = File.read("#{core_path}/core_id").chomp - nodes[node_id]['cores'] << { 'id' => core_id, 'cpus' => siblings } + nodes[node_id]['cores'] << {'id' => core_id, 'cpus' => siblings} rescue StandardError next end diff --git a/src/im_mad/remotes/node-probes.d/numa_usage.rb b/src/im_mad/remotes/node-probes.d/numa_usage.rb index aeceb8da51..6fd21ca168 100755 --- a/src/im_mad/remotes/node-probes.d/numa_usage.rb +++ b/src/im_mad/remotes/node-probes.d/numa_usage.rb @@ -18,6 +18,9 @@ require_relative '../../../lib/numa_common' +# +# Module for monitoring host NUMA information +# module NUMA def self.node_to_template(node, nid) diff --git a/src/vmm_mad/remotes/lib/firecracker/microvm.rb b/src/vmm_mad/remotes/lib/firecracker/microvm.rb index 4bda5c379c..6f68cdd516 100644 --- a/src/vmm_mad/remotes/lib/firecracker/microvm.rb +++ b/src/vmm_mad/remotes/lib/firecracker/microvm.rb @@ -101,9 +101,9 @@ class MicroVM end def get_pid - rc, stdout, = Command.execute("ps auxwww | grep " \ + rc, stdout, = Command.execute('ps auxwww | grep ' \ "\"^.*firecracker.*--id['\\\"=[[:space:]]]*#{@one.vm_name}\" " \ - "| grep -v grep", false) + '| grep -v grep', false) if !rc.zero? || stdout.nil? return -1 diff --git a/src/vmm_mad/remotes/vcenter/deploy b/src/vmm_mad/remotes/vcenter/deploy index f19aaac376..bbdf8eafbf 100755 --- a/src/vmm_mad/remotes/vcenter/deploy +++ b/src/vmm_mad/remotes/vcenter/deploy @@ -66,10 +66,15 @@ begin drv_action, vm_id) if vm.instantiated_as_persistent? + oclient = OpenNebula::Client.new + template_id = vm.one_item['TEMPLATE/TEMPLATE_ID'] - vm_template = OpenNebula::Template.new_with_id(template_id, OpenNebula::Client.new) - rc = vm_template.info() + vm_template = OpenNebula::Template.new_with_id(template_id, oclient) + + rc = vm_template.info + raise if OpenNebula.is_error?(rc) + vm_template.lock(1) end end