changeset 5111:7547c7dfd017

/tools/metrics-prometheus: added orthanc_last_change and orthanc_up_time_s
author Alain Mazy <am@osimis.io>
date Tue, 22 Nov 2022 18:01:23 +0100
parents 98da039474b1
children b89833d7ce22
files NEWS OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h
diffstat 4 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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++)
--- 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<float>(diskSize) / MEGA_BYTES);
     registry.SetValue("orthanc_uncompressed_size_mb", static_cast<float>(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);
 
--- 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();
+  }
+
 }
--- 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 <boost/date_time/posix_time/posix_time.hpp>
 
 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;
   };
 }