[PATCH 11/12] [v2] virNodeGetMemoryStats: Implement virsh support

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

 



virNodeGetMemoryStats: Implement virsh support

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

diff --git a/tools/virsh.c b/tools/virsh.c
index 2fbc91a..c419be9 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -3815,6 +3815,67 @@ cmdNodeCPUStats(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 const vshCmdOptDef opts_node_memstats[] = {
+    {"cell", VSH_OT_INT, 0, N_("prints specified cell statistics only.")},
+    {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdNodememstats(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
+{
+    int nparams = 0;
+    unsigned int i = 0;
+    int cellNum = VIR_MEMORY_STATS_ALL_CELLS;
+    virMemoryStatsPtr params = NULL;
+    bool ret = false;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return false;
+
+    if (vshCommandOptInt(cmd, "cell", &cellNum) < 0) {
+        vshError(ctl, "%s", _("Invalid value of cellNum"));
+        return false;
+    }
+
+    /* get the number of memory parameters */
+    if (virNodeGetMemoryStats(ctl->conn, cellNum, 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, cellNum, params, &nparams, 0) != 0) {
+        vshError(ctl, "%s", _("Unable to get memory stats"));
+        goto cleanup;
+    }
+
+    for (i = 0; i < nparams; i++)
+        vshPrint(ctl, "%-7s: %20llu kB\n", params[i].field, params[i].value);
+
+    ret = true;
+
+  cleanup:
+    VIR_FREE(params);
+    return ret;
+}
+
+/*
  * "capabilities" command
  */
 static const vshCmdInfo info_capabilities[] = {
@@ -11427,6 +11488,7 @@ static const vshCmdDef hostAndHypervisorCmds[] = {
     {"hostname", cmdHostname, NULL, info_hostname, 0},
     {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
     {"nodecpustats", cmdNodeCPUStats, opts_node_cpustats, info_nodecpustats},
+    {"nodememstats", cmdNodememstats, opts_node_memstats, 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 ade4eab..1556765 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -244,6 +244,11 @@ If I<--cpu> is specified, this will prints specified cpu statistics only.
 If I<--percent> is specified, this will prints percentage of each kind of cpu
 statistics during 1 second.
 
+=item B<nodememstats> optional I<--cell>
+
+Returns memory stats of the node.
+If I<--cell> is specified, this will prints specified cell statistics only.
+
 =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]