diff options
author | Tor Brede Vekterli <vekterli@vespa.ai> | 2024-03-15 16:06:25 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@vespa.ai> | 2024-03-19 10:55:28 +0000 |
commit | 640698e35e89850801a5a4a88807e7cd2f71e32b (patch) | |
tree | bd8d00ef53c488eb4e3367c13e449c95c94d3ed2 /storage | |
parent | 2f663bd8757167d9d655f38d0116be4ec77fb266 (diff) |
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.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/src/vespa/storage/common/statusmetricconsumer.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
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 <boost/lexical_cast.hpp> #include <vespa/metrics/jsonwriter.h> #include <vespa/metrics/textwriter.h> +#include <vespa/metrics/prometheus_writer.h> #include <vespa/metrics/metricmanager.h> #include <vespa/storageapi/messageapi/storagemessage.h> #include <vespa/vespalib/stllike/asciistream.h> @@ -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); |