From 0857d3bcd4175f39582376fb9980cf3f66fa09ce Mon Sep 17 00:00:00 2001 From: Wido den Hollander Date: Wed, 31 Jan 2018 14:43:54 +0100 Subject: [PATCH] mgr/influx: Only fetch the current time once when gathering data 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 --- src/pybind/mgr/influx/module.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/influx/module.py b/src/pybind/mgr/influx/module.py index ff498095944..aea8b913e79 100644 --- a/src/pybind/mgr/influx/module.py +++ b/src/pybind/mgr/influx/module.py @@ -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 } -- 2.39.5