From 79a562b2595497a0f1f457aeaa7e6f0041101e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez?= Date: Mon, 20 Apr 2020 10:46:36 +0200 Subject: [PATCH] M #: Remove virsh monitoring dependency (#4558) --- src/im_mad/remotes/lib/linux.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/im_mad/remotes/lib/linux.rb b/src/im_mad/remotes/lib/linux.rb index 98cecb7d25..36dc637bb5 100644 --- a/src/im_mad/remotes/lib/linux.rb +++ b/src/im_mad/remotes/lib/linux.rb @@ -24,7 +24,8 @@ class LinuxHost ENV['LANG'] = 'C' ENV['LC_ALL'] = 'C' - NODEINFO = 'virsh -c qemu:///system nodeinfo' + CPUINFO = 'lscpu | grep CPU' + MEMINFO = 'cat /proc/meminfo | grep MemTotal' ###### # First, get all the posible info out of virsh @@ -34,7 +35,7 @@ class LinuxHost attr_accessor :cpu, :memory, :net def initialize - nodeinfo = `#{NODEINFO}` + cpuinfo = `#{CPUINFO}` exit(-1) if $CHILD_STATUS.exitstatus != 0 @@ -42,15 +43,16 @@ class LinuxHost @memory = {} @net = {} - nodeinfo.split(/\n/).each {|line| - if line =~ /^CPU\(s\)/ - @cpu[:total] = line.split(':')[1].strip.to_i * 100 - elsif line =~ /^CPU frequency/ - @cpu[:speed] = line.split(':')[1].strip.split(' ')[0] - elsif line =~ /^Memory size/ - @memory[:total] = line.split(':')[1].strip.split(' ')[0] + cpuinfo.split(/\n/).each do |line| + if line =~ /^CPU\(s\)/ + @cpu[:total] = line.split(':')[1].strip.to_i * 100 + elsif line =~ /^CPU MHz:/ + @cpu[:speed] = Float(line.split(':')[1].strip.split(' ')[0]).round end - } + end + + meminfo = `#{MEMINFO}` + @memory[:total] = meminfo.split(':')[1].strip.split(' ')[0] ###### # CPU