From 640698e35e89850801a5a4a88807e7cd2f71e32b Mon Sep 17 00:00:00 2001 From: Tor Brede Vekterli Date: Fri, 15 Mar 2024 16:06:25 +0000 Subject: Support internal metric rendering in Prometheus text format in C++ Maps all internal metrics to one or more labelled time series. Due to poor compatibility between the data model (and sampling strategy) of the legacy metrics framework and that of Prometheus, all time series are emitted as `untyped` metrics. This is a stop-gap solution on the way to "properly" supporting Prometheus exposition, and the output of this renderer should therefore only be used for internal purposes. --- storage/src/vespa/storage/common/statusmetricconsumer.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'storage/src') diff --git a/storage/src/vespa/storage/common/statusmetricconsumer.cpp b/storage/src/vespa/storage/common/statusmetricconsumer.cpp index 90cd52e27b4..a2cfbf0843b 100644 --- a/storage/src/vespa/storage/common/statusmetricconsumer.cpp +++ b/storage/src/vespa/storage/common/statusmetricconsumer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,10 @@ StatusMetricConsumer::getReportContentType(const framework::HttpUrlPath& path) c return "text/plain"; } + if (path.getAttribute("format") == "prometheus") { + return "text/plain; version=0.0.4"; + } + if (path.getAttribute("format") == "json") { return "application/json"; } @@ -53,7 +58,8 @@ StatusMetricConsumer::reportStatus(std::ostream& out, _manager.updateMetrics(); vespalib::system_time currentTime = _component.getClock().getSystemTime(); - bool json = (path.getAttribute("format") == "json"); + const bool json = (path.getAttribute("format") == "json"); + const bool prometheus = (path.getAttribute("format") == "prometheus"); int verbosity(path.get("verbosity", 0)); // We have to copy unset values if using HTML as HTML version gathers @@ -126,6 +132,11 @@ StatusMetricConsumer::reportStatus(std::ostream& out, stream << End(); stream.finalize(); out << jsonStreamData.str(); + } else if (prometheus) { + vespalib::asciistream ps; + metrics::PrometheusWriter pw(ps); + _manager.visit(metricLock, *snapshot, pw, consumer); + out << ps.str(); } else { std::string pattern = path.getAttribute("pattern", ".*"); metrics::TextWriter textWriter(out, snapshot->getPeriod(), pattern, verbosity > 0); -- cgit v1.2.3