]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: add a statistic for the number of cache cleanups 11656/head
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Tue, 24 May 2022 14:59:42 +0000 (16:59 +0200)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Tue, 24 May 2022 14:59:42 +0000 (16:59 +0200)
pdns/dnsdist-cache.cc
pdns/dnsdist-cache.hh
pdns/dnsdist-carbon.cc
pdns/dnsdist-web.cc
pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc

index d6b99a079006d18bb5da7ac7313a79e4325c2454..7222a29162b0e47d897330802fcb62ef8c162673 100644 (file)
@@ -298,6 +298,7 @@ size_t DNSDistPacketCache::purgeExpired(size_t upTo, const time_t now)
 
   size_t removed = 0;
 
+  d_cleanupCount++;
   for (auto& shard : d_shards) {
     auto map = shard.d_map.write_lock();
     if (map->size() <= maxPerShard) {
index 3309459ecb9b16b3dcea5817b5ab0bf53ef916bd..23b321375c765faae21ecb1caf366f2aea38c40e 100644 (file)
@@ -53,6 +53,7 @@ public:
   uint64_t getInsertCollisions() const { return d_insertCollisions; }
   uint64_t getMaxEntries() const { return d_maxEntries; }
   uint64_t getTTLTooShorts() const { return d_ttlTooShorts; }
+  uint64_t getCleanupCount() const { return d_cleanupCount; }
   uint64_t getEntriesCount();
   uint64_t dump(int fd);
   void setSkippedOptions(const std::unordered_set<uint16_t>& optionsToSkip);
@@ -130,6 +131,7 @@ private:
   pdns::stat_t d_insertCollisions{0};
   pdns::stat_t d_lookupCollisions{0};
   pdns::stat_t d_ttlTooShorts{0};
+  pdns::stat_t d_cleanupCount{0};
 
   size_t d_maxEntries;
   uint32_t d_shardCount;
index cdad9dd69a74b69abbb624b1d3d722fa4c040ad4..e8048ed1743d71f259783d6100f786a49eb1625d 100644 (file)
@@ -182,6 +182,7 @@ void carbonDumpThread()
               str<<base<<"cache-lookup-collisions" << " " << cache->getLookupCollisions() << " " << now << "\r\n";
               str<<base<<"cache-insert-collisions" << " " << cache->getInsertCollisions() << " " << now << "\r\n";
               str<<base<<"cache-ttl-too-shorts" << " " << cache->getTTLTooShorts() << " " << now << "\r\n";
+              str<<base<<"cache-cleanup-count" << " " << cache->getCleanupCount() << " " << now << "\r\n";
             }
           }
 
index a60adaf216ca601d6c013aa61a73a01b65b05c20..5edc46114f12e1ad377047003850ef95345caae1 100644 (file)
@@ -787,6 +787,7 @@ static void handlePrometheus(const YaHTTP::Request& req, YaHTTP::Response& resp)
       output << cachebase << "cache_lookup_collisions" <<label << " " << cache->getLookupCollisions() << "\n";
       output << cachebase << "cache_insert_collisions" <<label << " " << cache->getInsertCollisions() << "\n";
       output << cachebase << "cache_ttl_too_shorts"    <<label << " " << cache->getTTLTooShorts()     << "\n";
+      output << cachebase << "cache_cleanup_count"     <<label << " " << cache->getCleanupCount()     << "\n";
     }
   }
 
@@ -1101,7 +1102,8 @@ static void handleStats(const YaHTTP::Request& req, YaHTTP::Response& resp)
       { "cacheDeferredLookups", (double) (cache ? cache->getDeferredLookups() : 0) },
       { "cacheLookupCollisions", (double) (cache ? cache->getLookupCollisions() : 0) },
       { "cacheInsertCollisions", (double) (cache ? cache->getInsertCollisions() : 0) },
-      { "cacheTTLTooShorts", (double) (cache ? cache->getTTLTooShorts() : 0) }
+      { "cacheTTLTooShorts", (double) (cache ? cache->getTTLTooShorts() : 0) },
+      { "cacheCleanupCount", (double) (cache ? cache->getCleanupCount() : 0) }
     };
     pools.push_back(entry);
   }
@@ -1199,7 +1201,8 @@ static void handlePoolStats(const YaHTTP::Request& req, YaHTTP::Response& resp)
     { "cacheDeferredLookups", (double) (cache ? cache->getDeferredLookups() : 0) },
     { "cacheLookupCollisions", (double) (cache ? cache->getLookupCollisions() : 0) },
     { "cacheInsertCollisions", (double) (cache ? cache->getInsertCollisions() : 0) },
-    { "cacheTTLTooShorts", (double) (cache ? cache->getTTLTooShorts() : 0) }
+    { "cacheTTLTooShorts", (double) (cache ? cache->getTTLTooShorts() : 0) },
+    { "cacheCleanupCount", (double) (cache ? cache->getCleanupCount() : 0) }
   };
 
   Json::array servers;
index 892de27f121d446b71b9f031fb7763b9795d1423..120edf30e55eeea92feab3642f9196c31328cf23 100644 (file)
@@ -179,6 +179,7 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client)
         g_outputBuffer+="Lookup Collisions: " + std::to_string(cache->getLookupCollisions()) + "\n";
         g_outputBuffer+="Insert Collisions: " + std::to_string(cache->getInsertCollisions()) + "\n";
         g_outputBuffer+="TTL Too Shorts: " + std::to_string(cache->getTTLTooShorts()) + "\n";
+        g_outputBuffer+="Cleanup Count: " + std::to_string(cache->getCleanupCount()) + "\n";
       }
     });
   luaCtx.registerFunction<LuaAssociativeTable<uint64_t>(std::shared_ptr<DNSDistPacketCache>::*)()const>("getStats", [](const std::shared_ptr<DNSDistPacketCache>& cache) {
@@ -193,6 +194,7 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client)
         stats["lookupCollisions"] = cache->getLookupCollisions();
         stats["insertCollisions"] = cache->getInsertCollisions();
         stats["ttlTooShorts"] = cache->getTTLTooShorts();
+        stats["cleanupCount"] = cache->getCleanupCount();
       }
       return stats;
     });