Mercurial > hg > orthanc
comparison OrthancFramework/Sources/MetricsRegistry.h @ 5336:dd9795dc380d
renamed MetricsType as MetricsUpdate to clarify
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 27 Jun 2023 15:56:04 +0200 |
parents | fbe857e942cd |
children | b376abae664a |
comparison
equal
deleted
inserted
replaced
5335:c103b0e70d75 | 5336:dd9795dc380d |
---|---|
37 #include <boost/date_time/posix_time/posix_time.hpp> | 37 #include <boost/date_time/posix_time/posix_time.hpp> |
38 #include <stdint.h> | 38 #include <stdint.h> |
39 | 39 |
40 namespace Orthanc | 40 namespace Orthanc |
41 { | 41 { |
42 enum MetricsType | 42 enum MetricsUpdate |
43 { | 43 { |
44 MetricsType_Default, | 44 MetricsUpdate_Directly, |
45 MetricsType_MaxOver10Seconds, | 45 MetricsUpdate_MaxOver10Seconds, |
46 MetricsType_MaxOver1Minute, | 46 MetricsUpdate_MaxOver1Minute, |
47 MetricsType_MinOver10Seconds, | 47 MetricsUpdate_MinOver10Seconds, |
48 MetricsType_MinOver1Minute | 48 MetricsUpdate_MinOver1Minute |
49 }; | 49 }; |
50 | 50 |
51 class ORTHANC_PUBLIC MetricsRegistry : public boost::noncopyable | 51 class ORTHANC_PUBLIC MetricsRegistry : public boost::noncopyable |
52 { | 52 { |
53 private: | 53 private: |
59 boost::mutex mutex_; | 59 boost::mutex mutex_; |
60 Content content_; | 60 Content content_; |
61 | 61 |
62 // The mutex must be locked | 62 // The mutex must be locked |
63 Item& GetItemInternal(const std::string& name, | 63 Item& GetItemInternal(const std::string& name, |
64 MetricsType type); | 64 MetricsUpdate update); |
65 | 65 |
66 public: | 66 public: |
67 MetricsRegistry(); | 67 MetricsRegistry(); |
68 | 68 |
69 ~MetricsRegistry(); | 69 ~MetricsRegistry(); |
71 bool IsEnabled() const; | 71 bool IsEnabled() const; |
72 | 72 |
73 void SetEnabled(bool enabled); | 73 void SetEnabled(bool enabled); |
74 | 74 |
75 void Register(const std::string& name, | 75 void Register(const std::string& name, |
76 MetricsType type); | 76 MetricsUpdate update); |
77 | 77 |
78 void SetValue(const std::string& name, | 78 void SetValue(const std::string& name, |
79 int64_t value, | 79 int64_t value, |
80 MetricsType type); | 80 MetricsUpdate update); |
81 | 81 |
82 void SetValue(const std::string& name, | 82 void SetValue(const std::string& name, |
83 int64_t value) | 83 int64_t value) |
84 { | 84 { |
85 SetValue(name, value, MetricsType_Default); | 85 SetValue(name, value, MetricsUpdate_Directly); |
86 } | 86 } |
87 | 87 |
88 void IncrementValue(const std::string& name, | 88 void IncrementValue(const std::string& name, |
89 int64_t delta); | 89 int64_t delta); |
90 | 90 |
91 MetricsType GetMetricsType(const std::string& name); | 91 MetricsUpdate GetMetricsUpdate(const std::string& name); |
92 | 92 |
93 // https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format | 93 // https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format |
94 void ExportPrometheusText(std::string& s); | 94 void ExportPrometheusText(std::string& s); |
95 | 95 |
96 | 96 |
103 int64_t value_; | 103 int64_t value_; |
104 | 104 |
105 public: | 105 public: |
106 SharedMetrics(MetricsRegistry& registry, | 106 SharedMetrics(MetricsRegistry& registry, |
107 const std::string& name, | 107 const std::string& name, |
108 MetricsType type); | 108 MetricsUpdate update); |
109 | 109 |
110 void Add(int64_t delta); | 110 void Add(int64_t delta); |
111 }; | 111 }; |
112 | 112 |
113 | 113 |
126 class ORTHANC_PUBLIC Timer : public boost::noncopyable | 126 class ORTHANC_PUBLIC Timer : public boost::noncopyable |
127 { | 127 { |
128 private: | 128 private: |
129 MetricsRegistry& registry_; | 129 MetricsRegistry& registry_; |
130 std::string name_; | 130 std::string name_; |
131 MetricsType type_; | 131 MetricsUpdate update_; |
132 bool active_; | 132 bool active_; |
133 boost::posix_time::ptime start_; | 133 boost::posix_time::ptime start_; |
134 | 134 |
135 void Start(); | 135 void Start(); |
136 | 136 |
138 Timer(MetricsRegistry& registry, | 138 Timer(MetricsRegistry& registry, |
139 const std::string& name); | 139 const std::string& name); |
140 | 140 |
141 Timer(MetricsRegistry& registry, | 141 Timer(MetricsRegistry& registry, |
142 const std::string& name, | 142 const std::string& name, |
143 MetricsType type); | 143 MetricsUpdate update); |
144 | 144 |
145 ~Timer(); | 145 ~Timer(); |
146 }; | 146 }; |
147 }; | 147 }; |
148 } | 148 } |