diff options
| author | Stefan Boberg <[email protected]> | 2023-10-25 12:21:51 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-25 12:21:51 +0200 |
| commit | 0b220255724020daea18ddb559f5edf3fdb1621b (patch) | |
| tree | 7809227752c15d90111c4e600d80b59d90ad25d2 /src/zenserver/cache | |
| parent | New rotating file logger that keeps on running regardless of errors (#495) (diff) | |
| download | zen-0b220255724020daea18ddb559f5edf3fdb1621b.tar.xz zen-0b220255724020daea18ddb559f5edf3fdb1621b.zip | |
statsd metrics reporting (#496)
added support for reporting metrics via statsd style UDP messaging, which is supported by many monitoring solution providers
this change adds reporting only of three cache related metrics (hit/miss/put) but this should be extended to include more metrics after additional evaluation
Diffstat (limited to 'src/zenserver/cache')
| -rw-r--r-- | src/zenserver/cache/structuredcachestore.cpp | 28 | ||||
| -rw-r--r-- | src/zenserver/cache/structuredcachestore.h | 21 |
2 files changed, 38 insertions, 11 deletions
diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp index 89123a70f..6fab14eee 100644 --- a/src/zenserver/cache/structuredcachestore.cpp +++ b/src/zenserver/cache/structuredcachestore.cpp @@ -16,6 +16,7 @@ #include <zencore/timer.h> #include <zencore/trace.h> #include <zencore/workthreadpool.h> +#include <zennet/statsdclient.h> #include <zenstore/scrubcontext.h> #include <zenutil/cache/cache.h> @@ -663,7 +664,7 @@ ZenCacheStore::StorageSize() const } ZenCacheStore::CacheStoreStats -ZenCacheStore::Stats() +ZenCacheStore::Stats(bool IncludeNamespaceStats) { ZenCacheStore::CacheStoreStats Result{.HitCount = m_HitCount, .MissCount = m_MissCount, @@ -672,13 +673,32 @@ ZenCacheStore::Stats() .RejectedReadCount = m_RejectedReadCount, .PutOps = m_PutOps.Snapshot(), .GetOps = m_GetOps.Snapshot()}; - IterateNamespaces([&](std::string_view NamespaceName, ZenCacheNamespace& Store) { - Result.NamespaceStats.emplace_back(NamedNamespaceStats{.NamespaceName = std::string(NamespaceName), .Stats = Store.Stats()}); - }); + + if (IncludeNamespaceStats) + { + IterateNamespaces([&](std::string_view NamespaceName, ZenCacheNamespace& Store) { + Result.NamespaceStats.emplace_back(NamedNamespaceStats{.NamespaceName = std::string(NamespaceName), .Stats = Store.Stats()}); + }); + } + return Result; } void +ZenCacheStore::ReportMetrics(StatsDaemonClient& Statsd) +{ + const bool IncludeNamespaceStats = false; + const CacheStoreStats Now = Stats(IncludeNamespaceStats); + const CacheStoreStats& Old = m_LastReportedMetrics; + + Statsd.Meter("zen.cache_hits", Now.HitCount - Old.HitCount); + Statsd.Meter("zen.cache_misses", Now.MissCount - Old.MissCount); + Statsd.Meter("zen.cache_writes", Now.WriteCount - Old.WriteCount); + + m_LastReportedMetrics = Now; +} + +void ZenCacheStore::SetLoggingConfig(const Configuration::LogConfig& Loggingconfig) { if (!Loggingconfig.EnableAccessLog && !Loggingconfig.EnableWriteLog) diff --git a/src/zenserver/cache/structuredcachestore.h b/src/zenserver/cache/structuredcachestore.h index 02d0e31c0..dacf482d8 100644 --- a/src/zenserver/cache/structuredcachestore.h +++ b/src/zenserver/cache/structuredcachestore.h @@ -3,6 +3,7 @@ #pragma once #include "cachedisklayer.h" +#include "stats/statsreporter.h" #include <zencore/compactbinary.h> #include <zencore/iohash.h> @@ -18,6 +19,8 @@ namespace zen { +class StatsDaemonClient; + /****************************************************************************** /$$$$$$$$ /$$$$$$ /$$ @@ -126,7 +129,7 @@ private: */ -class ZenCacheStore final : public RefCounted +class ZenCacheStore final : public RefCounted, public StatsProvider { public: static constexpr std::string_view DefaultNamespace = @@ -161,11 +164,11 @@ public: struct CacheStoreStats { - uint64_t HitCount; - uint64_t MissCount; - uint64_t WriteCount; - uint64_t RejectedWriteCount; - uint64_t RejectedReadCount; + uint64_t HitCount = 0; + uint64_t MissCount = 0; + uint64_t WriteCount = 0; + uint64_t RejectedWriteCount = 0; + uint64_t RejectedReadCount = 0; metrics::RequestStatsSnapshot PutOps; metrics::RequestStatsSnapshot GetOps; std::vector<NamedNamespaceStats> NamespaceStats; @@ -199,7 +202,7 @@ public: const std::string_view ValueFilter) const; GcStorageSize StorageSize() const; - CacheStoreStats Stats(); + CacheStoreStats Stats(bool IncludeNamespaceStats = true); Configuration GetConfiguration() const { return m_Configuration; } void SetLoggingConfig(const Configuration::LogConfig& Loggingconfig); @@ -212,6 +215,9 @@ public: std::string_view Bucket, std::function<void(const IoHash& Key, const CacheValueDetails::ValueDetails& Details)>&& Fn); + // StatsProvider + virtual void ReportMetrics(StatsDaemonClient& Statsd) override; + private: const ZenCacheNamespace* FindNamespace(std::string_view Namespace) const; ZenCacheNamespace* GetNamespace(std::string_view Namespace); @@ -219,6 +225,7 @@ private: typedef std::unordered_map<std::string, std::unique_ptr<ZenCacheNamespace>> NamespaceMap; + CacheStoreStats m_LastReportedMetrics; const DiskWriteBlocker* m_DiskWriteBlocker = nullptr; mutable RwLock m_NamespacesLock; NamespaceMap m_Namespaces; |