Finding PID's of Virtual Machine in openstack -
i working on openstack , want monitor virtual machines cpu usage. want find pids through parent (central) openstack instance. used
ps aux | grep
and did receive output. want confirm if correct pid. way can check this?
or other way find pid's of virtual machine?
update. command not work . gives me pid change. not constant. thank you
well libvirt has interfaces this. here's python extracts data datastructures you:
#!/usr/bin/env python # modules import subprocess import traceback import commands import signal import time import sys import re import os import getopt import pprint try: import libvirt except: print "no libvirt detected" sys.exit(0) xml.dom.minidom import parsestring global instances global virt_conn global tick global virt_exist def virtstats(): global virt_exist global virt_conn global instances cpu_stats = [] if virt_exist == true: if virt_conn == none: print 'failed open connection hypervisor' virt_exist = false if virt_exist == true: virt_info = virt_conn.getinfo() x in range(0, virt_info[2]): cpu_stats.append(virt_conn.getcpustats(x,0)) virt_capabilities = virt_conn.getcapabilities() domcpustats = 0 # domcpustats = virdomain::getcpustats() totmem = 0 totvcpu = 0 totcount = 0 vcpu_stats = [] id in virt_conn.listdomainsid(): dom = virt_conn.lookupbyid(id) totvcpu += dom.maxvcpus() vcpu_stats.append(dom.vcpus()) totmem += dom.maxmemory() totcount += 1 dom = parsestring(virt_capabilities) xmltag = dom.getelementsbytagname('model')[0].toxml() xmldata=xmltag.replace('<model>','').replace('</model>','') info in virt_info: print info stat in cpu_stats: print "cpu %s" % stat vstat in vcpu_stats: print "vcpu:\n" pprint.pprint(vstat) print "cpu ( %s ) use - %s vcpus ( %s logical processors )" % (xmldata, totvcpu, virt_info[2]) sys.exit(0) def main(): try: global virt_conn global virt_exist virt_conn = libvirt.openreadonly(none) virt_exist = true except: virt_exist = false print "ok: not compute node" sys.exit(0) virtstats() if __name__ == "__main__": main()
now in terms of usage cpu time.
the vcpu blocks in layout:
1st: vcpu number, starting 0. 2nd: vcpu state. 0: offline 1: running 2: blocked on resource 3rd: cpu time used in nanoseconds 4th: real cpu number
the cpu blocks obvious once realize that's what's goin down in libvirt.
hope helps!
Comments
Post a Comment