From: Boris Ranto Date: Thu, 12 Jul 2018 17:29:07 +0000 (+0200) Subject: prometheus: Format metrics in the collect function X-Git-Tag: v13.2.2~49^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=aa7b20d62e2c48cd15dd15b20e9ef4a7585f35e5;p=ceph.git prometheus: Format metrics in the collect function This allows us to clear metrics upon formatting in the collect function. Signed-off-by: Boris Ranto (cherry picked from commit 2583672dba808b126580b0ba3e961d274a162d11) --- diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index 70f7a2de9b3d..381af8c6de1a 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -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 ''' @@ -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')