mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
Allow balloon driver collection to be adjusted dynamically
Use the virDomainSetMemoryStatsPeriodFlags() to pass a period defined by usage of a new --period option in order to set the collection period for the balloon driver. This may enable or disable the collection based on the value. Add the --current, --live, & --config options to dommemstat.
This commit is contained in:
parent
2431269bd3
commit
57b65c58d0
@ -4664,7 +4664,16 @@ qemu-kvm -net nic,model=? /dev/null
|
||||
<p>
|
||||
The optional <code>period</code> allows the QEMU virtio memory
|
||||
balloon driver to provide statistics through the <code>virsh
|
||||
dommemstat [domain]</code> command.
|
||||
dommemstat [domain]</code> command. By default, collection is
|
||||
not enabled. In order to enable, use the <code>virsh dommemstat
|
||||
[domain] --period [number]</code> command or <code>virsh edit</code>
|
||||
command to add the option to the XML definition.
|
||||
The <code>virsh dommemstat</code> will accept the options
|
||||
<code>--live</code>, <code>--current</code>, or <code>--config</code>.
|
||||
If an option is not provided, the change for a running domain will
|
||||
only be made to the active guest.
|
||||
If the QEMU driver is not at the right
|
||||
revision, the attempt to set the period will fail.
|
||||
<span class='since'>Since 1.1.1, requires QEMU 1.5</span>
|
||||
</p>
|
||||
</dd>
|
||||
|
@ -314,6 +314,23 @@ static const vshCmdOptDef opts_dommemstat[] = {
|
||||
.flags = VSH_OFLAG_REQ,
|
||||
.help = N_("domain name, id or uuid")
|
||||
},
|
||||
{.name = "period",
|
||||
.type = VSH_OT_DATA,
|
||||
.flags = VSH_OFLAG_REQ_OPT,
|
||||
.help = N_("period in seconds to set collection")
|
||||
},
|
||||
{.name = "config",
|
||||
.type = VSH_OT_BOOL,
|
||||
.help = N_("affect next boot")
|
||||
},
|
||||
{.name = "live",
|
||||
.type = VSH_OT_BOOL,
|
||||
.help = N_("affect running domain")
|
||||
},
|
||||
{.name = "current",
|
||||
.type = VSH_OT_BOOL,
|
||||
.help = N_("affect current domain")
|
||||
},
|
||||
{.name = NULL}
|
||||
};
|
||||
|
||||
@ -325,15 +342,56 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
|
||||
struct _virDomainMemoryStat stats[VIR_DOMAIN_MEMORY_STAT_NR];
|
||||
unsigned int nr_stats;
|
||||
size_t i;
|
||||
int ret = false;
|
||||
int rv = 0;
|
||||
int period = -1;
|
||||
bool config = vshCommandOptBool(cmd, "config");
|
||||
bool live = vshCommandOptBool(cmd, "live");
|
||||
bool current = vshCommandOptBool(cmd, "current");
|
||||
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
||||
|
||||
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
||||
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
||||
if (config)
|
||||
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
||||
if (live)
|
||||
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
||||
return false;
|
||||
|
||||
/* If none of the options were specified and we're active
|
||||
* then be sure to allow active modification */
|
||||
if (!current && !live && !config && virDomainIsActive(dom) == 1)
|
||||
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
||||
|
||||
/* Providing a period will adjust the balloon driver collection period.
|
||||
* This is not really an unsigned long, but it
|
||||
*/
|
||||
if ((rv = vshCommandOptInt(cmd, "period", &period)) < 0) {
|
||||
vshError(ctl, "%s",
|
||||
_("Unable to parse integer parameter."));
|
||||
goto cleanup;
|
||||
}
|
||||
if (rv > 0) {
|
||||
if (period < 0) {
|
||||
vshError(ctl, _("Invalid collection period value '%d'"), period);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virDomainSetMemoryStatsPeriod(dom, period, flags) < 0) {
|
||||
vshError(ctl, "%s",
|
||||
_("Unable to change balloon collection period."));
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
nr_stats = virDomainMemoryStats(dom, stats, VIR_DOMAIN_MEMORY_STAT_NR, 0);
|
||||
if (nr_stats == -1) {
|
||||
vshError(ctl, _("Failed to get memory statistics for domain %s"), name);
|
||||
virDomainFree(dom);
|
||||
return false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (i = 0; i < nr_stats; i++) {
|
||||
@ -355,8 +413,10 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
|
||||
vshPrint(ctl, "rss %llu\n", stats[i].val);
|
||||
}
|
||||
|
||||
ret = true;
|
||||
cleanup:
|
||||
virDomainFree(dom);
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -668,10 +668,30 @@ Both I<--live> and I<--current> flags may be given, but I<--current> is
|
||||
exclusive. If no flag is specified, behavior is different depending
|
||||
on hypervisor.
|
||||
|
||||
=item B<dommemstat> I<domain>
|
||||
=item B<dommemstat> I<domain> [I<--period> B<seconds>]
|
||||
[[I<--config>] [I<--live>] | [I<--current>]]
|
||||
|
||||
Get memory stats for a running domain.
|
||||
|
||||
Depending on the hypervisor a variety of statistics can be returned
|
||||
|
||||
For QEMU/KVM with a memory balloon, setting the optional I<--period> to a
|
||||
value larger than 0 in seconds will allow the balloon driver to return
|
||||
additional statistics which will be displayed by subsequent B<dommemstat>
|
||||
commands. Setting the I<--period> to 0 will stop the balloon driver collection,
|
||||
but does not clear the statistics in the balloon driver. Requires at least
|
||||
QEMU/KVM 1.5 to be running on the host.
|
||||
|
||||
The I<--live>, I<--config>, and I<--current> flags are only valid when using
|
||||
the I<--period> option in order to set the collection period for the balloon
|
||||
driver. If I<--live> is specified, only the running guest collection period
|
||||
is affected. If I<--config> is specified, affect the next boot of a persistent
|
||||
guest. If I<--current> is specified, affect the current guest state.
|
||||
|
||||
Both I<--live> and I<--config> flags may be given, but I<--current> is
|
||||
exclusive. If no flag is specified, behavior is different depending
|
||||
on the guest state.
|
||||
|
||||
=item B<domblkerror> I<domain>
|
||||
|
||||
Show errors on block devices. This command usually comes handy when
|
||||
|
Loading…
x
Reference in New Issue
Block a user