# HG changeset patch # User Alain Mazy # Date 1700559162 -3600 # Node ID 4be5f117aa0d0456833da01aca3236b150b089b4 # Parent b83192e7ad10db33330ac200b6cbd297aa6739cc metrics diff -r b83192e7ad10 -r 4be5f117aa0d NEWS --- a/NEWS Mon Nov 20 17:01:48 2023 +0100 +++ b/NEWS Tue Nov 21 10:32:42 2023 +0100 @@ -45,6 +45,9 @@ * All 'expand' GET arguments now accepts expand=true and expand=false values. The /studies/../instances and sibling routes are the only whose expand is true if not specified. These routes now accepts expand=false to simply list the child resources ids. +* In /tools/metrics-prometheus: + - 'orthanc_dicom_cache_size' renamed into 'orthanc_dicom_cache_size_mb' + - added 'orthanc_storage_cache_count' and 'orthanc_storage_cache_size_mb' Maintenance diff -r b83192e7ad10 -r 4be5f117aa0d OrthancFramework/Sources/Cache/MemoryStringCache.cpp --- a/OrthancFramework/Sources/Cache/MemoryStringCache.cpp Mon Nov 20 17:01:48 2023 +0100 +++ b/OrthancFramework/Sources/Cache/MemoryStringCache.cpp Tue Nov 21 10:32:42 2023 +0100 @@ -268,6 +268,20 @@ } // Post-condition: "currentSize_ <= targetSize" + } + + size_t MemoryStringCache::GetCurrentSize() const + { + boost::mutex::scoped_lock cacheLock(cacheMutex_); + + return currentSize_; + } + + size_t MemoryStringCache::GetNumberOfItems() const + { + boost::mutex::scoped_lock cacheLock(cacheMutex_); + return content_.GetSize(); } + } diff -r b83192e7ad10 -r 4be5f117aa0d OrthancFramework/Sources/Cache/MemoryStringCache.h --- a/OrthancFramework/Sources/Cache/MemoryStringCache.h Mon Nov 20 17:01:48 2023 +0100 +++ b/OrthancFramework/Sources/Cache/MemoryStringCache.h Tue Nov 21 10:32:42 2023 +0100 @@ -70,7 +70,7 @@ private: class StringValue; - boost::mutex cacheMutex_; // note: we can not use recursive_mutex with condition_variable + mutable boost::mutex cacheMutex_; // note: we can not use recursive_mutex with condition_variable boost::condition_variable cacheCond_; std::set itemsBeingLoaded_; @@ -91,6 +91,10 @@ void Invalidate(const std::string& key); + size_t GetCurrentSize() const; + + size_t GetNumberOfItems() const; + private: void Add(const std::string& key, const std::string& value); diff -r b83192e7ad10 -r 4be5f117aa0d OrthancFramework/Sources/FileStorage/StorageCache.cpp --- a/OrthancFramework/Sources/FileStorage/StorageCache.cpp Mon Nov 20 17:01:48 2023 +0100 +++ b/OrthancFramework/Sources/FileStorage/StorageCache.cpp Tue Nov 21 10:32:42 2023 +0100 @@ -185,4 +185,16 @@ return false; } + + + size_t StorageCache::GetCurrentSize() const + { + return cache_.GetCurrentSize(); + } + + size_t StorageCache::GetNumberOfItems() const + { + return cache_.GetNumberOfItems(); + } + } diff -r b83192e7ad10 -r 4be5f117aa0d OrthancFramework/Sources/FileStorage/StorageCache.h --- a/OrthancFramework/Sources/FileStorage/StorageCache.h Mon Nov 20 17:01:48 2023 +0100 +++ b/OrthancFramework/Sources/FileStorage/StorageCache.h Tue Nov 21 10:32:42 2023 +0100 @@ -93,6 +93,10 @@ void Invalidate(const std::string& uuid, FileContentType contentType); + size_t GetCurrentSize() const; + + size_t GetNumberOfItems() const; + private: void Add(const std::string& uuid, FileContentType contentType, diff -r b83192e7ad10 -r 4be5f117aa0d OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp Mon Nov 20 17:01:48 2023 +0100 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp Tue Nov 21 10:32:42 2023 +0100 @@ -955,6 +955,8 @@ registry.SetIntegerValue("orthanc_up_time_s", serverUpTime); registry.SetIntegerValue("orthanc_last_change", lastChange["Last"].asInt64()); + context.PublishCacheMetrics(); + std::string s; registry.ExportPrometheusText(s); diff -r b83192e7ad10 -r 4be5f117aa0d OrthancServer/Sources/ServerContext.cpp --- a/OrthancServer/Sources/ServerContext.cpp Mon Nov 20 17:01:48 2023 +0100 +++ b/OrthancServer/Sources/ServerContext.cpp Tue Nov 21 10:32:42 2023 +0100 @@ -328,11 +328,15 @@ } - void ServerContext::PublishDicomCacheMetrics() + void ServerContext::PublishCacheMetrics() { - metricsRegistry_->SetFloatValue("orthanc_dicom_cache_size", + metricsRegistry_->SetFloatValue("orthanc_dicom_cache_size_mb", static_cast(dicomCache_.GetCurrentSize()) / static_cast(1024 * 1024)); metricsRegistry_->SetIntegerValue("orthanc_dicom_cache_count", dicomCache_.GetNumberOfItems()); + + metricsRegistry_->SetFloatValue("orthanc_storage_cache_size_mb", + static_cast(storageCache_.GetCurrentSize()) / static_cast(1024 * 1024)); + metricsRegistry_->SetIntegerValue("orthanc_storage_cache_count", storageCache_.GetNumberOfItems()); } @@ -668,7 +672,6 @@ // Remove the file from the DicomCache (useful if // "OverwriteInstances" is set to "true") dicomCache_.Invalidate(resultPublicId); - PublishDicomCacheMetrics(); // TODO Should we use "gzip" instead? CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None); @@ -1328,7 +1331,6 @@ try { context_.dicomCache_.Acquire(instancePublicId_, dicom_.release(), dicomSize_); - context_.PublishDicomCacheMetrics(); } catch (OrthancException&) { @@ -1406,7 +1408,6 @@ { // remove the file from the DicomCache dicomCache_.Invalidate(uuid); - PublishDicomCacheMetrics(); } return index_.DeleteResource(remainingAncestor, uuid, expectedType); @@ -1419,7 +1420,6 @@ change.GetChangeType() == ChangeType_Deleted) { dicomCache_.Invalidate(change.GetPublicId()); - PublishDicomCacheMetrics(); } pendingChanges_.Enqueue(change.Clone()); diff -r b83192e7ad10 -r 4be5f117aa0d OrthancServer/Sources/ServerContext.h --- a/OrthancServer/Sources/ServerContext.h Mon Nov 20 17:01:48 2023 +0100 +++ b/OrthancServer/Sources/ServerContext.h Tue Nov 21 10:32:42 2023 +0100 @@ -282,8 +282,6 @@ StoreInstanceMode mode, bool isReconstruct); - void PublishDicomCacheMetrics(); - // This method must only be called from "ServerIndex"! void RemoveFile(const std::string& fileUuid, FileContentType type); @@ -615,5 +613,7 @@ } int64_t GetServerUpTime() const; + + void PublishCacheMetrics(); }; }