20.12. Retrieving Information about Your Virtual Machine
20.12. Retrieving Information about Your Virtual Machine 20.12.1. Displaying Device Block Statistics By default, the virsh domblkstat command displays the block statistics for the first block device defined for the domain. To view statistics of other block devices, use the virsh domblklist domain command to list all block devices, and then select a specific block device and display it by specifying either the Target or Source name from the virsh domblklist command output after the domain name. Note that not every hypervisor can display every field. To make sure that the output is presented in its most legible form use the --human argument. Example 20.21. How to display block statistics for a guest virtual machine The following example displays the devices that are defined for the guest1 virtual machine, and then lists the block statistics for that device. 20.12.2. Retrieving Network Interface Statistics The virsh domifstat domain interface-device command displays the network interface statistics for the specified device running on a given guest virtual machine. To determine which interface devices are defined for the domain, use the virsh domiflist command and use the output in the Interface column. Example 20.22. How to display networking statistics for a guest virtual machine The following example obtains the networking interface defined for the guest1 virtual machine, and then displays the networking statistics on the obtained interface ( macvtap0 ): 20.12.3. Modifying the Link State of a Guest Virtual Machine's Virtual Interface The virsh domif-setlink domain interface-device state command configures the status of the specified interface device link state as either up or down . To determine which interface devices are defined for the domain, use the virsh domiflist command and use either the Interface or MAC column as the interface device option. By default, virsh domif-setlink changes the link state for the running domain. To modify the domain's persistent configuration use the --config argument. Example 20.23. How to enable a guest virtual machine interface The following example shows determining the interface device of the rhel7 domain, then setting the link as down , and finally as up : 20.12.4. Listing the Link State of a Guest Virtual Machine's Virtual Interface The virsh domif-getlink domain interface-device command retrieves the specified interface device link state. To determine which interface devices are defined for the domain, use the virsh domiflist command and use either the Interface or MAC column as the interface device option. By default, virsh domif-getlink retrieves the link state for the running domain. To retrieve the domain's persistent configuration use the --config option . Example 20.24. How to display the link state of a guest virtual machine's interface The following example shows determining the interface device of the rhel7 domain, then determining its state as up , then changing the state to down , and then verifying the change was successful: 20.12.5. Setting Network Interface Bandwidth Parameters The virsh domiftune domain interface-device command either retrieves or sets the specified domain's interface bandwidth parameters. To determine which interface devices are defined for the domain, use the virsh domiflist command and use either the Interface or MAC column as the interface device option. The following format should be used: The --config , --live , and --current options are described in Section 20.43, "Setting Schedule Parameters" . If the --inbound or the --outbound option is not specified, virsh domiftune queries the specified network interface and displays the bandwidth settings. By specifying --inbound or --outbound , or both, and the average, peak, and burst values, virsh domiftune sets the bandwidth settings. At minimum the average value is required. In order to clear the bandwidth settings, provide 0 (zero). For a description of the average, peak, and burst values, see Section 20.27.6.2, "Attaching interface devices" . Example 20.25. How to set the guest virtual machine network interface parameters The following example sets eth0 parameters for the guest virtual machine named guest1 : # virsh domiftune guest1 eth0 outbound --live 20.12.6. Retrieving Memory Statistics The virsh dommemstat domain [<period in seconds>] [--config] [--live] [--current] command displays the memory statistics for a running guest virtual machine. Using the optional period switch requires a time period in seconds. Setting this option to a value larger than 0 will allow the balloon driver to return additional statistics which will be displayed by running subsequent dommemstat commands. Setting the period option to 0, stops the balloon driver collection but does not clear the statistics already in the balloon driver. You cannot use the --live , --config , or --current options without also setting the period option. If the --live option is specified, only the guest's running statistics will be collected. If the --config option is used, it will collect the statistics for a persistent guest, but only after the boot. If the --current option is used, it will collect the current statistics. Both the --live and --config options may be used but --current is exclusive. If no flag is specified, the guest's state will dictate the behavior of the statistics collection (running or not). Example 20.26. How to collect memory statistics for a running guest virtual machine The following example shows displaying the memory statistics in the rhel7 domain: 20.12.7. Displaying Errors on Block Devices The virsh domblkerror domain command lists all the block devices in the error state and the error detected on each of them. This command is best used after a virsh domstate command reports that a guest virtual machine is paused due to an I/O error. Example 20.27. How to display the block device errors for a virtual machine The following example displays the block device errors for the guest1 virtual machine: # virsh domblkerror guest1 20.12.8. Displaying the Block Device Size The virsh domblkinfo domain command lists the capacity, allocation, and physical block sizes for a specific block device in the virtual machine. Use the virsh domblklist command to list all block devices and then choose to display a specific block device by specifying either the Target or Source name from the virsh domblklist output after the domain name. Example 20.28. How to display the block device size In this example, you list block devices on the rhel7 virtual machine, and then display the block size for each of the devices. 20.12.9. Displaying the Block Devices Associated with a Guest Virtual Machine The virsh domblklist domain [--inactive] [--details] command displays a table of all block devices that are associated with the specified guest virtual machine. If --inactive is specified, the result will show the devices that are to be used at the boot and will not show those that are currently running in use by the running guest virtual machine. If --details is specified, the disk type and device value will be included in the table. The information displayed in this table can be used with other commands that require a block-device to be provided, such as virsh domblkinfo and virsh snapshot-create . The disk Target or Source contexts can also be used when generating the xmlfile context information for the virsh snapshot-create command. Example 20.29. How to display the block devices that are associated with a virtual machine The following example displays details about block devices associated with the rhel7 virtual machine. 20.12.10. Displaying Virtual Interfaces Associated with a Guest Virtual Machine The virsh domblklist domain command displays a table of all the virtual interfaces that are associated with the specified domain. The virsh domiflist command requires the name of the virtual machine (or domain ), and optionally can take the --inactive argument. The latter retrieves the inactive rather than the running configuration, which is retrieved with the default setting. If --inactive is specified, the result shows devices that are to be used at the boot, and does not show devices that are currently in use by the running guest. Virsh commands that require a MAC address of a virtual interface (such as detach-interface , domif-setlink , domif-getlink , domifstat , and domiftune ) accept the output displayed by this command. Example 20.30. How to display the virtual interfaces associated with a guest virtual machine The following example displays the virtual interfaces that are associated with the rhel7 virtual machine, and then displays the network interface statistics for the vnet0 device.
virsh domblklist guest1 Target Source ------------------------------------------------ vda /VirtualMachines/guest1.img hdc - virsh domblkstat guest1 vda --human Device: vda number of read operations: 174670 number of bytes read: 3219440128 number of write operations: 23897 number of bytes written: 164849664 number of flush operations: 11577 total duration of reads (ns): 1005410244506 total duration of writes (ns): 1085306686457 total duration of flushes (ns): 340645193294 virsh domiflist guest1 Interface Type Source Model MAC ------------------------------------------------------- macvtap0 direct em1 rtl8139 12:34:00:0f:8a:4a virsh domifstat guest1 macvtap0 macvtap0 rx_bytes 51120 macvtap0 rx_packets 440 macvtap0 rx_errs 0 macvtap0 rx_drop 0 macvtap0 tx_bytes 231666 macvtap0 tx_packets 520 macvtap0 tx_errs 0 macvtap0 tx_drop 0 virsh domiflist rhel7 Interface Type Source Model MAC ------------------------------------------------------- vnet0 network default virtio 52:54:00:01:1d:d0 virsh domif-setlink rhel7 vnet0 down Device updated successfully virsh domif-setlink rhel7 52:54:00:01:1d:d0 up Device updated successfully virsh domiflist rhel7 Interface Type Source Model MAC ------------------------------------------------------- vnet0 network default virtio 52:54:00:01:1d:d0 virsh domif-getlink rhel7 52:54:00:01:1d:d0 52:54:00:01:1d:d0 up virsh domif-setlink rhel7 vnet0 down Device updated successfully virsh domif-getlink rhel7 vnet0 vnet0 down virsh domiftune domain interface [--inbound] [--outbound] [--config] [--live] [--current] virsh dommemstat rhel7 actual 1048576 swap_in 0 swap_out 0 major_fault 2974 minor_fault 1272454 unused 246020 available 1011248 rss 865172 virsh domblklist rhel7 Target Source ------------------------------------------------ vda /home/vm-images/rhel7-os vdb /home/vm-images/rhel7-data virsh domblkinfo rhel7 vda Capacity: 10737418240 Allocation: 8211980288 Physical: 10737418240 virsh domblkinfo rhel7 /home/vm-images/rhel7-data Capacity: 104857600 Allocation: 104857600 Physical: 104857600 virsh domblklist rhel7 --details Type Device Target Source ------------------------------------------------ file disk vda /home/vm-images/rhel7-os file disk vdb /home/vm-images/rhel7-data virsh domiflist rhel7 Interface Type Source Model MAC ------------------------------------------------------- vnet0 network default virtio 52:54:00:01:1d:d0 virsh domifstat rhel7 vnet0 vnet0 rx_bytes 55308 vnet0 rx_packets 969 vnet0 rx_errs 0 vnet0 rx_drop 0 vnet0 tx_bytes 14341 vnet0 tx_packets 148 vnet0 tx_errs 0 vnet0 tx_drop 0