aboutsummaryrefslogtreecommitdiff
path: root/zenserver
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-10-12 14:46:10 +0200
committerMartin Ridgers <[email protected]>2021-10-12 14:46:10 +0200
commit7afea60028346eaff55deaf4f4ddbd213a265e4d (patch)
treee17d8e1d1ec2a0013df10994db28929a86189568 /zenserver
parentAdded "xmake project" output to .gitignore (diff)
parentRatios should not be percentages (this should be done in presentation) (diff)
downloadzen-7afea60028346eaff55deaf4f4ddbd213a265e4d.tar.xz
zen-7afea60028346eaff55deaf4f4ddbd213a265e4d.zip
Merged main
Diffstat (limited to 'zenserver')
-rw-r--r--zenserver/cache/structuredcache.cpp12
-rw-r--r--zenserver/monitoring/httpstats.cpp16
-rw-r--r--zenserver/monitoring/httpstats.h1
-rw-r--r--zenserver/monitoring/httpstatus.cpp16
-rw-r--r--zenserver/monitoring/httpstatus.h1
-rw-r--r--zenserver/upstream/upstreamcache.cpp4
6 files changed, 40 insertions, 10 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index 4a2a3748a..35cb02cbb 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -161,13 +161,16 @@ HttpStructuredCacheService::HttpStructuredCacheService(ZenCacheStore& InCac
, m_CidStore(InCidStore)
, m_UpstreamCache(std::move(UpstreamCache))
{
- StatsService.RegisterHandler("z$", *this);
- StatusService.RegisterHandler("z$", *this);
+ m_StatsService.RegisterHandler("z$", *this);
+ m_StatusService.RegisterHandler("z$", *this);
}
HttpStructuredCacheService::~HttpStructuredCacheService()
{
ZEN_INFO("closing structured cache");
+
+ m_StatsService.UnregisterHandler("z$", *this);
+ m_StatusService.UnregisterHandler("z$", *this);
}
const char*
@@ -275,6 +278,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(HttpServerRequest& Request,
HandleGetCacheRecord(Request, Ref, Policy);
}
break;
+
case kPut:
HandlePutCacheRecord(Request, Ref, Policy);
break;
@@ -883,9 +887,9 @@ HttpStructuredCacheService::HandleStatsRequest(zen::HttpServerRequest& Request)
Cbo.BeginObject("cache");
Cbo << "hits" << HitCount << "misses" << MissCount;
- Cbo << "hit_ratio" << (TotalCount > 0 ? (double(HitCount) / double(TotalCount) * 100.0) : 0.0);
+ Cbo << "hit_ratio" << (TotalCount > 0 ? (double(HitCount) / double(TotalCount)) : 0.0);
Cbo << "upstream_hits" << m_CacheStats.UpstreamHitCount;
- Cbo << "upstream_ratio" << (HitCount > 0 ? (double(UpstreamHitCount) / double(HitCount)) * 100.0 : 0.0);
+ Cbo << "upstream_ratio" << (HitCount > 0 ? (double(UpstreamHitCount) / double(HitCount)) : 0.0);
Cbo.EndObject();
if (m_UpstreamCache)
diff --git a/zenserver/monitoring/httpstats.cpp b/zenserver/monitoring/httpstats.cpp
index de04294d0..4d985f8c2 100644
--- a/zenserver/monitoring/httpstats.cpp
+++ b/zenserver/monitoring/httpstats.cpp
@@ -26,6 +26,15 @@ HttpStatsService::RegisterHandler(std::string_view Id, IHttpStatsProvider& Provi
}
void
+HttpStatsService::UnregisterHandler(std::string_view Id, IHttpStatsProvider& Provider)
+{
+ ZEN_UNUSED(Provider);
+
+ RwLock::ExclusiveLockScope _(m_Lock);
+ m_Providers.erase(std::string(Id));
+}
+
+void
HttpStatsService::HandleRequest(HttpServerRequest& Request)
{
using namespace std::literals;
@@ -36,9 +45,12 @@ HttpStatsService::HandleRequest(HttpServerRequest& Request)
{
case HttpVerb::kHead:
case HttpVerb::kGet:
- if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers))
{
- return It->second->HandleStatsRequest(Request);
+ RwLock::SharedLockScope _(m_Lock);
+ if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers))
+ {
+ return It->second->HandleStatsRequest(Request);
+ }
}
[[fallthrough]];
diff --git a/zenserver/monitoring/httpstats.h b/zenserver/monitoring/httpstats.h
index 1c3c79dd0..732815a9a 100644
--- a/zenserver/monitoring/httpstats.h
+++ b/zenserver/monitoring/httpstats.h
@@ -23,6 +23,7 @@ public:
virtual const char* BaseUri() const override;
virtual void HandleRequest(HttpServerRequest& Request) override;
void RegisterHandler(std::string_view Id, IHttpStatsProvider& Provider);
+ void UnregisterHandler(std::string_view Id, IHttpStatsProvider& Provider);
private:
spdlog::logger& m_Log;
diff --git a/zenserver/monitoring/httpstatus.cpp b/zenserver/monitoring/httpstatus.cpp
index e12662b1c..8b10601dd 100644
--- a/zenserver/monitoring/httpstatus.cpp
+++ b/zenserver/monitoring/httpstatus.cpp
@@ -26,6 +26,15 @@ HttpStatusService::RegisterHandler(std::string_view Id, IHttpStatusProvider& Pro
}
void
+HttpStatusService::UnregisterHandler(std::string_view Id, IHttpStatusProvider& Provider)
+{
+ ZEN_UNUSED(Provider);
+
+ RwLock::ExclusiveLockScope _(m_Lock);
+ m_Providers.erase(std::string(Id));
+}
+
+void
HttpStatusService::HandleRequest(HttpServerRequest& Request)
{
using namespace std::literals;
@@ -36,9 +45,12 @@ HttpStatusService::HandleRequest(HttpServerRequest& Request)
{
case HttpVerb::kHead:
case HttpVerb::kGet:
- if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers))
{
- return It->second->HandleStatusRequest(Request);
+ RwLock::SharedLockScope _(m_Lock);
+ if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers))
+ {
+ return It->second->HandleStatusRequest(Request);
+ }
}
[[fallthrough]];
diff --git a/zenserver/monitoring/httpstatus.h b/zenserver/monitoring/httpstatus.h
index 8f069f760..b04e45324 100644
--- a/zenserver/monitoring/httpstatus.h
+++ b/zenserver/monitoring/httpstatus.h
@@ -23,6 +23,7 @@ public:
virtual const char* BaseUri() const override;
virtual void HandleRequest(HttpServerRequest& Request) override;
void RegisterHandler(std::string_view Id, IHttpStatusProvider& Provider);
+ void UnregisterHandler(std::string_view Id, IHttpStatusProvider& Provider);
private:
spdlog::logger& m_Log;
diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp
index 5b2629f72..168449d05 100644
--- a/zenserver/upstream/upstreamcache.cpp
+++ b/zenserver/upstream/upstreamcache.cpp
@@ -697,7 +697,7 @@ struct UpstreamStats
const double UpSpeed = UpBytes > 0 ? UpBytes / SecondsUp : 0.0;
const double DownSpeed = DownBytes > 0 ? DownBytes / SecondsDown : 0.0;
const uint64_t TotalCount = HitCount + MissCount;
- const double HitRate = TotalCount > 0 ? (double(HitCount) / double(TotalCount)) * 100.0 : 0.0;
+ const double HitRate = TotalCount > 0 ? (double(HitCount) / double(TotalCount)) : 0.0;
Logger.debug("STATS - '{}', Hit rate: {:.2f}%, DOWN: '{:.2f} MiB {:.2f} MiB/s', UP: '{:.2f} MiB {:.2f} MiB/s'",
Ep->DisplayName(),
@@ -842,7 +842,7 @@ public:
const uint64_t HitCount = Stats.HitCount;
const uint64_t MissCount = Stats.MissCount;
const uint64_t TotalCount = HitCount + MissCount;
- const double HitRate = TotalCount > 0 ? (double(HitCount) / double(TotalCount)) * 100.0 : 0.0;
+ const double HitRate = TotalCount > 0 ? (double(HitCount) / double(TotalCount)) : 0.0;
Status << "hit_ratio" << HitRate;
Status << "downloaded_mb" << Stats.DownBytes;