]> git.sesse.net Git - nageru/commitdiff
Prefix all the Futatabi Prometheus metrics by futatabi_ instead of nageru_.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 23 Dec 2018 23:39:17 +0000 (00:39 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 23 Dec 2018 23:39:17 +0000 (00:39 +0100)
futatabi/main.cpp
shared/metrics.cpp
shared/metrics.h

index 486bcfff213654bf409691ac4212bd4acdaaa44c..52cdb80664379e5014fb0f5ea673234e087f14b8 100644 (file)
@@ -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);
index 24b61fe56de7cb0574dab74670101393ae645dab..b2d0bbce5ca0671a3d810bf19c74cd7dda29f1ce 100644 (file)
@@ -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<pair<string, string>> &labels)
 {
-       return "nageru_" + name + serialize_labels(labels);
+       return prefix + "_" + name + serialize_labels(labels);
 }
 
 string Metrics::serialize_labels(const vector<pair<string, string>> &labels)
@@ -114,7 +115,7 @@ string Metrics::serialize() const
        lock_guard<mutex> 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;
                }
index e2e1e74f5ac9bb818f5bbdb8e6798ec27cadf869..1f130c981ba65684d77b44c627832a3b93d1be40 100644 (file)
@@ -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<int64_t> *location, Type type = TYPE_COUNTER)
        {
                add(name, {}, location, type);
@@ -113,6 +118,7 @@ private:
        mutable std::mutex mu;
        std::map<std::string, Type> types;  // Ordered the same as metrics.
        std::map<MetricKey, Metric> metrics;
+       static std::string prefix;
 
        friend class Histogram;
        friend class Summary;