diff OrthancServer/Sources/ServerContext.cpp @ 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 e69a3ff39bc5
children 19ccae2e0371
line wrap: on
line diff
--- 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();
+  }
+
 }