]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
prometheus: Format metrics in the collect function
authorBoris Ranto <branto@redhat.com>
Thu, 12 Jul 2018 17:29:07 +0000 (19:29 +0200)
committerBoris Ranto <branto@redhat.com>
Tue, 24 Jul 2018 19:41:39 +0000 (21:41 +0200)
This allows us to clear metrics upon formatting in the collect function.

Signed-off-by: Boris Ranto <branto@redhat.com>
(cherry picked from commit 2583672dba808b126580b0ba3e961d274a162d11)

src/pybind/mgr/prometheus/module.py

index 70f7a2de9b3d048122914f0744707926f3effa38..381af8c6de1a85efef77c73ab8bacc59d595b000 100644 (file)
@@ -585,7 +585,12 @@ class Module(MgrModule):
                         )
                     self.metrics[path].set(value, (daemon,))
 
-        return self.metrics
+        # Return formatted metrics and clear no longer used data
+        _metrics = [m.str_expfmt() for m in self.metrics.values()]
+        for k in self.metrics.keys():
+            self.metrics[k].clear()
+
+        return ''.join(_metrics) + '\n'
 
     def get_file_sd_config(self):
         servers = self.list_servers()
@@ -643,10 +648,6 @@ class Module(MgrModule):
                 cherrypy.request.path = ''
                 return self
 
-            def format_metrics(self, metrics):
-                _metrics = [m.str_expfmt() for m in metrics.values()]
-                return ''.join(_metrics) + '\n'
-
             @cherrypy.expose
             def index(self):
                 return '''<!DOCTYPE html>
@@ -674,11 +675,9 @@ class Module(MgrModule):
                     return instance.collect_cache
 
                 if instance.have_mon_connection():
-                    metrics = instance.collect()
+                    instance.collect_cache = instance.collect()
                     cherrypy.response.headers['Content-Type'] = 'text/plain'
-                    if metrics:
-                        instance.collect_cache = self.format_metrics(metrics)
-                        return instance.collect_cache
+                    return instance.collect_cache
                 else:
                     raise cherrypy.HTTPError(503, 'No MON connection')