Setting Up Virtual Host Metrics Daemon on SUSE Linux Micro
- WHAT?
vhostmdis a tool that collects metrics from a virtual machine host and can provide these metrics to the virtual machines running on that host.- WHY?
The article describes how to install and configure
vhostmdto enable collecting metrics.- EFFORT
It takes approximately 15 minutes to read the article.
- GOAL
You will have the
vhostmdtool running and collecting metrics.- REQUIREMENTS
a running instance of SUSE Linux Micro
virtual machines running on that instance
1 What is a virtual host metrics daemon aka vhostmd? #
vhostmd is a daemon that runs in a host environment and provides a metrics
communication channel between the host and guest machines. The daemon provides the guest
machine administrator with a limited set of host resource usage data (usually in read-only mode),
to help analyze issues with the guest machine.
vhostdmd periodically writes metrics to a disk. The metrics to be
collected, along with the
frequency and storage location of the data, are configurable parameters.
2 Getting vhostmd #
By default, vhostmd is not included in the delivered
images. Therefore, you must install it before using it:
Install the daemon by running:
>sudotransactional-update pkg install vhostmdReboot your system to switch to the new snapshot.
Start the daemon by running:
>sudovhostmdOPTIONSYou can use the following options to modify the command behavior:
-v— for a verbose output--connect URI—to pass the URI of thelibvirtdaemon to establish connections to the daemon-f FILE_PATH— to pass an alternative configuration file. For details regarding configuration, refer to Section 4, “Configuration ofvhostmd”.-p PID_FILE— to create an alternative PID file. The default is/var/run/vhostmd.pid.-u USERNAME— to use a non-privileged user
You can also run vhostmd as systemd service:
>sudosystemctl enable --now vhostmd
Whenever you perform changes to configuration as described in Section 4, “Configuration of vhostmd”, restart the vhostmd service as follows:
>sudosystemctl restart vhostmd
3 Providing collected metrics to a virtual machine #
You can make the collected metrics visible to particular virtual machines for further use or
just for reading. There are two ways to achieve this. You can either attach the
metrics disk using the virsh command or adjust the domain configuration.
To attach the metrics disk in a read-only mode, run virsh as follows:
>sudovirsh attach-disk VIRTUAL_MACHINE \ PATH_TO_METRICS_DISC --driver tap \ --subdriver aio --type disk --mode readonly
To change the domain configuration, proceed as follows:
Run the command
>sudovirsh edit GUEST_NAMEUpdate the
<devices>section by adding the following snippet:<disk type='block' device='disk'> <source dev='/dev/shm/vhostmd0'/> <target dev='hdb' bus='ide'/> <readonly/> </disk>
Adjust the
devanddbusvalues of the target.
4 Configuration of vhostmd #
The default configuration file of vhostmd is located in
/etc/vhostmd/vhostmd.conf. You can adjust this file to suit your needs. The configuration file is an XML file that must
include the <vhostmd> element. <vhostmd> then
includes <globals> and <metrics> that are
described in the following sections. Use the default configuration file as a reference for
custom changes.
4.1 The <globals> element #
The <globals> element defines the disk storage location, data update
frequency and the method of transporting data
to guest machines. It contains the following elements:
<disk>The element is used to define the path of the disk where metrics data is stored and also the size of the disk. It may contain the following elements:
<name>— defines the name of the disk<path>— an absolute path where the disk is mounted<size>— using theunitattribute, specify the maximum size of the metrics. Usekfor KB,mfor MB.
<update_period>Defines how often the metrics are updated. The value is in seconds.
<transport>Specifies how the metrics are transported to guest machines. In the case of SUSE Linux Micro, use the default of
virtio.<virtio>Here you can use the following elements:
<max_channels>—specifies the maximum numbervirtioncan use between the host and guest systems.<expiration_time>—defines the time interval after which avirtiochannel of a virtual machine is closed when being idle. The default value is three times the<update_period>.
4.2 The <metrics> element #
The <metrics> element contains a list of metrics to be collected. Each
metric has two attributes:
typeDescribes the metrics value data type. Possible values are the following:
int32,uint32,int64,uint64,real32,real64,string,groupandxml.Use
groupwhen a metric returns several values.xmlis a versatile form when the metric returns a valid XML.contextDefines where the particular metric is collected. Possible values are:
hostfor metrics collected on the host machinevmfor metrics collected on the guest machine
Each metric must have a unique name and a command to run to record the metrics. The following list describes possible elements to define a metric:
<name>Defines the unique variable name. If the metric is collected on a virtual machine, you can use the following values here:
NAME,IDandUUID. Those values are then replaced with the actual ones of the virtual machine currently being checked.<action>Specifies a command or script to run to collect a metric. For example, to gather total CPU time, use:
<action>virsh dominfo NAME | sed 's/: */:/' | \ gawk -F: '/CPU time/ {print $2;}'<action><variable>if an action retuns a group of values, define variables that store particular data. The element needs to have the following attributes defined:
name— specify the name of a variabletype— specify the data type of the variable
5 How are the collected metrics stored? #
vhostmd stores the collected metrics data on the metrics disk in a raw
format. The disk contains a 32-byte header followed by the metrics data in XML format.
5.1 Metrics XML format #
The collected metrics results are similar to the configured metrics definition. The <metric>
element can have the following attributes:
typeDenotes the data type of the particular metric, for example,
string.contextIdentifies whether the metric is collected on the host (
host) or on a virtual machine (vm).idUsed in the
vmcontext. Conveys the ID number of the virtual machine.uuidUsed in the
vmcontext. Conveys the Universally Unique Identifier of the virtual machine.
The <metric> element contains the following elements:
<name>Conveys the metric name.
<value>Conveys the metrics actual value.
When the group type of a metric has been configured, each configured <variable> is stored
as a separate metric in the result. For example, the following configuration snippet:
<metric type="group" context="host"> <name>PageRates</name> <action>pagerate.pl</action> <variable name="PageInRate" type="uint64"/> <variable name="PageFaultRate" type="uint64"/> </metric>
Results in the following snippet:
<metric type='uint64' context='host'> <name>PageInRate</name> <value>0.000000</value> </metric> <metric type='uint64' context='host'> <name>PageFaultRate</name> <value>0.000000</value> </metric>
6 Legal Notice #
Copyright© 2006–2025 SUSE LLC and contributors. All rights reserved.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or (at your option) version 1.3; with the Invariant Section being this copyright notice and license. A copy of the license version 1.2 is included in the section entitled “GNU Free Documentation License”.
For SUSE trademarks, see https://www.suse.com/company/legal/. All other third-party trademarks are the property of their respective owners. Trademark symbols (®, ™ etc.) denote trademarks of SUSE and its affiliates. Asterisks (*) denote third-party trademarks.
All information found in this book has been compiled with utmost attention to detail. However, this does not guarantee complete accuracy. Neither SUSE LLC, its affiliates, the authors, nor the translators shall be held liable for possible errors or the consequences thereof.