Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alshba7 opened this issue Jun 22, 2019 · 0 comments
Open

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

alshba7 opened this issue Jun 22, 2019 · 0 comments

Comments

@alshba7
Copy link

alshba7 commented Jun 22, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant