On Tue, Feb 25, 2025 at 11:51:28 +0100, Martin Kletzander wrote: > Since this is already in QEMU we can add this stat which might be useful > for people. > > Resolves: https://issues.redhat.com/browse/RHEL-71883 > Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx> > --- > docs/manpages/virsh.rst | 3 +++ > src/libvirt-domain.c | 3 +++ > src/qemu/qemu_agent.c | 59 +++++++++++++++++++++++++++++++++++++++++ > src/qemu/qemu_agent.h | 6 +++++ > src/qemu/qemu_driver.c | 32 ++++++++++++++++++++++ > tests/qemuagenttest.c | 53 ++++++++++++++++++++++++++++++++++++ > 6 files changed, 156 insertions(+) > > diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst > index 06c2802b3f9f..60b556cb0cd0 100644 > --- a/docs/manpages/virsh.rst > +++ b/docs/manpages/virsh.rst > @@ -2408,6 +2408,9 @@ When selecting the *--state* group the following fields are returned: > for bank <index> in cache monitor <num> > * ``cpu.cache.monitor.<num>.bank.<index>.bytes`` - the number of bytes > of last level cache that the domain is using on cache bank <index> > +* ``cpu.load.1m`` - average load in guest for last 1 minute > +* ``cpu.load.5m`` - average load in guest for last 5 minutes > +* ``cpu.load.15m`` - average load in guest for last 15 minutes > > > *--balloon* returns: > diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c > index 072cc3225579..35f5e926e52b 100644 > --- a/src/libvirt-domain.c > +++ b/src/libvirt-domain.c > @@ -12272,6 +12272,9 @@ virConnectGetDomainCapabilities(virConnectPtr conn, > * last level cache that the > * domain is using on cache > * bank <index> > + * "cpu.load.1m" - average load in guest for last 1 minute > + * "cpu.load.5m" - average load in guest for last 5 minutes > + * "cpu.load.15m" - average load in guest for last 15 minutes Data fetched via the guest agent doesn't belong in virConnectGetAllDomainStats but rather into virDomainGetGuestInfo. Also you should mention which typed parameter type is returned. > * > * VIR_DOMAIN_STATS_BALLOON: > * Return memory balloon device information. > diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c > index 43fca86f10ed..6dbe8c52d738 100644 > --- a/src/qemu/qemu_agent.c > +++ b/src/qemu/qemu_agent.c > @@ -2568,3 +2568,62 @@ int qemuAgentGetDisks(qemuAgent *agent, > g_free(*disks); > return -1; > } > + > + > +int > +qemuAgentGetLoadAvg(qemuAgent *agent, > + double *load1m, > + double *load5m, > + double *load15m, > + bool report_unsupported) > +{ > + g_autoptr(virJSONValue) cmd = NULL; > + g_autoptr(virJSONValue) reply = NULL; > + virJSONValue *data = NULL; > + int rc; > + > + if (load1m) > + *load1m = 0; > + > + if (load5m) > + *load5m = 0; > + > + if (load15m) > + *load15m = 0; > + > + if (!(cmd = qemuAgentMakeCommand("guest-get-load", NULL))) > + return -1; > + > + if ((rc = qemuAgentCommandFull(agent, cmd, &reply, agent->timeout, > + report_unsupported)) < 0) > + return rc; > + > + if (!(data = virJSONValueObjectGetObject(reply, "return"))) { > + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", > + _("qemu agent didn't return an array of loads")); > + return -1; > + } > + > + if (load1m && > + virJSONValueObjectGetNumberDouble(data, "load1m", load1m) < 0) { > + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", > + _("'load1m' missing in reply of guest-get-load")); > + return -1; > + } > + > + if (load5m && > + virJSONValueObjectGetNumberDouble(data, "load5m", load5m) < 0) { > + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", > + _("'load5m' missing in reply of guest-get-load")); > + return -1; > + } > + > + if (load15m && > + virJSONValueObjectGetNumberDouble(data, "load15m", load15m) < 0) { > + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", > + _("'load15m' missing in reply of guest-get-load")); Is there value having this as a translatable string for each entry? > + return -1; > + } > + > + return 0; > +}