]> git.sesse.net Git - nageru/blobdiff - metrics.h
Mark the appropriate metrics as gauges.
[nageru] / metrics.h
index 6c72ad53ed71c6bc66b8923a643697d0dea16701..e54bbcf41b083ea1dcc36c2a2ab781cad81471dc 100644 (file)
--- a/metrics.h
+++ b/metrics.h
 
 class Metrics {
 public:
-       void register_int_metric(const std::string &name, std::atomic<int64_t> *location);
-       void register_double_metric(const std::string &name, std::atomic<double> *location);
+       enum Type {
+               TYPE_COUNTER,
+               TYPE_GAUGE,
+       };
+
+       void register_int_metric(const std::string &name, std::atomic<int64_t> *location, Type type = TYPE_COUNTER);
+       void register_double_metric(const std::string &name, std::atomic<double> *location, Type type = TYPE_COUNTER);
        std::string serialize() const;
 
 private:
+       template<class T>
+       struct Metric {
+               Type type;
+               std::atomic<T> *location;
+       };
+
        mutable std::mutex mu;
-       std::unordered_map<std::string, std::atomic<int64_t> *> int_metrics;
-       std::unordered_map<std::string, std::atomic<double> *> double_metrics;
+       std::unordered_map<std::string, Metric<int64_t>> int_metrics;
+       std::unordered_map<std::string, Metric<double>> double_metrics;
 };
 
 extern Metrics global_metrics;