diff Core/MetricsRegistry.h @ 3176:784bbb03fb54

new metrics: orthanc_rest_api_active_requests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Jan 2019 18:07:41 +0100
parents 8ea7c4546c3a
children 94f4a18a79cc
line wrap: on
line diff
--- a/Core/MetricsRegistry.h	Tue Jan 29 17:34:09 2019 +0100
+++ b/Core/MetricsRegistry.h	Tue Jan 29 18:07:41 2019 +0100
@@ -111,6 +111,47 @@
     void ExportPrometheusText(std::string& s);
 
 
+    class SharedMetrics : public boost::noncopyable
+    {
+    private:
+      boost::mutex      mutex_;
+      MetricsRegistry&  registry_;
+      std::string       name_;
+      float             value_;
+
+    public:
+      SharedMetrics(MetricsRegistry& registry,
+                    const std::string& name,
+                    MetricsType type) :
+        registry_(registry),
+        name_(name),
+        value_(0)
+      {
+      }
+
+      void Add(float delta);
+    };
+
+
+    class ActiveCounter : public boost::noncopyable
+    {
+    private:
+      SharedMetrics&   metrics_;
+
+    public:
+      ActiveCounter(SharedMetrics& metrics) :
+        metrics_(metrics)
+      {
+        metrics_.Add(1);
+      }
+
+      ~ActiveCounter()
+      {
+        metrics_.Add(-1);
+      }
+    };
+
+
     class Timer : public boost::noncopyable
     {
     private: