O'Reilly logo

KVM Virtualization Cookbook by Konstantin Ivanov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To collect CPU, memory, and state information about a running instance, use the following Python methods:

  1. Get the name of the instance:
In [1]: instance.name()Out[1]: 'kvm_python'In [2]:
  1. Ensure the instance is running:
In [2]: instance.isActive()Out[2]: 1In [3]:
  1. Collect resource statistics on the KVM instance:
In [3]: instance.info()Out[3]: [1, 1048576L, 1048576L, 1, 10910000000L]In [4]:
  1. Retrieve the maximum amount of physical memory allocated to the instance:
In [4]: instance.maxMemory()Out[4]: 1048576LIn [5]:
  1. Extract CPU statistics for the instance:
In [5]: instance.getCPUStats(1)Out[5]:[{'cpu_time': 10911545901L, 'system_time': 1760000000L, 'user_time': 1560000000L}]In [6]:
  1. Check if the virtual machine ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required