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/structuredcachestore.cpp | |
| 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/structuredcachestore.cpp')
| -rw-r--r-- | src/zenserver/cache/structuredcachestore.cpp | 28 |
1 files changed, 24 insertions, 4 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) |