Product SiteDocumentation Site

3.4.19. getCPUStats

Get the stats for on or all CPUs.
This method requires a single argument that represents the CPU number to fetch the statistics for a single CPU, or the value VIR_NODE_CPU_STATS_ALL_CPUS to fetch a Python list of statistics for all CPUs.

Example 3.30. Using getCPUStats

# Example-30.py
#!/usr/bin/env python3
import sys
import libvirt

conn = None
try:
    conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
    print(repr(e), file=sys.stderr)
    exit(1)

stats = conn.getCPUStats(0)

print("kernel: " + str(stats['kernel']))
print("idle:   " + str(stats['idle']))
print("user:   " + str(stats['user']))
print("iowait: " + str(stats['iowait']))

conn.close()
exit(0)