[PATCH 5/6] virNodeGetMemoryStats: Implement virsh support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



virNodeGetMemoryStats: Implement virsh support

Add nodecpustats subcommand to virsh.
This subcommand prints below output.

[Linux]
  # build/tools/virsh nodememstats
  total          :              8058876 kB
  free           :              5042384 kB
  buffers        :               832728 kB
  cached         :               776736 kB

Signed-off-by: Minoru Usui <usui@xxxxxxxxxxxxxxxxx>
---
 tools/virsh.c   |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod |    4 ++++
 2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index de49489..9e57b27 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -3490,6 +3490,56 @@ cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 }
 
 /*
+ * "nodememstats" command
+ */
+static const vshCmdInfo info_nodememstats[] = {
+    {"help", N_("Prints memory stats of the node.")},
+    {"desc", N_("Returns memory stats of the node.(KB)")},
+    {NULL, NULL}
+};
+
+static bool
+cmdNodememstats(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
+{
+    int nparams = 0;
+    unsigned int i = 0;
+    virMemoryStatsPtr params = NULL;
+    bool ret = false;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return false;
+
+    /* get the number of memory parameters */
+    if (virNodeGetMemoryStats(ctl->conn, NULL, &nparams, 0) != 0) {
+        vshError(ctl, "%s",
+                 _("Unable to get number of memory stats"));
+        goto cleanup;
+    }
+
+    if (nparams == 0) {
+        /* nothing to output */
+        ret = true;
+        goto cleanup;
+    }
+
+    /* now go get all the memory parameters */
+    params = vshCalloc(ctl, nparams, sizeof(*params));
+    if (virNodeGetMemoryStats(ctl->conn, params, &nparams, 0) != 0) {
+        vshError(ctl, "%s", _("Unable to get memory stats"));
+        goto cleanup;
+    }
+
+    for (i = 0; i < nparams; i++)
+        vshPrint(ctl, "%-15s: %20llu kB\n", params[i].field, params[i].value);
+
+    ret = true;
+
+  cleanup:
+    VIR_FREE(params);
+    return ret;
+}
+
+/*
  * "capabilities" command
  */
 static const vshCmdInfo info_capabilities[] = {
@@ -10998,6 +11048,7 @@ static const vshCmdDef hostAndHypervisorCmds[] = {
     {"freecell", cmdFreecell, opts_freecell, info_freecell, 0},
     {"hostname", cmdHostname, NULL, info_hostname, 0},
     {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
+    {"nodememstats", cmdNodememstats, NULL, info_nodememstats, 0},
     {"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command,
      info_qemu_monitor_command, 0},
     {"sysinfo", cmdSysinfo, NULL, info_sysinfo, 0},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index ef01f41..bafc6f2 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -237,6 +237,10 @@ Print the XML representation of the hypervisor sysinfo, if available.
 Returns basic information about the node, like number and type of CPU,
 and size of the physical memory.
 
+=item B<nodememstats>
+
+Returns memory stats of the node.
+
 =item B<capabilities>
 
 Print an XML document describing the capabilities of the hypervisor
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]