annotate OrthancFramework/Sources/MetricsRegistry.cpp @ 5334:5b2a5cc64cb1

upgraded anonymization to Basic Profile of PS 3.15-2023b Table E.1-1
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Jun 2023 15:12:39 +0200
parents fbe857e942cd
children c103b0e70d75
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
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * 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
12 *
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * 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
15 * 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
16 * Lesser General Public License for more details.
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
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
18 * 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
19 * 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
20 * <http://www.gnu.org/licenses/>.
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
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 #include "PrecompiledHeaders.h"
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "MetricsRegistry.h"
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
27 #include "ChunkedBuffer.h"
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
28 #include "Compatibility.h"
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "OrthancException.h"
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace Orthanc
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 static const boost::posix_time::ptime GetNow()
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
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
35 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
36 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 class MetricsRegistry::Item
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 private:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 MetricsType type_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 boost::posix_time::ptime time_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 bool hasValue_;
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
44 int64_t value_;
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
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
46 void Touch(int64_t value,
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 const boost::posix_time::ptime& now)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 hasValue_ = true;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 value_ = value;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 time_ = now;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
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
54 void Touch(int64_t value)
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 Touch(value, GetNow());
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
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
59 void UpdateMax(int64_t value,
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 int duration)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 if (hasValue_)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 const boost::posix_time::ptime now = GetNow();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 if (value > value_ ||
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 (now - time_).total_seconds() > duration)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 Touch(value, now);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 Touch(value);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
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
78 void UpdateMin(int64_t value,
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 int duration)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 if (hasValue_)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 const boost::posix_time::ptime now = GetNow();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 if (value < value_ ||
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 (now - time_).total_seconds() > duration)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 Touch(value, now);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 Touch(value);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 public:
4203
4d42408da117 improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4202
diff changeset
98 explicit Item(MetricsType type) :
4202
2007ab69ac16 moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
99 type_(type),
2007ab69ac16 moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
100 hasValue_(false),
2007ab69ac16 moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
101 value_(0)
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 MetricsType GetType() const
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return type_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
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
110 void Update(int64_t value)
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 switch (type_)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 case MetricsType_Default:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 Touch(value);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 break;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 case MetricsType_MaxOver10Seconds:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 UpdateMax(value, 10);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 break;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 case MetricsType_MaxOver1Minute:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 UpdateMax(value, 60);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 break;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 case MetricsType_MinOver10Seconds:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 UpdateMin(value, 10);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 break;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 case MetricsType_MinOver1Minute:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 UpdateMin(value, 60);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 break;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 default:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 throw OrthancException(ErrorCode_NotImplemented);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 bool HasValue() const
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 return hasValue_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 const boost::posix_time::ptime& GetTime() const
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 if (hasValue_)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 return time_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 throw OrthancException(ErrorCode_BadSequenceOfCalls);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
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
156 int64_t GetValue() const
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 if (hasValue_)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 return value_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 throw OrthancException(ErrorCode_BadSequenceOfCalls);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 };
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 MetricsRegistry::~MetricsRegistry()
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 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
173 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 assert(it->second != NULL);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 delete it->second;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
179 bool MetricsRegistry::IsEnabled() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
180 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
181 return enabled_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
182 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
183
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 void MetricsRegistry::SetEnabled(bool enabled)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 boost::mutex::scoped_lock lock(mutex_);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 enabled_ = enabled;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 void MetricsRegistry::Register(const std::string& name,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 MetricsType type)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 boost::mutex::scoped_lock lock(mutex_);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 Content::iterator found = content_.find(name);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 if (found == content_.end())
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 content_[name] = new Item(type);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 assert(found->second != NULL);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 // This metrics already exists: Only recreate it if there is a
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 // mismatch in the type of metrics
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 if (found->second->GetType() != type)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 delete found->second;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 found->second = new Item(type);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
217
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
218 MetricsRegistry::Item& MetricsRegistry::GetItemInternal(const std::string& name,
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
219 MetricsType type)
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 Content::iterator found = content_.find(name);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 if (found == content_.end())
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 {
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
225 Item* item = new Item(type);
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
226 content_[name] = item;
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
227 return *item;
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 assert(found->second != NULL);
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
232 return *found->second;
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
236 MetricsRegistry::MetricsRegistry() :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
237 enabled_(true)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
238 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
239 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
240
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
241
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
242 void MetricsRegistry::SetValue(const std::string &name,
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
243 int64_t value,
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
244 MetricsType type)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
245 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
246 // Inlining to avoid loosing time if metrics are disabled
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
247 if (enabled_)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
248 {
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
249 boost::mutex::scoped_lock lock(mutex_);
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
250 GetItemInternal(name, type).Update(value);
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
251 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
252 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
253
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
254
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
255 void MetricsRegistry::IncrementValue(const std::string &name,
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
256 int64_t delta)
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
257 {
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
258 // Inlining to avoid loosing time if metrics are disabled
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
259 if (enabled_)
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
260 {
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
261 boost::mutex::scoped_lock lock(mutex_);
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
262 Item& item = GetItemInternal(name, MetricsType_Default);
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
263
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
264 if (item.HasValue())
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
265 {
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
266 item.Update(item.GetValue() + delta);
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
267 }
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
268 else
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
269 {
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
270 item.Update(delta);
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
271 }
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
272 }
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
273 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
274
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 MetricsType MetricsRegistry::GetMetricsType(const std::string& name)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 boost::mutex::scoped_lock lock(mutex_);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 Content::const_iterator found = content_.find(name);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 if (found == content_.end())
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 throw OrthancException(ErrorCode_InexistentItem);
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 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 assert(found->second != NULL);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 return found->second->GetType();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 void MetricsRegistry::ExportPrometheusText(std::string& s)
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 // 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
297 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
298
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 boost::mutex::scoped_lock lock(mutex_);
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 s.clear();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 if (!enabled_)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 return;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 ChunkedBuffer buffer;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 for (Content::const_iterator it = content_.begin();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 it != content_.end(); ++it)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 assert(it->second != NULL);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 if (it->second->HasValue())
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 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
318
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 std::string line = (it->first + " " +
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 boost::lexical_cast<std::string>(it->second->GetValue()) + " " +
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 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
322
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 buffer.AddChunk(line);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 }
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 buffer.Flatten(s);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
331 MetricsRegistry::SharedMetrics::SharedMetrics(MetricsRegistry &registry,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
332 const std::string &name,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
333 MetricsType type) :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
334 registry_(registry),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
335 name_(name),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
336 value_(0)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
337 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
338 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
339
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
340 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
341 {
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
342 boost::mutex::scoped_lock lock(mutex_);
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
343 value_ += delta;
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
344 registry_.SetValue(name_, value_);
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
345 }
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
346
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3175
diff changeset
347
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
348 MetricsRegistry::ActiveCounter::ActiveCounter(MetricsRegistry::SharedMetrics &metrics) :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
349 metrics_(metrics)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
350 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
351 metrics_.Add(1);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
352 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
353
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
354 MetricsRegistry::ActiveCounter::~ActiveCounter()
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
355 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
356 metrics_.Add(-1);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
357 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
358
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
359
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 void MetricsRegistry::Timer::Start()
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 if (registry_.IsEnabled())
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 active_ = true;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 start_ = GetNow();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 else
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 active_ = false;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
374 MetricsRegistry::Timer::Timer(MetricsRegistry &registry,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
375 const std::string &name) :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
376 registry_(registry),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
377 name_(name),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
378 type_(MetricsType_MaxOver10Seconds)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
379 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
380 Start();
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
381 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
382
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
383
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
384 MetricsRegistry::Timer::Timer(MetricsRegistry &registry,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
385 const std::string &name,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
386 MetricsType type) :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
387 registry_(registry),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
388 name_(name),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
389 type_(type)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
390 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
391 Start();
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
392 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
393
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
394
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 MetricsRegistry::Timer::~Timer()
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 if (active_)
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
398 {
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 boost::posix_time::time_duration diff = GetNow() - start_;
3378
596cfabd72c5 Fixed a couple of truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3176
diff changeset
400 registry_.SetValue(
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
401 name_, static_cast<int64_t>(diff.total_milliseconds()), type_);
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 }