annotate Core/MetricsRegistry.h @ 3848:44bfcfdf42e8 transcoding

integration mainline->transcoding
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 20 Apr 2020 14:04:14 +0200
parents 94f4a18a79cc
children f9863630ec7f
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
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3176
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
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 * 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
25 * 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
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
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
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #pragma once
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 #if !defined(ORTHANC_SANDBOXED)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 # error The macro ORTHANC_SANDBOXED must be defined
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #endif
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 #if ORTHANC_SANDBOXED == 1
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 # error The class MetricsRegistry cannot be used in sandboxed environments
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #endif
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include <boost/thread/mutex.hpp>
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include <boost/date_time/posix_time/posix_time.hpp>
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 namespace Orthanc
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 enum MetricsType
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 MetricsType_Default,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 MetricsType_MaxOver10Seconds,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 MetricsType_MaxOver1Minute,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 MetricsType_MinOver10Seconds,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 MetricsType_MinOver1Minute
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 };
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 class MetricsRegistry : public boost::noncopyable
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 private:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 class Item;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 typedef std::map<std::string, Item*> Content;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 bool enabled_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 boost::mutex mutex_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 Content content_;
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 void SetValueInternal(const std::string& name,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 float value,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 MetricsType type);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 public:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 MetricsRegistry() :
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 enabled_(true)
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 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ~MetricsRegistry();
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 bool IsEnabled() const
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 return enabled_;
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
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 void SetEnabled(bool enabled);
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 void Register(const std::string& name,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 MetricsType type);
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 void SetValue(const std::string& name,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 float value,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 MetricsType type)
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 // Inlining to avoid loosing time if metrics are disabled
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 if (enabled_)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 SetValueInternal(name, value, type);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 void SetValue(const std::string& name,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 float value)
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 SetValue(name, value, MetricsType_Default);
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
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 MetricsType GetMetricsType(const std::string& name);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 // https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 void ExportPrometheusText(std::string& s);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
3176
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
114 class SharedMetrics : public boost::noncopyable
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
115 {
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
116 private:
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
117 boost::mutex mutex_;
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
118 MetricsRegistry& registry_;
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
119 std::string name_;
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
120 float value_;
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
121
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
122 public:
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
123 SharedMetrics(MetricsRegistry& registry,
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
124 const std::string& name,
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
125 MetricsType type) :
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
126 registry_(registry),
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
127 name_(name),
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
128 value_(0)
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
129 {
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
130 }
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
131
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
132 void Add(float delta);
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
133 };
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
134
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
135
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
136 class ActiveCounter : public boost::noncopyable
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
137 {
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
138 private:
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
139 SharedMetrics& metrics_;
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
140
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
141 public:
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
142 ActiveCounter(SharedMetrics& metrics) :
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
143 metrics_(metrics)
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
144 {
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
145 metrics_.Add(1);
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
146 }
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
147
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
148 ~ActiveCounter()
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
149 {
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
150 metrics_.Add(-1);
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
151 }
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
152 };
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
153
784bbb03fb54 new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
154
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 class Timer : public boost::noncopyable
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 private:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 MetricsRegistry& registry_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 std::string name_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 MetricsType type_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 bool active_;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 boost::posix_time::ptime start_;
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 void Start();
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 public:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 Timer(MetricsRegistry& registry,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 const std::string& name) :
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 registry_(registry),
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 name_(name),
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 type_(MetricsType_MaxOver10Seconds)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 Start();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 Timer(MetricsRegistry& registry,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 const std::string& name,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 MetricsType type) :
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 registry_(registry),
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 name_(name),
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 type_(type)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 Start();
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
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 ~Timer();
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 };
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 }