]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virNodeGetMemoryStats: Implement virsh support
authorMinoru Usui <usui@mxm.nes.nec.co.jp>
Tue, 7 Jun 2011 01:09:15 +0000 (10:09 +0900)
committerEric Blake <eblake@redhat.com>
Tue, 14 Jun 2011 22:36:13 +0000 (16:36 -0600)
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
tools/virsh.c
tools/virsh.pod

index eaa8465739085281112588b3e6d1492e5b63b255..4b6b8ba103c9583f018af306078d02d346251654 100644 (file)
@@ -3718,7 +3718,7 @@ cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
  */
 static const vshCmdInfo info_nodecpustats[] = {
     {"help", N_("Prints cpu stats of the node.")},
-    {"desc", N_("Returns cpu stats of the node.")},
+    {"desc", N_("Returns cpu stats of the node, in nanoseconds.")},
     {NULL, NULL}
 };
 
@@ -3729,7 +3729,7 @@ static const vshCmdOptDef opts_node_cpustats[] = {
 };
 
 static bool
-cmdNodeCPUStats(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
 {
     int i, j;
     bool flag_utilization = false;
@@ -3842,6 +3842,67 @@ cmdNodeCPUStats(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     return ret;
 }
 
+/*
+ * "nodememstats" command
+ */
+static const vshCmdInfo info_nodememstats[] = {
+    {"help", N_("Prints memory stats of the node.")},
+    {"desc", N_("Returns memory stats of the node, in kilobytes.")},
+    {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)
+{
+    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
  */
@@ -11522,8 +11583,9 @@ static const vshCmdDef hostAndHypervisorCmds[] = {
      VSH_CMD_FLAG_NOCONNECT},
     {"freecell", cmdFreecell, opts_freecell, info_freecell, 0},
     {"hostname", cmdHostname, NULL, info_hostname, 0},
-    {"nodecpustats", cmdNodeCPUStats, opts_node_cpustats, info_nodecpustats, 0},
+    {"nodecpustats", cmdNodeCpuStats, opts_node_cpustats, info_nodecpustats, 0},
     {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
+    {"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},
index b4c580ac87c8079059a0dede78b40e89f34eabda..c3f521aabd58f647463dd57bf2c1df00521d3439 100644 (file)
@@ -246,6 +246,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