[PATCH 2/2] qemu: expand domain memory statistics with 'last-update' timestamp

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

 



From: Derbyshev Dmitry <dderbyshev@xxxxxxxxxxxxx>

QEMU reports timestamp along with other memory statistics, but this information
is not saved into domain statistics. It could be useful to determine if the
data reported is fresh or not.
Balloon statistics are not reported in hrf, so no modifications are made in
qemu_monitor_text.c.

Signed-off-by: Derbyshev Dmitry <dderbyshev@xxxxxxxxxxxxx>
---
 include/libvirt/libvirt-domain.h |  4 ++++
 src/libvirt-domain.c             |  2 ++
 src/qemu/qemu_monitor_json.c     | 21 +++++++++++----------
 tools/virsh-domain-monitor.c     |  2 ++
 4 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index b65dd33..002253f 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -603,6 +603,10 @@ typedef enum {
      * is in kB */
     VIR_DOMAIN_MEMORY_STAT_RSS             = 7,
 
+
+    /* Timestamp of the last update of statistics */
+    VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE     = 8,
+
     /*
      * How big the balloon can be inflated without pushing the guest system
      * to swap, corresponds to 'Available' in /proc/meminfo
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 6ef53a6..be35173 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -5991,6 +5991,8 @@ virDomainGetInterfaceParameters(virDomainPtr domain,
  *     to swap, corresponds to 'Available' in /proc/meminfo
  * VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON:
  *     Current balloon value (in kb).
+ * VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE
+ *     Timestamp of the last statistic
  *
  * Returns: The number of stats provided or -1 in case of failure.
  */
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index aa9762f..d31ea74 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1602,10 +1602,10 @@ qemuMonitorJSONGetBalloonInfo(qemuMonitorPtr mon,
  * rates and/or whether data has been collected since a previous cycle.
  * It's currently unused.
  */
-#define GET_BALLOON_STATS(FIELD, TAG, DIVISOR)                                \
-    if (virJSONValueObjectHasKey(statsdata, FIELD) &&                         \
+#define GET_BALLOON_STATS(OBJECT, FIELD, TAG, DIVISOR)                        \
+    if (virJSONValueObjectHasKey(OBJECT, FIELD) &&                            \
        (got < nr_stats)) {                                                    \
-        if (virJSONValueObjectGetNumberUlong(statsdata, FIELD, &mem) < 0) {   \
+        if (virJSONValueObjectGetNumberUlong(OBJECT, FIELD, &mem) < 0) {      \
             VIR_DEBUG("Failed to get '%s' value", FIELD);                     \
         } else {                                                              \
             /* Not being collected? No point in providing bad data */         \
@@ -1676,21 +1676,22 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,
         goto cleanup;
     }
 
-    GET_BALLOON_STATS("stat-swap-in",
+    GET_BALLOON_STATS(statsdata, "stat-swap-in",
                       VIR_DOMAIN_MEMORY_STAT_SWAP_IN, 1024);
-    GET_BALLOON_STATS("stat-swap-out",
+    GET_BALLOON_STATS(statsdata, "stat-swap-out",
                       VIR_DOMAIN_MEMORY_STAT_SWAP_OUT, 1024);
-    GET_BALLOON_STATS("stat-major-faults",
+    GET_BALLOON_STATS(statsdata, "stat-major-faults",
                       VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT, 1);
-    GET_BALLOON_STATS("stat-minor-faults",
+    GET_BALLOON_STATS(statsdata, "stat-minor-faults",
                       VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT, 1);
-    GET_BALLOON_STATS("stat-free-memory",
+    GET_BALLOON_STATS(statsdata, "stat-free-memory",
                       VIR_DOMAIN_MEMORY_STAT_UNUSED, 1024);
-    GET_BALLOON_STATS("stat-total-memory",
+    GET_BALLOON_STATS(statsdata, "stat-total-memory",
                       VIR_DOMAIN_MEMORY_STAT_AVAILABLE, 1024);
     GET_BALLOON_STATS("available",
                       VIR_DOMAIN_MEMORY_STAT_USABLE, 1024);
-
+    GET_BALLOON_STATS(data, "last-update",
+                      VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE, 1);
 
  cleanup:
     virJSONValueFree(cmd);
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 1921ff5..b4ccbf6 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -375,6 +375,8 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
             vshPrint(ctl, "actual %llu\n", stats[i].val);
         if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_RSS)
             vshPrint(ctl, "rss %llu\n", stats[i].val);
+        if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE)
+            vshPrint(ctl, "last_update %llu\n", stats[i].val);
     }
 
     ret = true;
-- 
1.9.5.msysgit.0

--
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]