]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Export cache stats to carbon. 3608/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 21 Mar 2016 14:37:26 +0000 (15:37 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 21 Mar 2016 14:37:26 +0000 (15:37 +0100)
pdns/dnsdist-cache.cc
pdns/dnsdist-cache.hh
pdns/dnsdist-carbon.cc
pdns/dnsdist-lua2.cc

index c8a1dd175ccc66a362f96786e366ae515ba14cee..9e164b33860a8d35002989df82e861d48c7cd473 100644 (file)
@@ -92,8 +92,9 @@ void DNSDistPacketCache::insert(uint32_t key, const DNSName& qname, uint16_t qty
     }
 
     /* if the existing entry had a longer TTD, keep it */
-    if (newValidity <= value.validity)
+    if (newValidity <= value.validity) {
       return;
+    }
 
     value = newValue;
   }
@@ -266,3 +267,9 @@ string DNSDistPacketCache::toString()
   ReadLock r(&d_lock);
   return std::to_string(d_map.size()) + "/" + std::to_string(d_maxEntries);
 }
+
+uint64_t DNSDistPacketCache::getEntriesCount()
+{
+  ReadLock r(&d_lock);
+  return d_map.size();
+}
index 011a151c4f773988e3cb5882fdae5d9a2ca4328f..a154ab86a1f5da2e640478e976f560a9c192692f 100644 (file)
@@ -19,13 +19,15 @@ public:
   void expungeByName(const DNSName& name, uint16_t qtype=QType::ANY);
   bool isFull();
   string toString();
-  uint64_t getSize() const { return d_map.size(); };
-  uint64_t getHits() const { return d_hits; };
-  uint64_t getMisses() const { return d_misses; };
-  uint64_t getDeferredLookups() const { return d_deferredLookups; };
-  uint64_t getDeferredInserts() const { return d_deferredInserts; };
-  uint64_t getLookupCollisions() const { return d_lookupCollisions; };
-  uint64_t getInsertCollisions() const { return d_insertCollisions; };
+  uint64_t getSize() const { return d_map.size(); }
+  uint64_t getHits() const { return d_hits; }
+  uint64_t getMisses() const { return d_misses; }
+  uint64_t getDeferredLookups() const { return d_deferredLookups; }
+  uint64_t getDeferredInserts() const { return d_deferredInserts; }
+  uint64_t getLookupCollisions() const { return d_lookupCollisions; }
+  uint64_t getInsertCollisions() const { return d_insertCollisions; }
+  uint64_t getMaxEntries() const { return d_maxEntries; }
+  uint64_t getEntriesCount();
 
   static uint32_t getMinTTL(const char* packet, uint16_t length);
 
index 4741d5965432c3af516c0e2acec0961b2dac4786..29f00d069b65ac9d0c03fc75835391299748c7d1 100644 (file)
@@ -81,6 +81,28 @@ try
           const string base = "dnsdist." + hostname + ".main.frontends." + frontName + ".";
           str<<base<<"queries" << ' ' << front->queries.load() << " " << now << "\r\n";
         }
+        const auto localPools = g_pools.getCopy();
+        for (const auto& entry : localPools) {
+          string poolName = entry.first;
+          boost::replace_all(poolName, ".", "_");
+          if (poolName.empty()) {
+            poolName = "_default_";
+          }
+          const string base = "dnsdist." + hostname + ".main.pools." + poolName + ".";
+          const std::shared_ptr<ServerPool> pool = entry.second;
+          str<<base<<"servers" << " " << pool->servers.size() << " " << now << "\r\n";
+          if (pool->packetCache != nullptr) {
+            const auto& cache = pool->packetCache;
+            str<<base<<"cache-size" << " " << cache->getMaxEntries() << " " << now << "\r\n";
+            str<<base<<"cache-entries" << " " << cache->getEntriesCount() << " " << now << "\r\n";
+            str<<base<<"cache-hits" << " " << cache->getHits() << " " << now << "\r\n";
+            str<<base<<"cache-misses" << " " << cache->getMisses() << " " << now << "\r\n";
+            str<<base<<"cache-deferred-inserts" << " " << cache->getDeferredInserts() << " " << now << "\r\n";
+            str<<base<<"cache-deferred-lookups" << " " << cache->getDeferredLookups() << " " << now << "\r\n";
+            str<<base<<"cache-lookup-collisions" << " " << cache->getLookupCollisions() << " " << now << "\r\n";
+            str<<base<<"cache-insert-collisions" << " " << cache->getInsertCollisions() << " " << now << "\r\n";
+          }
+        }
         const string msg = str.str();
 
         int ret = waitForRWData(s.getHandle(), false, 1 , 0);
index f5f30d3d7bb032b39aa1de7ad94601723e690a64..857e91fbce68404a8d5c6f2e74cea9fcc76cd99b 100644 (file)
@@ -552,7 +552,8 @@ void moreLua(bool client)
       });
     g_lua.registerFunction<void(std::shared_ptr<DNSDistPacketCache>::*)()>("printStats", [](const std::shared_ptr<DNSDistPacketCache> cache) {
         if (cache) {
-          g_outputBuffer="Hits: " + std::to_string(cache->getHits()) + "\n";
+          g_outputBuffer="Entries: " + std::to_string(cache->getEntriesCount()) + "/" + std::to_string(cache->getMaxEntries()) + "\n";
+          g_outputBuffer+="Hits: " + std::to_string(cache->getHits()) + "\n";
           g_outputBuffer+="Misses: " + std::to_string(cache->getMisses()) + "\n";
           g_outputBuffer+="Deferred inserts: " + std::to_string(cache->getDeferredInserts()) + "\n";
           g_outputBuffer+="Deferred lookups: " + std::to_string(cache->getDeferredLookups()) + "\n";