Mercurial > hg > orthanc
comparison OrthancFramework/Sources/MetricsRegistry.h @ 4300:b30a8de92ad9
abi continued
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 05 Nov 2020 19:33:18 +0100 |
parents | 7112a8af0b63 |
children | d9473bd5ed43 |
comparison
equal
deleted
inserted
replaced
4299:3f85db78c441 | 4300:b30a8de92ad9 |
---|---|
60 void SetValueInternal(const std::string& name, | 60 void SetValueInternal(const std::string& name, |
61 float value, | 61 float value, |
62 MetricsType type); | 62 MetricsType type); |
63 | 63 |
64 public: | 64 public: |
65 MetricsRegistry() : | 65 MetricsRegistry(); |
66 enabled_(true) | |
67 { | |
68 } | |
69 | 66 |
70 ~MetricsRegistry(); | 67 ~MetricsRegistry(); |
71 | 68 |
72 bool IsEnabled() const | 69 bool IsEnabled() const; |
73 { | |
74 return enabled_; | |
75 } | |
76 | 70 |
77 void SetEnabled(bool enabled); | 71 void SetEnabled(bool enabled); |
78 | 72 |
79 void Register(const std::string& name, | 73 void Register(const std::string& name, |
80 MetricsType type); | 74 MetricsType type); |
81 | 75 |
82 void SetValue(const std::string& name, | 76 void SetValue(const std::string& name, |
83 float value, | 77 float value, |
84 MetricsType type) | 78 MetricsType type); |
85 { | |
86 // Inlining to avoid loosing time if metrics are disabled | |
87 if (enabled_) | |
88 { | |
89 SetValueInternal(name, value, type); | |
90 } | |
91 } | |
92 | 79 |
93 void SetValue(const std::string& name, | 80 void SetValue(const std::string& name, |
94 float value) | 81 float value); |
95 { | |
96 SetValue(name, value, MetricsType_Default); | |
97 } | |
98 | 82 |
99 MetricsType GetMetricsType(const std::string& name); | 83 MetricsType GetMetricsType(const std::string& name); |
100 | 84 |
101 // https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format | 85 // https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format |
102 void ExportPrometheusText(std::string& s); | 86 void ExportPrometheusText(std::string& s); |
111 float value_; | 95 float value_; |
112 | 96 |
113 public: | 97 public: |
114 SharedMetrics(MetricsRegistry& registry, | 98 SharedMetrics(MetricsRegistry& registry, |
115 const std::string& name, | 99 const std::string& name, |
116 MetricsType type) : | 100 MetricsType type); |
117 registry_(registry), | |
118 name_(name), | |
119 value_(0) | |
120 { | |
121 } | |
122 | 101 |
123 void Add(float delta); | 102 void Add(float delta); |
124 }; | 103 }; |
125 | 104 |
126 | 105 |
128 { | 107 { |
129 private: | 108 private: |
130 SharedMetrics& metrics_; | 109 SharedMetrics& metrics_; |
131 | 110 |
132 public: | 111 public: |
133 explicit ActiveCounter(SharedMetrics& metrics) : | 112 explicit ActiveCounter(SharedMetrics& metrics); |
134 metrics_(metrics) | |
135 { | |
136 metrics_.Add(1); | |
137 } | |
138 | 113 |
139 ~ActiveCounter() | 114 ~ActiveCounter(); |
140 { | |
141 metrics_.Add(-1); | |
142 } | |
143 }; | 115 }; |
144 | 116 |
145 | 117 |
146 class ORTHANC_PUBLIC Timer : public boost::noncopyable | 118 class ORTHANC_PUBLIC Timer : public boost::noncopyable |
147 { | 119 { |
154 | 126 |
155 void Start(); | 127 void Start(); |
156 | 128 |
157 public: | 129 public: |
158 Timer(MetricsRegistry& registry, | 130 Timer(MetricsRegistry& registry, |
159 const std::string& name) : | 131 const std::string& name); |
160 registry_(registry), | |
161 name_(name), | |
162 type_(MetricsType_MaxOver10Seconds) | |
163 { | |
164 Start(); | |
165 } | |
166 | 132 |
167 Timer(MetricsRegistry& registry, | 133 Timer(MetricsRegistry& registry, |
168 const std::string& name, | 134 const std::string& name, |
169 MetricsType type) : | 135 MetricsType type); |
170 registry_(registry), | |
171 name_(name), | |
172 type_(type) | |
173 { | |
174 Start(); | |
175 } | |
176 | 136 |
177 ~Timer(); | 137 ~Timer(); |
178 }; | 138 }; |
179 }; | 139 }; |
180 } | 140 } |