From ed041ec8c0fa1dd31fd3c3ac053da13519c524c3 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 24 Dec 2018 00:39:17 +0100 Subject: [PATCH] Prefix all the Futatabi Prometheus metrics by futatabi_ instead of nageru_. --- futatabi/main.cpp | 1 + shared/metrics.cpp | 11 ++++++----- shared/metrics.h | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/futatabi/main.cpp b/futatabi/main.cpp index 486bcff..52cdb80 100644 --- a/futatabi/main.cpp +++ b/futatabi/main.cpp @@ -211,6 +211,7 @@ int main(int argc, char **argv) } avformat_network_init(); + global_metrics.set_prefix("futatabi"); global_httpd = new HTTPD; QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); diff --git a/shared/metrics.cpp b/shared/metrics.cpp index 24b61fe..b2d0bbc 100644 --- a/shared/metrics.cpp +++ b/shared/metrics.cpp @@ -12,6 +12,7 @@ using namespace std; using namespace std::chrono; Metrics global_metrics; +string Metrics::prefix = "nageru"; double get_timestamp_for_metrics() { @@ -20,7 +21,7 @@ double get_timestamp_for_metrics() string Metrics::serialize_name(const string &name, const vector> &labels) { - return "nageru_" + name + serialize_labels(labels); + return prefix + "_" + name + serialize_labels(labels); } string Metrics::serialize_labels(const vector> &labels) @@ -114,7 +115,7 @@ string Metrics::serialize() const lock_guard lock(mu); auto type_it = types.cbegin(); for (const auto &key_and_metric : metrics) { - string name = "nageru_" + key_and_metric.first.name + key_and_metric.first.serialized_labels; + string name = prefix + "_" + key_and_metric.first.name + key_and_metric.first.serialized_labels; const Metric &metric = key_and_metric.second; if (type_it != types.cend() && @@ -122,11 +123,11 @@ string Metrics::serialize() const // It's the first time we print out any metric with this name, // so add the type header. if (type_it->second == TYPE_GAUGE) { - ss << "# TYPE nageru_" << type_it->first << " gauge\n"; + ss << "# TYPE " + prefix + "_" << type_it->first << " gauge\n"; } else if (type_it->second == TYPE_HISTOGRAM) { - ss << "# TYPE nageru_" << type_it->first << " histogram\n"; + ss << "# TYPE " + prefix + "_" << type_it->first << " histogram\n"; } else if (type_it->second == TYPE_SUMMARY) { - ss << "# TYPE nageru_" << type_it->first << " summary\n"; + ss << "# TYPE " + prefix + "_" << type_it->first << " summary\n"; } ++type_it; } diff --git a/shared/metrics.h b/shared/metrics.h index e2e1e74..1f130c9 100644 --- a/shared/metrics.h +++ b/shared/metrics.h @@ -38,6 +38,11 @@ public: PRINT_WHEN_NONEMPTY, }; + void set_prefix(const std::string &prefix) // Not thread-safe; must be set before HTTPD starts up. + { + this->prefix = prefix; + } + void add(const std::string &name, std::atomic *location, Type type = TYPE_COUNTER) { add(name, {}, location, type); @@ -113,6 +118,7 @@ private: mutable std::mutex mu; std::map types; // Ordered the same as metrics. std::map metrics; + static std::string prefix; friend class Histogram; friend class Summary; -- 2.39.2