Mercurial > hg > orthanc
annotate OrthancFramework/Sources/MetricsRegistry.cpp @ 5644:343149762476
fix build with DCMTK <= 3.6.6
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 31 May 2024 18:23:44 +0200 |
parents | f7adfb22e20e |
children | 7fadeb395359 |
rev | line source |
---|---|
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5344
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
12 * the License, or (at your option) any later version. |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, but |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * Lesser General Public License for more details. |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 **/ |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "PrecompiledHeaders.h" |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "MetricsRegistry.h" |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
28 #include "ChunkedBuffer.h" |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
29 #include "Compatibility.h" |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 #include "OrthancException.h" |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
32 #include <boost/math/special_functions/round.hpp> |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
33 |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 namespace Orthanc |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 static const boost::posix_time::ptime GetNow() |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
38 return boost::posix_time::microsec_clock::universal_time(); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
41 namespace |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
42 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
43 template <typename T> |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
44 class TimestampedValue : public boost::noncopyable |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
45 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
46 private: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
47 boost::posix_time::ptime time_; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
48 bool hasValue_; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
49 T value_; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
50 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
51 void SetValue(const T& value, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
52 const boost::posix_time::ptime& now) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
53 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
54 hasValue_ = true; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
55 value_ = value; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
56 time_ = now; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
57 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
58 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
59 bool IsLargerOverPeriod(const T& value, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
60 int duration, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
61 const boost::posix_time::ptime& now) const |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
62 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
63 if (hasValue_) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
64 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
65 return (value > value_ || |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
66 (now - time_).total_seconds() > duration /* old value has expired */); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
67 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
68 else |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
69 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
70 return true; // No value yet |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
71 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
72 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
73 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
74 bool IsSmallerOverPeriod(const T& value, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
75 int duration, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
76 const boost::posix_time::ptime& now) const |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
77 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
78 if (hasValue_) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
79 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
80 return (value < value_ || |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
81 (now - time_).total_seconds() > duration /* old value has expired */); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
82 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
83 else |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
84 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
85 return true; // No value yet |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
86 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
87 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
88 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
89 public: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
90 explicit TimestampedValue() : |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
91 hasValue_(false), |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
92 value_(0) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
93 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
94 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
95 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
96 void Update(const T& value, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
97 const MetricsUpdatePolicy& policy) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
98 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
99 const boost::posix_time::ptime now = GetNow(); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
100 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
101 switch (policy) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
102 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
103 case MetricsUpdatePolicy_Directly: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
104 SetValue(value, now); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
105 break; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
106 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
107 case MetricsUpdatePolicy_MaxOver10Seconds: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
108 if (IsLargerOverPeriod(value, 10, now)) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
109 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
110 SetValue(value, now); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
111 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
112 break; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
113 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
114 case MetricsUpdatePolicy_MaxOver1Minute: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
115 if (IsLargerOverPeriod(value, 60, now)) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
116 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
117 SetValue(value, now); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
118 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
119 break; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
120 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
121 case MetricsUpdatePolicy_MinOver10Seconds: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
122 if (IsSmallerOverPeriod(value, 10, now)) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
123 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
124 SetValue(value, now); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
125 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
126 break; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
127 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
128 case MetricsUpdatePolicy_MinOver1Minute: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
129 if (IsSmallerOverPeriod(value, 60, now)) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
130 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
131 SetValue(value, now); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
132 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
133 break; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
134 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
135 default: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
136 throw OrthancException(ErrorCode_NotImplemented); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
137 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
138 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
139 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
140 void Increment(const T& delta) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
141 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
142 if (hasValue_) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
143 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
144 value_ += delta; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
145 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
146 else |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
147 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
148 value_ = delta; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
149 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
150 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
151 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
152 bool HasValue() const |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
153 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
154 return hasValue_; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
155 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
156 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
157 const boost::posix_time::ptime& GetTime() const |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
158 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
159 if (hasValue_) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
160 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
161 return time_; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
162 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
163 else |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
164 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
165 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
166 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
167 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
168 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
169 const T& GetValue() const |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
170 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
171 if (hasValue_) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
172 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
173 return value_; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
174 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
175 else |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
176 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
177 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
178 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
179 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
180 }; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
181 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
182 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
183 |
5336
dd9795dc380d
renamed MetricsType as MetricsUpdate to clarify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5335
diff
changeset
|
184 class MetricsRegistry::Item : public boost::noncopyable |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 private: |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
187 MetricsUpdatePolicy policy_; |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
189 public: |
5344 | 190 explicit Item(MetricsUpdatePolicy policy) : |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
191 policy_(policy) |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 } |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
194 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
195 virtual ~Item() |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
199 MetricsUpdatePolicy GetPolicy() const |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
201 return policy_; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
202 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
203 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
204 virtual void UpdateFloat(float value) = 0; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
205 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
206 virtual void UpdateInteger(int64_t value) = 0; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
207 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
208 virtual void IncrementInteger(int64_t delta) = 0; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
209 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
210 virtual MetricsDataType GetDataType() const = 0; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
211 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
212 virtual bool HasValue() const = 0; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
213 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
214 virtual const boost::posix_time::ptime& GetTime() const = 0; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
215 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
216 virtual std::string FormatValue() const = 0; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
217 }; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
218 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
219 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
220 class MetricsRegistry::FloatItem : public Item |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
221 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
222 private: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
223 TimestampedValue<float> value_; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
224 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
225 public: |
5344 | 226 explicit FloatItem(MetricsUpdatePolicy policy) : |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
227 Item(policy) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
228 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
229 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
230 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
231 virtual void UpdateFloat(float value) ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
232 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
233 value_.Update(value, GetPolicy()); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
234 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
235 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
236 virtual void UpdateInteger(int64_t value) ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
237 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
238 value_.Update(static_cast<float>(value), GetPolicy()); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
239 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
240 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
241 virtual void IncrementInteger(int64_t delta) ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
242 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
243 value_.Increment(static_cast<float>(delta)); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
244 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
245 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
246 virtual MetricsDataType GetDataType() const ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
247 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
248 return MetricsDataType_Float; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
249 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
250 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
251 virtual bool HasValue() const ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
252 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
253 return value_.HasValue(); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
256 virtual const boost::posix_time::ptime& GetTime() const ORTHANC_OVERRIDE |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
258 return value_.GetTime(); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
259 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
260 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
261 virtual std::string FormatValue() const ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
262 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
263 return boost::lexical_cast<std::string>(value_.GetValue()); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
264 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
265 }; |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
267 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
268 class MetricsRegistry::IntegerItem : public Item |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
269 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
270 private: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
271 TimestampedValue<int64_t> value_; |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
273 public: |
5344 | 274 explicit IntegerItem(MetricsUpdatePolicy policy) : |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
275 Item(policy) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
276 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
277 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
278 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
279 virtual void UpdateFloat(float value) ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
280 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
281 value_.Update(boost::math::llround(value), GetPolicy()); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
284 virtual void UpdateInteger(int64_t value) ORTHANC_OVERRIDE |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
286 value_.Update(value, GetPolicy()); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
287 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
288 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
289 virtual void IncrementInteger(int64_t delta) ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
290 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
291 value_.Increment(delta); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
294 virtual MetricsDataType GetDataType() const ORTHANC_OVERRIDE |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
296 return MetricsDataType_Integer; |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
299 virtual bool HasValue() const ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
300 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
301 return value_.HasValue(); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
302 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
303 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
304 virtual const boost::posix_time::ptime& GetTime() const ORTHANC_OVERRIDE |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
306 return value_.GetTime(); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
307 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
308 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
309 virtual std::string FormatValue() const ORTHANC_OVERRIDE |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
310 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
311 return boost::lexical_cast<std::string>(value_.GetValue()); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 }; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 MetricsRegistry::~MetricsRegistry() |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 assert(it->second != NULL); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 delete it->second; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 |
4300 | 325 bool MetricsRegistry::IsEnabled() const |
326 { | |
327 return enabled_; | |
328 } | |
329 | |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 void MetricsRegistry::SetEnabled(bool enabled) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
333 boost::mutex::scoped_lock lock(mutex_); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
334 enabled_ = enabled; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
335 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
336 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
338 void MetricsRegistry::Register(const std::string& name, |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
339 MetricsUpdatePolicy policy, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
340 MetricsDataType type) |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
341 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
342 boost::mutex::scoped_lock lock(mutex_); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
343 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
344 if (content_.find(name) != content_.end()) |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
345 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
346 throw OrthancException(ErrorCode_BadSequenceOfCalls, "Cannot register twice the same metrics: " + name); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
348 else |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
349 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
350 GetItemInternal(name, policy, type); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
351 } |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
352 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
353 |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
354 |
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
355 MetricsRegistry::Item& MetricsRegistry::GetItemInternal(const std::string& name, |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
356 MetricsUpdatePolicy policy, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
357 MetricsDataType type) |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
358 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
359 Content::iterator found = content_.find(name); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
360 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 if (found == content_.end()) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
362 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
363 Item* item = NULL; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
364 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
365 switch (type) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
366 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
367 case MetricsDataType_Float: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
368 item = new FloatItem(policy); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
369 break; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
370 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
371 case MetricsDataType_Integer: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
372 item = new IntegerItem(policy); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
373 break; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
374 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
375 default: |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
376 throw OrthancException(ErrorCode_ParameterOutOfRange); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
377 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
378 |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
379 content_[name] = item; |
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
380 return *item; |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
382 else |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 assert(found->second != NULL); |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
385 return *found->second; |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
387 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 |
4300 | 389 MetricsRegistry::MetricsRegistry() : |
390 enabled_(true) | |
391 { | |
392 } | |
393 | |
394 | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
395 void MetricsRegistry::SetFloatValue(const std::string& name, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
396 float value, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
397 MetricsUpdatePolicy policy) |
4300 | 398 { |
399 // Inlining to avoid loosing time if metrics are disabled | |
400 if (enabled_) | |
401 { | |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
402 boost::mutex::scoped_lock lock(mutex_); |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
403 GetItemInternal(name, policy, MetricsDataType_Float).UpdateFloat(value); |
4300 | 404 } |
405 } | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
406 |
4300 | 407 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
408 void MetricsRegistry::SetIntegerValue(const std::string &name, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
409 int64_t value, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
410 MetricsUpdatePolicy policy) |
4300 | 411 { |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
412 // Inlining to avoid loosing time if metrics are disabled |
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
413 if (enabled_) |
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
414 { |
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
415 boost::mutex::scoped_lock lock(mutex_); |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
416 GetItemInternal(name, policy, MetricsDataType_Integer).UpdateInteger(value); |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
417 } |
4300 | 418 } |
419 | |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
420 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
421 void MetricsRegistry::IncrementIntegerValue(const std::string &name, |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
422 int64_t delta) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
423 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
424 // Inlining to avoid loosing time if metrics are disabled |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
425 if (enabled_) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
426 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
427 boost::mutex::scoped_lock lock(mutex_); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
428 GetItemInternal(name, MetricsUpdatePolicy_Directly, MetricsDataType_Integer).IncrementInteger(delta); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
429 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
430 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
431 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
432 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
433 MetricsUpdatePolicy MetricsRegistry::GetUpdatePolicy(const std::string& metrics) |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
434 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 boost::mutex::scoped_lock lock(mutex_); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
436 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
437 Content::const_iterator found = content_.find(metrics); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
438 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
439 if (found == content_.end()) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
440 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
441 throw OrthancException(ErrorCode_InexistentItem); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
442 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
443 else |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
444 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
445 assert(found->second != NULL); |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
446 return found->second->GetPolicy(); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
447 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
448 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
449 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
450 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
451 MetricsDataType MetricsRegistry::GetDataType(const std::string& metrics) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
452 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
453 boost::mutex::scoped_lock lock(mutex_); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
454 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
455 Content::const_iterator found = content_.find(metrics); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
456 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
457 if (found == content_.end()) |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
458 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
459 throw OrthancException(ErrorCode_InexistentItem); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
460 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
461 else |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
462 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
463 assert(found->second != NULL); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
464 return found->second->GetDataType(); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
465 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
466 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
467 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
468 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
469 void MetricsRegistry::ExportPrometheusText(std::string& s) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
470 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
471 // https://www.boost.org/doc/libs/1_69_0/doc/html/date_time/examples.html#date_time.examples.seconds_since_epoch |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
472 static const boost::posix_time::ptime EPOCH(boost::gregorian::date(1970, 1, 1)); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
473 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
474 boost::mutex::scoped_lock lock(mutex_); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
475 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
476 s.clear(); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
477 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
478 if (!enabled_) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
479 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
480 return; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
481 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
482 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
483 ChunkedBuffer buffer; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
484 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
485 for (Content::const_iterator it = content_.begin(); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
486 it != content_.end(); ++it) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
487 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
488 assert(it->second != NULL); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
489 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
490 if (it->second->HasValue()) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
491 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
492 boost::posix_time::time_duration diff = it->second->GetTime() - EPOCH; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
493 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
494 std::string line = (it->first + " " + |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
495 it->second->FormatValue() + " " + |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
496 boost::lexical_cast<std::string>(diff.total_milliseconds()) + "\n"); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
497 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
498 buffer.AddChunk(line); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
499 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
500 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
501 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
502 buffer.Flatten(s); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
503 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
504 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
505 |
4300 | 506 MetricsRegistry::SharedMetrics::SharedMetrics(MetricsRegistry ®istry, |
507 const std::string &name, | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
508 MetricsUpdatePolicy policy) : |
4300 | 509 registry_(registry), |
510 name_(name), | |
511 value_(0) | |
512 { | |
513 } | |
514 | |
5326
fbe857e942cd
store metrics as integers instead of floats to avoid precision loss in increments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
515 void MetricsRegistry::SharedMetrics::Add(int64_t delta) |
3176
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
516 { |
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
517 boost::mutex::scoped_lock lock(mutex_); |
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
518 value_ += delta; |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
519 registry_.SetIntegerValue(name_, value_); |
3176
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
520 } |
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
521 |
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
522 |
4300 | 523 MetricsRegistry::ActiveCounter::ActiveCounter(MetricsRegistry::SharedMetrics &metrics) : |
524 metrics_(metrics) | |
525 { | |
526 metrics_.Add(1); | |
527 } | |
528 | |
529 MetricsRegistry::ActiveCounter::~ActiveCounter() | |
530 { | |
531 metrics_.Add(-1); | |
532 } | |
533 | |
534 | |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
535 void MetricsRegistry::Timer::Start() |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
536 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
537 if (registry_.IsEnabled()) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
538 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
539 active_ = true; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
540 start_ = GetNow(); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
541 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
542 else |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
543 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
544 active_ = false; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
545 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
546 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
547 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
548 |
4300 | 549 MetricsRegistry::Timer::Timer(MetricsRegistry ®istry, |
550 const std::string &name) : | |
551 registry_(registry), | |
552 name_(name), | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
553 policy_(MetricsUpdatePolicy_MaxOver10Seconds) |
4300 | 554 { |
555 Start(); | |
556 } | |
557 | |
558 | |
559 MetricsRegistry::Timer::Timer(MetricsRegistry ®istry, | |
560 const std::string &name, | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
561 MetricsUpdatePolicy policy) : |
4300 | 562 registry_(registry), |
563 name_(name), | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
564 policy_(policy) |
4300 | 565 { |
566 Start(); | |
567 } | |
568 | |
569 | |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
570 MetricsRegistry::Timer::~Timer() |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
571 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
572 if (active_) |
4300 | 573 { |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
574 boost::posix_time::time_duration diff = GetNow() - start_; |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
575 registry_.SetIntegerValue(name_, static_cast<int64_t>(diff.total_milliseconds()), policy_); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
576 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
577 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
578 } |