# HG changeset patch # User Sebastien Jodogne # Date 1548840252 -3600 # Node ID 053e72ff9fc57ca149580c9f0368ca321b2910b2 # Parent 784bbb03fb54424d8961f4784f740950f6b54040 new metrics: orthanc_jobs_[pending|running|completed] diff -r 784bbb03fb54 -r 053e72ff9fc5 Core/JobsEngine/JobsRegistry.cpp --- a/Core/JobsEngine/JobsRegistry.cpp Tue Jan 29 18:07:41 2019 +0100 +++ b/Core/JobsEngine/JobsRegistry.cpp Wed Jan 30 10:24:12 2019 +0100 @@ -1398,4 +1398,44 @@ } } } + + + void JobsRegistry::GetStatistics(unsigned int& pending, + unsigned int& running, + unsigned int& completed) + { + boost::mutex::scoped_lock lock(mutex_); + CheckInvariants(); + + pending = 0; + running = 0; + completed = 0; + + for (JobsIndex::const_iterator it = jobsIndex_.begin(); + it != jobsIndex_.end(); ++it) + { + JobHandler& job = *it->second; + + switch (job.GetState()) + { + case JobState_Retry: + case JobState_Paused: + case JobState_Pending: + pending ++; + break; + + case JobState_Running: + running ++; + break; + + case JobState_Success: + case JobState_Failure: + completed ++; + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + } + } } diff -r 784bbb03fb54 -r 053e72ff9fc5 Core/JobsEngine/JobsRegistry.h --- a/Core/JobsEngine/JobsRegistry.h Tue Jan 29 18:07:41 2019 +0100 +++ b/Core/JobsEngine/JobsRegistry.h Wed Jan 30 10:24:12 2019 +0100 @@ -199,6 +199,10 @@ void ResetObserver(); + void GetStatistics(unsigned int& pending, + unsigned int& running, + unsigned int& completed); + class RunningJob : public boost::noncopyable { private: diff -r 784bbb03fb54 -r 053e72ff9fc5 OrthancServer/OrthancRestApi/OrthancRestSystem.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Tue Jan 29 18:07:41 2019 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Wed Jan 30 10:24:12 2019 +0100 @@ -407,22 +407,27 @@ static void GetMetricsPrometheus(RestApiGetCall& call) { - static const uint64_t MEGA_BYTES = 1024 * 1024; + static const float MEGA_BYTES = 1024 * 1024; ServerContext& context = OrthancRestApi::GetContext(call); - MetricsRegistry& registry = context.GetMetricsRegistry(); - uint64_t diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances; context.GetIndex().GetGlobalStatistics(diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances); - registry.SetValue("orthanc_disk_size_mb", static_cast(diskSize / MEGA_BYTES)); - registry.SetValue("orthanc_uncompressed_size_mb", static_cast(diskSize / MEGA_BYTES)); + unsigned int jobsPending, jobsRunning, jobsCompleted; + context.GetJobsEngine().GetRegistry().GetStatistics(jobsPending, jobsRunning, jobsCompleted); + + MetricsRegistry& registry = context.GetMetricsRegistry(); + registry.SetValue("orthanc_disk_size_mb", static_cast(diskSize) / MEGA_BYTES); + registry.SetValue("orthanc_uncompressed_size_mb", static_cast(diskSize) / MEGA_BYTES); registry.SetValue("orthanc_count_patients", static_cast(countPatients)); registry.SetValue("orthanc_count_studies", static_cast(countStudies)); registry.SetValue("orthanc_count_series", static_cast(countSeries)); registry.SetValue("orthanc_count_instances", static_cast(countInstances)); + registry.SetValue("orthanc_jobs_pending", jobsPending); + registry.SetValue("orthanc_jobs_running", jobsRunning); + registry.SetValue("orthanc_jobs_completed", jobsCompleted); std::string s; registry.ExportPrometheusText(s);