OpenMetrics endpoint WIP

This commit is contained in:
Florian Sesser 2021-09-08 14:54:57 +00:00
parent 8a64f50b79
commit 2dbb9434b0
1 changed files with 10 additions and 8 deletions

View File

@ -1554,6 +1554,10 @@ class Statistics(MultiFormatResource):
@render_exception @render_exception
def render_OPENMETRICS(self, req): 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): def mangle_name(name):
return re.sub( return re.sub(
"_(\d\d)_(\d)_percentile", "_(\d\d)_(\d)_percentile",
@ -1561,15 +1565,13 @@ class Statistics(MultiFormatResource):
name.replace(".", "_") name.replace(".", "_")
) )
req.setHeader( for (k, v) in sorted(stats['counters'].items()):
"content-type", "application/openmetrics-text; version=1.0.0; charset=utf-8" ret += u"tahoe_counters_%s %s\n" % (mangle_name(k), v)
)
stats = self._provider.get_stats() for (k, v) in sorted(stats['stats'].items()):
return (str({mangle_name(k): v for k, v in stats['counters'].items()}) ret += u"tahoe_stats_%s %s\n" % (mangle_name(k), v)
+ str({mangle_name(k): v for k, v in stats['stats'].items()})
+ "\n" return ret
)
class StatisticsElement(Element): class StatisticsElement(Element):