4 // A simple global class to keep track of metrics export in Prometheus format.
5 // It would be better to use a more full-featured Prometheus client library for this,
6 // but it would introduce a dependency that is not commonly packaged in distributions,
7 // which makes it quite unwieldy. Thus, we'll package our own for the time being.
22 void add(const std::string &name, std::atomic<int64_t> *location, Type type = TYPE_COUNTER)
24 add(name, {}, location, type);
27 void add(const std::string &name, std::atomic<double> *location, Type type = TYPE_COUNTER)
29 add(name, {}, location, type);
32 void add(const std::string &name, const std::vector<std::pair<std::string, std::string>> &labels, std::atomic<int64_t> *location, Type type = TYPE_COUNTER);
33 void add(const std::string &name, const std::vector<std::pair<std::string, std::string>> &labels, std::atomic<double> *location, Type type = TYPE_COUNTER);
35 // Only integer histogram, ie. keys are 0..(N-1).
36 void add_histogram(const std::string &name, const std::vector<std::pair<std::string, std::string>> &labels, std::atomic<int64_t> *location, size_t num_elements);
38 std::string serialize() const;
49 std::vector<std::pair<std::string, std::string>> labels;
51 std::atomic<int64_t> *location_int64;
52 std::atomic<double> *location_double;
56 // TODO: This needs to be more general.
59 std::vector<std::pair<std::string, std::string>> labels;
60 std::atomic<int64_t> *location_int64; // First bucket.
64 mutable std::mutex mu;
65 std::map<std::string, Type> types;
66 std::vector<Metric> metrics;
67 std::vector<Histogram> histograms;
70 extern Metrics global_metrics;
72 #endif // !defined(_METRICS_H)