# HG changeset patch # User Sebastien Jodogne # Date 1354288164 -3600 # Node ID e4148b0ab1d05c42cd7e02e9ebf4764b8bc20405 # Parent 16a4ac70bd8a69858289d6bbc70f2e9b45266738 statistics URI diff -r 16a4ac70bd8a -r e4148b0ab1d0 NEWS --- a/NEWS Fri Nov 30 15:45:15 2012 +0100 +++ b/NEWS Fri Nov 30 16:09:24 2012 +0100 @@ -15,6 +15,7 @@ Minor changes ------------- +* "/statistics" URI * "last" flag to retrieve the last change from the "/changes" URI * Generate a sample configuration file from command line * "CompletedSeries" event in the changes API diff -r 16a4ac70bd8a -r e4148b0ab1d0 OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Fri Nov 30 15:45:15 2012 +0100 +++ b/OrthancServer/DatabaseWrapper.cpp Fri Nov 30 16:09:24 2012 +0100 @@ -739,4 +739,21 @@ db_.Register(signalRemainingAncestor_); db_.Register(new Internals::SignalFileDeleted(listener_)); } + + uint64_t DatabaseWrapper::GetResourceCount(ResourceType resourceType) + { + SQLite::Statement s(db_, SQLITE_FROM_HERE, + "SELECT COUNT(*) FROM Resources WHERE resourceType=?"); + s.BindInt(0, resourceType); + + if (!s.Step()) + { + throw OrthancException(ErrorCode_InternalError); + } + + int64_t c = s.ColumnInt(0); + assert(!s.Step()); + + return c; + } } diff -r 16a4ac70bd8a -r e4148b0ab1d0 OrthancServer/DatabaseWrapper.h --- a/OrthancServer/DatabaseWrapper.h Fri Nov 30 15:45:15 2012 +0100 +++ b/OrthancServer/DatabaseWrapper.h Fri Nov 30 16:09:24 2012 +0100 @@ -167,12 +167,15 @@ void GetLastExportedResource(Json::Value& target); + // For unit testing only! int64_t GetTableRecordCount(const std::string& table); uint64_t GetTotalCompressedSize(); uint64_t GetTotalUncompressedSize(); + uint64_t GetResourceCount(ResourceType resourceType); + void GetAllPublicIds(Json::Value& target, ResourceType resourceType); diff -r 16a4ac70bd8a -r e4148b0ab1d0 OrthancServer/OrthancRestApi.cpp --- a/OrthancServer/OrthancRestApi.cpp Fri Nov 30 15:45:15 2012 +0100 +++ b/OrthancServer/OrthancRestApi.cpp Fri Nov 30 16:09:24 2012 +0100 @@ -296,15 +296,19 @@ static void GetSystemInformation(RestApi::GetCall& call) { RETRIEVE_CONTEXT(call); + Json::Value result = Json::objectValue; - Json::Value result = Json::objectValue; result["Version"] = ORTHANC_VERSION; result["Name"] = GetGlobalStringParameter("Name", ""); - result["TotalCompressedSize"] = boost::lexical_cast - (context.GetIndex().GetTotalCompressedSize()); - result["TotalUncompressedSize"] = boost::lexical_cast - (context.GetIndex().GetTotalUncompressedSize()); + + call.GetOutput().AnswerJson(result); + } + static void GetStatistics(RestApi::GetCall& call) + { + RETRIEVE_CONTEXT(call); + Json::Value result = Json::objectValue; + context.GetIndex().ComputeStatistics(result); call.GetOutput().AnswerJson(result); } @@ -631,6 +635,7 @@ Register("/", ServeRoot); Register("/system", GetSystemInformation); + Register("/statistics", GetStatistics); Register("/changes", GetChanges); Register("/exports", GetExports); diff -r 16a4ac70bd8a -r e4148b0ab1d0 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Fri Nov 30 15:45:15 2012 +0100 +++ b/OrthancServer/ServerIndex.cpp Fri Nov 30 16:09:24 2012 +0100 @@ -350,17 +350,24 @@ } - uint64_t ServerIndex::GetTotalCompressedSize() + void ServerIndex::ComputeStatistics(Json::Value& target) { boost::mutex::scoped_lock lock(mutex_); - return db_->GetTotalCompressedSize(); - } + target = Json::objectValue; - uint64_t ServerIndex::GetTotalUncompressedSize() - { - boost::mutex::scoped_lock lock(mutex_); - return db_->GetTotalUncompressedSize(); - } + uint64_t cs = db_->GetTotalCompressedSize(); + uint64_t us = db_->GetTotalUncompressedSize(); + target["TotalDiskSize"] = boost::lexical_cast(cs); + target["TotalUncompressedSize"] = boost::lexical_cast(us); + target["TotalDiskSizeMB"] = boost::lexical_cast(cs / (1024llu * 1024llu)); + target["TotalUncompressedSizeMB"] = boost::lexical_cast(us / (1024llu * 1024llu)); + + target["CountPatients"] = static_cast(db_->GetResourceCount(ResourceType_Patient)); + target["CountStudies"] = static_cast(db_->GetResourceCount(ResourceType_Study)); + target["CountSeries"] = static_cast(db_->GetResourceCount(ResourceType_Series)); + target["CountInstances"] = static_cast(db_->GetResourceCount(ResourceType_Instance)); + } + SeriesStatus ServerIndex::GetSeriesStatus(int id) diff -r 16a4ac70bd8a -r e4148b0ab1d0 OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Fri Nov 30 15:45:15 2012 +0100 +++ b/OrthancServer/ServerIndex.h Fri Nov 30 16:09:24 2012 +0100 @@ -79,9 +79,7 @@ const Attachments& attachments, const std::string& remoteAet); - uint64_t GetTotalCompressedSize(); - - uint64_t GetTotalUncompressedSize(); + void ComputeStatistics(Json::Value& target); bool LookupResource(Json::Value& result, const std::string& publicId,