# HG changeset patch # User Alain Mazy # Date 1669136483 -3600 # Node ID 7547c7dfd0172c37447c9fc414a988a46b25f9e7 # Parent 98da039474b165350fb905505544ac34c73058ca /tools/metrics-prometheus: added orthanc_last_change and orthanc_up_time_s diff -r 98da039474b1 -r 7547c7dfd017 NEWS --- a/NEWS Tue Nov 22 16:30:50 2022 +0100 +++ b/NEWS Tue Nov 22 18:01:23 2022 +0100 @@ -24,6 +24,7 @@ * Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB) * /modalities/.../store now accepts "CalledAet", "Host", "Port" to override the modality configuration from the configuration file for a specific operation. +* /tools/metrics-prometheus: added orthanc_last_change and orthanc_up_time_s OrthancFramework (C++) diff -r 98da039474b1 -r 7547c7dfd017 OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp Tue Nov 22 16:30:50 2022 +0100 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp Tue Nov 22 18:01:23 2022 +0100 @@ -845,6 +845,10 @@ unsigned int jobsPending, jobsRunning, jobsSuccess, jobsFailed; context.GetJobsEngine().GetRegistry().GetStatistics(jobsPending, jobsRunning, jobsSuccess, jobsFailed); + int64_t serverUpTime = context.GetServerUpTime(); + Json::Value lastChange; + context.GetIndex().GetLastChange(lastChange); + 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); @@ -857,7 +861,9 @@ registry.SetValue("orthanc_jobs_completed", jobsSuccess + jobsFailed); registry.SetValue("orthanc_jobs_success", jobsSuccess); registry.SetValue("orthanc_jobs_failed", jobsFailed); - + registry.SetValue("orthanc_up_time_s", serverUpTime); + registry.SetValue("orthanc_last_change", lastChange["Last"].asInt64()); + std::string s; registry.ExportPrometheusText(s); diff -r 98da039474b1 -r 7547c7dfd017 OrthancServer/Sources/ServerContext.cpp --- a/OrthancServer/Sources/ServerContext.cpp Tue Nov 22 16:30:50 2022 +0100 +++ b/OrthancServer/Sources/ServerContext.cpp Tue Nov 22 18:01:23 2022 +0100 @@ -313,7 +313,8 @@ ingestTranscodingOfUncompressed_(true), ingestTranscodingOfCompressed_(true), preferredTransferSyntax_(DicomTransferSyntax_LittleEndianExplicit), - deidentifyLogs_(false) + deidentifyLogs_(false), + serverStartTimeUtc_(boost::posix_time::second_clock::universal_time()) { try { @@ -2490,4 +2491,12 @@ return true; } + int64_t ServerContext::GetServerUpTime() const + { + boost::posix_time::ptime nowUtc = boost::posix_time::second_clock::universal_time(); + boost::posix_time::time_duration elapsed = nowUtc - serverStartTimeUtc_; + + return elapsed.total_seconds(); + } + } diff -r 98da039474b1 -r 7547c7dfd017 OrthancServer/Sources/ServerContext.h --- a/OrthancServer/Sources/ServerContext.h Tue Nov 22 16:30:50 2022 +0100 +++ b/OrthancServer/Sources/ServerContext.h Tue Nov 22 18:01:23 2022 +0100 @@ -35,6 +35,7 @@ #include "../../OrthancFramework/Sources/FileStorage/StorageCache.h" #include "../../OrthancFramework/Sources/MultiThreading/Semaphore.h" +#include namespace Orthanc { @@ -276,6 +277,8 @@ DicomModification logsDeidentifierRules_; bool deidentifyLogs_; + boost::posix_time::ptime serverStartTimeUtc_; + public: class DicomCacheLocker : public boost::noncopyable { @@ -572,5 +575,7 @@ { return findStorageAccessMode_; } + + int64_t GetServerUpTime() const; }; }