]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/influx: Only fetch the current time once when gathering data
authorWido den Hollander <wido@42on.com>
Wed, 31 Jan 2018 13:43:54 +0000 (14:43 +0100)
committerWido den Hollander <wido@42on.com>
Tue, 20 Feb 2018 08:20:18 +0000 (09:20 +0100)
By fetching the current time once and storing it into a variable
we save a lot of system calls. On large clusters this can be a lot
of system calls.

In addition we also make sure that all points gathered in the same
loop/run have exactly the same timestamp.

Otherwise there will be a difference in time between the items in
InfluxDB which then causes problems when creating graphs with for
example Grafana.

Signed-off-by: Wido den Hollander <wido@42on.com>
src/pybind/mgr/influx/module.py

index ff498095944cf0879e5b9ddefac69e70c7bcf083..aea8b913e79010be4ebb5a10a6cb113bccab2519 100644 (file)
@@ -77,6 +77,8 @@ class Module(MgrModule):
         df = self.get("df")
         data = []
 
+        now = datetime.utcnow().isoformat() + 'Z'
+
         df_types = [
             'bytes_used',
             'kb_used',
@@ -102,7 +104,7 @@ class Module(MgrModule):
                         "type_instance": df_type,
                         "fsid": self.get_fsid()
                     },
-                    "time": datetime.utcnow().isoformat() + 'Z',
+                    "time": now,
                     "fields": {
                         "value": pool['stats'][df_type],
                     }
@@ -113,6 +115,8 @@ class Module(MgrModule):
     def get_daemon_stats(self):
         data = []
 
+        now = datetime.utcnow().isoformat() + 'Z'
+
         for daemon, counters in self.get_all_perf_counters().iteritems():
             svc_type, svc_id = daemon.split(".")
             metadata = self.get_metadata(svc_type, svc_id)
@@ -131,7 +135,7 @@ class Module(MgrModule):
                         "host": metadata['hostname'],
                         "fsid": self.get_fsid()
                     },
-                    "time": datetime.utcnow().isoformat() + 'Z',
+                    "time": now,
                     "fields": {
                         "value": value
                     }