Managing KVM hypervisor and Virtual machines hosted by it are very much easy if you know what they are capable of. In this post we will see how to view different settings, Hardware info etc for both KVM hypervisor and Guest virtual machine details. Below the concepts already covered in this series.

Get KVM Hypervisor details

Example1: Get KVM version installed on the host machine

virsh version

Output:

Compiled against library: libvir 0.9.13
Using library: libvir 0.9.13
Using API: QEMU 0.9.13
Running hypervisor: QEMU 1.2.0

Example2: Get KVM Hypervisor(Host) Memory info

virsh nodememstats

Output:

total : 8027952 KiB
free : 2772452 KiB
buffers: 264476 KiB
cached : 1677176 KiB

Example3: Get KVM Hypervisor CPU info

virsh nodecpustats

Output:

user: 3916550000000
system: 1183160000000
idle: 21003220000000
iowait: 655350000000

Note: The above numbers are in nanoseconds of time available for user/system/idle etc.

If you want we can even get individual CPU, if you have more than 1 CPU. Suppose if we want to get CPU2 details use –cpu 1 for that

virsh nodecpustats –cpu 1

Output:
user: 1131610000000
system: 348770000000
idle: 5141870000000
iowait: 136620000000

How about getting the values in percentage of total CPU available?

virsh nodecpustats –percent

Output:

usage: 20.3%
user: 17.5%
system: 2.8%
idle: 79.7%
iowait: 0.0%

Example4: How to get number of Guest Virtual machines irrespective of state such as running, save, shutdown etc.

virsh list –all

Output:
Id Name State
—————————————————-
1 BaseMachine running
– bt51 shut off
– centos-64 shut off
– Clusterbase shut off
– mint1 shut off
– node.linuxnix.com shut off
– node1.linuxnix.com shut off
– node2.linuxnix.com shut off

To get only running machines in KVM hypervisor

virsh list

Output:
Id Name State
—————————————————-
1 BaseMachine running

Example5: To get all the networks available for KVM hypervisor

virsh net-list

Output:
Name State Autostart
—————————————–
default active yes
net1 active yes
net2 active yes
NewNAT active yes

To get info of particular network use below command

virsh net-info default

Output:
Name default
UUID 456a45cf-dac8-17b2-c736-e7cf287283cc
Active: yes
Persistent: yes
Autostart: yes
Bridge: virbr0

Get KVM Guest machine details

Example6: Get Hardware information of a KVM guest machine

virsh dominfo BaseMachine

Output:
Id: 1
Name: BaseMachine
UUID: 78c48a29-7c2c-4b84-8968-198f8ed17db2
OS Type: hvm
State: running
CPU(s): 1
CPU time: 32.4s
Max memory: 1048576 KiB
Used memory: 1048576 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: apparmor
Security DOI: 0
Security label: libvirt-78c48a29-7c2c-4b84-8968-198f8ed17db2 (enforcing)

Example7: Get guest machine CPU details like how many vCPU’s etc.

virsh vcpucount centos-64

Output:
maximum config 2
maximum live 2
current config 2
current live 2

Example8: Get guest machine RAM details

virsh dommemstat centos-64

Output:

actual 3223552
rss 1009044

Note: The above numbers in KB, so I assigned 3GB of RAM to this machine.

Example9: List all networks available for a VM

virsh domiflist centos-64

Output:

Interface Type Source Model MAC
——————————————————-
vnet1 network default virtio 52:54:00:cf:99:0c

In our next post we will see on how to edit VM vCPU’s and RAM.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.