Skip to content

There is any way i can add memory monitor of guest vm #245

@alshba7

Description

@alshba7

There is any way i can add memory monitor of guest vm

my code for example

#!/usr/bin/env python

import libvirt
from libvirt import libvirtError
import time

def request_cred(credentials, user_data):
for credential in credentials:
if credential[0] == libvirt.VIR_CRED_AUTHNAME:
credential[4] = 'test'
elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
credential[4] = 'dddddddd'
return 0

auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], request_cred, None]
conn = libvirt.openAuth('qemu+{0}://{1}/system'.format('tcp','127.0.0.1'), auth, 0)
#conn = libvirt.open(optional_params['conn'])
guest = 'guest'
vm = conn.lookupByName(guest)
""" test with running vm """
memstats = vm.memoryStats()
percent = memstats['rss'] / memstats['actual'] * 100
pcentCurrMem = max(100.0,min(percent, 0.0))
print(percent)
print(int( float(int(memstats['rss'])) / float(int(memstats['actual'])) * 100 ))
time.sleep(1)
vm.setMemoryStatsPeriod(5, libvirt.VIR_DOMAIN_AFFECT_LIVE)
memstats = vm.memoryStats()
print(int( float(int(memstats['rss'])) / float(int(memstats['actual'])) * 100 ))

But the usage of memory the same 99% or 101%
how can i solve this problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions