# HG changeset patch # User Sebastien Jodogne # Date 1548781661 -3600 # Node ID 784bbb03fb54424d8961f4784f740950f6b54040 # Parent 574890d14c92cf4d933fd45eefa4401212742d2e new metrics: orthanc_rest_api_active_requests diff -r 574890d14c92 -r 784bbb03fb54 Core/MetricsRegistry.cpp --- a/Core/MetricsRegistry.cpp Tue Jan 29 17:34:09 2019 +0100 +++ b/Core/MetricsRegistry.cpp Tue Jan 29 18:07:41 2019 +0100 @@ -295,6 +295,14 @@ } + void MetricsRegistry::SharedMetrics::Add(float delta) + { + boost::mutex::scoped_lock lock(mutex_); + value_ += delta; + registry_.SetValue(name_, value_); + } + + void MetricsRegistry::Timer::Start() { if (registry_.IsEnabled()) diff -r 574890d14c92 -r 784bbb03fb54 Core/MetricsRegistry.h --- a/Core/MetricsRegistry.h Tue Jan 29 17:34:09 2019 +0100 +++ b/Core/MetricsRegistry.h Tue Jan 29 18:07:41 2019 +0100 @@ -111,6 +111,47 @@ void ExportPrometheusText(std::string& s); + class SharedMetrics : public boost::noncopyable + { + private: + boost::mutex mutex_; + MetricsRegistry& registry_; + std::string name_; + float value_; + + public: + SharedMetrics(MetricsRegistry& registry, + const std::string& name, + MetricsType type) : + registry_(registry), + name_(name), + value_(0) + { + } + + void Add(float delta); + }; + + + class ActiveCounter : public boost::noncopyable + { + private: + SharedMetrics& metrics_; + + public: + ActiveCounter(SharedMetrics& metrics) : + metrics_(metrics) + { + metrics_.Add(1); + } + + ~ActiveCounter() + { + metrics_.Add(-1); + } + }; + + class Timer : public boost::noncopyable { private: diff -r 574890d14c92 -r 784bbb03fb54 OrthancServer/OrthancRestApi/OrthancRestApi.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestApi.cpp Tue Jan 29 17:34:09 2019 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestApi.cpp Tue Jan 29 18:07:41 2019 +0100 @@ -137,7 +137,10 @@ OrthancRestApi::OrthancRestApi(ServerContext& context) : context_(context), leaveBarrier_(false), - resetRequestReceived_(false) + resetRequestReceived_(false), + activeRequests_(context.GetMetricsRegistry(), + "orthanc_rest_api_active_requests", + MetricsType_MaxOver10Seconds) { RegisterSystem(); @@ -169,6 +172,7 @@ size_t bodySize) { MetricsRegistry::Timer timer(context_.GetMetricsRegistry(), "orthanc_rest_api_duration_ms"); + MetricsRegistry::ActiveCounter counter(activeRequests_); return RestApi::Handle(output, origin, remoteIp, username, method, uri, headers, getArguments, bodyData, bodySize); diff -r 574890d14c92 -r 784bbb03fb54 OrthancServer/OrthancRestApi/OrthancRestApi.h --- a/OrthancServer/OrthancRestApi/OrthancRestApi.h Tue Jan 29 17:34:09 2019 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestApi.h Tue Jan 29 18:07:41 2019 +0100 @@ -33,9 +33,10 @@ #pragma once +#include "../../Core/DicomParsing/DicomModification.h" #include "../../Core/JobsEngine/SetOfCommandsJob.h" +#include "../../Core/MetricsRegistry.h" #include "../../Core/RestApi/RestApi.h" -#include "../../Core/DicomParsing/DicomModification.h" #include "../ServerEnumerations.h" #include @@ -52,9 +53,10 @@ typedef std::set SetOfStrings; private: - ServerContext& context_; - bool leaveBarrier_; - bool resetRequestReceived_; + ServerContext& context_; + bool leaveBarrier_; + bool resetRequestReceived_; + MetricsRegistry::SharedMetrics activeRequests_; void RegisterSystem();