From 2dbb9434b0d10b086e6d5367087aa1a4cdd77be0 Mon Sep 17 00:00:00 2001 From: Florian Sesser Date: Wed, 8 Sep 2021 14:54:57 +0000 Subject: [PATCH] OpenMetrics endpoint WIP --- src/allmydata/web/status.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/allmydata/web/status.py b/src/allmydata/web/status.py index 741f93061..7d3fdd06e 100644 --- a/src/allmydata/web/status.py +++ b/src/allmydata/web/status.py @@ -1554,6 +1554,10 @@ class Statistics(MultiFormatResource): @render_exception def render_OPENMETRICS(self, req): + req.setHeader("content-type", "application/openmetrics-text; version=1.0.0; charset=utf-8") + stats = self._provider.get_stats() + ret = u"" + def mangle_name(name): return re.sub( "_(\d\d)_(\d)_percentile", @@ -1561,15 +1565,13 @@ class Statistics(MultiFormatResource): name.replace(".", "_") ) - req.setHeader( - "content-type", "application/openmetrics-text; version=1.0.0; charset=utf-8" - ) + for (k, v) in sorted(stats['counters'].items()): + ret += u"tahoe_counters_%s %s\n" % (mangle_name(k), v) - stats = self._provider.get_stats() - return (str({mangle_name(k): v for k, v in stats['counters'].items()}) - + str({mangle_name(k): v for k, v in stats['stats'].items()}) - + "\n" - ) + for (k, v) in sorted(stats['stats'].items()): + ret += u"tahoe_stats_%s %s\n" % (mangle_name(k), v) + + return ret class StatisticsElement(Element):