]> git.sesse.net Git - nageru/blobdiff - shared/metrics.h
Export SRT statistics as Prometheus metrics.
[nageru] / shared / metrics.h
index e2e1e74f5ac9bb818f5bbdb8e6798ec27cadf869..858853f8c0ce976bd07997a7725a5554109cb3c5 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);
@@ -70,6 +75,8 @@ public:
 
        void remove(const std::string &name, const std::vector<std::pair<std::string, std::string>> &labels);
 
+       void remove_if_exists(const std::string &name, const std::vector<std::pair<std::string, std::string>> &labels);
+
        std::string serialize() const;
 
 private:
@@ -113,6 +120,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;