annotate OrthancFramework/Sources/MetricsRegistry.cpp @ 5853:4d932683049d get-scu tip

very first implementation of C-Get SCU
author Alain Mazy <am@orthanc.team>
date Tue, 29 Oct 2024 17:25:49 +0100
parents 7fadeb395359
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
142 time_ = GetNow();
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
143
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
144 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
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 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
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 else
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 value_ = delta;
5791
7fadeb395359 fixed incremented metrics that were not published + added orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
151 hasValue_ = true;
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
152 }
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
155 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
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 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
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
160 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
161 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
162 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
163 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
164 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
165 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
166 else
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 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
169 }
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
172 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
173 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
174 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
175 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
176 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
177 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
178 else
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 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
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 };
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
184 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
185
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
186
5336
dd9795dc380d renamed MetricsType as MetricsUpdate to clarify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5335
diff changeset
187 class MetricsRegistry::Item : public boost::noncopyable
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 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
190 MetricsUpdatePolicy policy_;
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
192 public:
5344
f41e1f635c4d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
193 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
194 policy_(policy)
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
197
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
198 virtual ~Item()
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
202 MetricsUpdatePolicy GetPolicy() const
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
204 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
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
207 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
208
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
209 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
210
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
211 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
212
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
213 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
214
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
215 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
216
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
217 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
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 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
220 };
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
223 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
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 private:
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
226 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
227
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
228 public:
5344
f41e1f635c4d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
229 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
230 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
231 {
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
234 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
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 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
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
239 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
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 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
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
244 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
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 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
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
249 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
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 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
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
254 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
255 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
256 return value_.HasValue();
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
259 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
260 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
261 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
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
264 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
265 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
266 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
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 };
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
270
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
271 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
272 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
273 private:
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
274 TimestampedValue<int64_t> value_;
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
276 public:
5344
f41e1f635c4d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
277 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
278 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
279 {
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
282 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
283 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
284 value_.Update(boost::math::llround(value), GetPolicy());
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
287 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
288 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
289 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
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
292 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
293 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
294 value_.Increment(delta);
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
297 virtual MetricsDataType GetDataType() const ORTHANC_OVERRIDE
3174
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 return MetricsDataType_Integer;
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
302 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
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 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
305 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
306
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
307 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
308 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
309 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
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
312 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
313 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
314 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
315 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 };
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
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 MetricsRegistry::~MetricsRegistry()
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 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
322 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 assert(it->second != NULL);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 delete it->second;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
328 bool MetricsRegistry::IsEnabled() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
329 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
330 return enabled_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
331 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
332
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 void MetricsRegistry::SetEnabled(bool 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 boost::mutex::scoped_lock lock(mutex_);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 enabled_ = enabled;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 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
342 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
343 MetricsDataType type)
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 boost::mutex::scoped_lock lock(mutex_);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
347 if (content_.find(name) != content_.end())
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
349 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
350 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
353 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
354 }
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
357
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
358 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
359 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
360 MetricsDataType type)
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 Content::iterator found = content_.find(name);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 if (found == content_.end())
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
366 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
367
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
368 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
369 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
370 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
371 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
372 break;
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
373
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
374 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
375 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
376 break;
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 default:
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
379 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
380 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
381
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
382 content_[name] = item;
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
383 return *item;
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 else
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 assert(found->second != NULL);
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
388 return *found->second;
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
392 MetricsRegistry::MetricsRegistry() :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
393 enabled_(true)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
394 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
395 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
396
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
397
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
398 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
399 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
400 MetricsUpdatePolicy policy)
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
401 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
402 // Inlining to avoid loosing time if metrics are disabled
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
403 if (enabled_)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
404 {
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
405 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
406 GetItemInternal(name, policy, MetricsDataType_Float).UpdateFloat(value);
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
407 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
408 }
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
409
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
410
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
411 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
412 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
413 MetricsUpdatePolicy policy)
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
414 {
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
415 // Inlining to avoid loosing time if metrics are disabled
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
416 if (enabled_)
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
417 {
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
418 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
419 GetItemInternal(name, policy, MetricsDataType_Integer).UpdateInteger(value);
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
420 }
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
421 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
422
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
424 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
425 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
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 // 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
428 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
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 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
431 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
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 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
434
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
435
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
436 MetricsUpdatePolicy MetricsRegistry::GetUpdatePolicy(const std::string& metrics)
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 boost::mutex::scoped_lock lock(mutex_);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
440 Content::const_iterator found = content_.find(metrics);
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 if (found == content_.end())
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 throw OrthancException(ErrorCode_InexistentItem);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 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
449 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
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 }
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
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
454 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
455 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
456 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
457
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
458 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
459
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
460 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
461 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
462 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
463 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
464 else
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
465 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
466 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
467 return found->second->GetDataType();
3174
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 }
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
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 void MetricsRegistry::ExportPrometheusText(std::string& s)
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 // 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
475 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
476
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 boost::mutex::scoped_lock lock(mutex_);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 s.clear();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 if (!enabled_)
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 return;
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
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 ChunkedBuffer buffer;
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 for (Content::const_iterator it = content_.begin();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 it != content_.end(); ++it)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 assert(it->second != NULL);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 if (it->second->HasValue())
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 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
496
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 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
498 it->second->FormatValue() + " " +
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 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
500
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 buffer.AddChunk(line);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 }
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 buffer.Flatten(s);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
509 MetricsRegistry::SharedMetrics::SharedMetrics(MetricsRegistry &registry,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
510 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
511 MetricsUpdatePolicy policy) :
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
512 registry_(registry),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
513 name_(name),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
514 value_(0)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
515 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
516 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
517
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
518 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
519 {
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
520 boost::mutex::scoped_lock lock(mutex_);
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
521 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
522 registry_.SetIntegerValue(name_, value_);
3176
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
523 }
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
524
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
525
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
526 MetricsRegistry::ActiveCounter::ActiveCounter(MetricsRegistry::SharedMetrics &metrics) :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
527 metrics_(metrics)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
528 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
529 metrics_.Add(1);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
530 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
531
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
532 MetricsRegistry::ActiveCounter::~ActiveCounter()
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
533 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
534 metrics_.Add(-1);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
535 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
536
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
537
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 void MetricsRegistry::Timer::Start()
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 if (registry_.IsEnabled())
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 active_ = true;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 start_ = GetNow();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 else
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 active_ = false;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
552 MetricsRegistry::Timer::Timer(MetricsRegistry &registry,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
553 const std::string &name) :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
554 registry_(registry),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
555 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
556 policy_(MetricsUpdatePolicy_MaxOver10Seconds)
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
557 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
558 Start();
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
559 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
560
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
561
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
562 MetricsRegistry::Timer::Timer(MetricsRegistry &registry,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
563 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
564 MetricsUpdatePolicy policy) :
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
565 registry_(registry),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
566 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
567 policy_(policy)
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
568 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
569 Start();
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
570 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
571
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
572
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 MetricsRegistry::Timer::~Timer()
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 if (active_)
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
576 {
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 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
578 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
579 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 }