From 92d1ff6b11b3adf0c3d7e98e57ce2555c077e694 Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Tue, 23 Oct 2018 12:23:05 +0200 Subject: [PATCH] B #2179 Report RSS + swap usage for KVM VMs _max_memory_ is always equal to Available because: 1. the memballoon is not used for resizing VM memory 2. the memballoon stats reporting is not enabled by default: ``` ``` --- src/vmm_mad/remotes/kvm/poll | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/vmm_mad/remotes/kvm/poll b/src/vmm_mad/remotes/kvm/poll index 16cf18fab0..1e3de34db0 100755 --- a/src/vmm_mad/remotes/kvm/poll +++ b/src/vmm_mad/remotes/kvm/poll @@ -80,13 +80,13 @@ module KVM cpu = get_cpu_info({one_vm => vm}) resident_mem = psinfo[5].to_i - max_mem = dominfo['Max memory'].split(/\s+/).first.to_i + swap_mem = get_swap_usage(vm[:pid]).to_i values=Hash.new values[:state] = get_state(dominfo['State'], vm[:reason]) values[:cpu] = cpu[vm[:pid]] if cpu[vm[:pid]] - values[:memory] = [resident_mem, max_mem].max + values[:memory] = resident_mem + swap_mem xml = dump_xml(one_vm) @@ -139,13 +139,13 @@ module KVM dominfo = vm[:dominfo] resident_mem = ps_data[5].to_i - max_mem = dominfo['Max memory'].split(/\s+/).first.to_i + swap_mem = get_swap_usage(vm[:pid]).to_i values = Hash.new values[:state] = get_state(dominfo['State'], vm[:reason]) values[:cpu] = cpu[vm[:pid]] if cpu[vm[:pid]] - values[:memory] = [resident_mem, max_mem].max + values[:memory] = resident_mem + swap_mem xml = dump_xml(name) @@ -243,6 +243,14 @@ module KVM ps.split(/\s+/) end + # Gets the swap allocation of given process + # @param pid [String] process id + # @return [Integer] of swap allocation of given process + def self.get_swap_usage(pid) + swap=`cat /proc/#{pid}/status 2>/dev/null | grep VmSwap` + swap.split()[1] || 0 + end + # Gets the info of a domain by its id # @param the ID of the VM as defined in libvirt # @return [Hash] with the output of virsh dominfo, indexed by name (Id...)