diff --git a/src/vmm_mad/remotes/kvm/poll b/src/vmm_mad/remotes/kvm/poll old mode 100755 new mode 100644 index d5196ce9a5..5841e6c781 --- a/src/vmm_mad/remotes/kvm/poll +++ b/src/vmm_mad/remotes/kvm/poll @@ -81,13 +81,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) @@ -100,7 +100,6 @@ module KVM # # @return [Hash, nil] Hash with the VM information or nil in case of error def self.get_all_vm_info - t1=Time.now vms_info = Hash.new vms = Hash.new @@ -130,8 +129,6 @@ module KVM info[:pid] = psinfo[1] info[:reason] = dom_state_reason(vm) - #info = {:dominfo=>{"Id"=>"81", "Name"=>"one-80", "UUID"=>"9044e7ac-2c36-4e89-a48c-a7e9a561cf2a", "OS Type"=>"hvm", "State"=>"running", "CPU(s)"=>"1", "CPU time"=>"9.2s", "Max memory"=>"65536 KiB", "Used memory"=>"65536 KiB", "Persistent"=>"no", "Autostart"=>"disable", "Managed save"=>"no", "Security model"=>"none", "Security DOI"=>"0"}, :psinfo=>["oneadmin", "23667", "0.0", "0.4", "1096504", "144740", "?", "Sl", "Nov27", "0:09", "/usr/bin/qemu-system-x86_64", "-name", "guest=one-80,debug-threads=on", "-S", "-object", "secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-81-one-80/master-key.aes", "-machine", "pc-i440fx-bionic,accel=kvm,usb=off,dump-guest-core=off", "-m", "64", "-realtime", "mlock=off", "-smp", "1,sockets=1,cores=1,threads=1", "-uuid", "9044e7ac-2c36-4e89-a48c-a7e9a561cf2a", "-no-user-config", "-nodefaults", "-chardev", "socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-81-one-80/monitor.sock,server,nowait", "-mon", "chardev=charmonitor,id=monitor,mode=control", "-rtc", "base=utc", "-no-shutdown", "-boot", "strict=on", "-device", "piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2", "-drive", "file=/var/lib/one//datastores/0/80/disk.0,format=qcow2,if=none,id=drive-virtio-disk0,cache=none", "-device", "virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1", "-drive", "file=/var/lib/one//datastores/0/80/disk.1,format=raw,if=none,id=drive-ide0-0-0,readonly=on", "-device", "ide-cd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0", "-vnc", "0.0.0.0:80", "-device", "cirrus-vga,id=video0,bus=pci.0,addr=0x2", "-device", "virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4", "-msg", "timestamp=on"], :name=>"one-80", :pid=>"23667", :reason=>"booted"} - vms[vm]=info end end @@ -143,13 +140,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) @@ -246,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...) @@ -359,7 +364,6 @@ module KVM def self.get_diskio_statistics(vmid, text = nil) disks=get_disk_names(vmid, text) - puts "disk = #{disks}" if disks && !disks.empty? values={} @@ -416,8 +420,6 @@ module KVM values end - - # Translate libvirt state to Opennebula monitor state # @param state [String] libvirt state # @return [String] OpenNebula state