From: Remi Gacogne Date: Mon, 21 Mar 2016 14:37:26 +0000 (+0100) Subject: dnsdist: Export cache stats to carbon. X-Git-Tag: dnsdist-1.0.0-beta1~70^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e9be156bf28e22b090e9e8f90a17bacd064fd2a;p=thirdparty%2Fpdns.git dnsdist: Export cache stats to carbon. --- diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index c8a1dd175c..9e164b3386 100644 --- a/pdns/dnsdist-cache.cc +++ b/pdns/dnsdist-cache.cc @@ -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(); +} diff --git a/pdns/dnsdist-cache.hh b/pdns/dnsdist-cache.hh index 011a151c4f..a154ab86a1 100644 --- a/pdns/dnsdist-cache.hh +++ b/pdns/dnsdist-cache.hh @@ -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); diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index 4741d59654..29f00d069b 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -81,6 +81,28 @@ try const string base = "dnsdist." + hostname + ".main.frontends." + frontName + "."; str<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 pool = entry.second; + str<servers.size() << " " << now << "\r\n"; + if (pool->packetCache != nullptr) { + const auto& cache = pool->packetCache; + str<getMaxEntries() << " " << now << "\r\n"; + str<getEntriesCount() << " " << now << "\r\n"; + str<getHits() << " " << now << "\r\n"; + str<getMisses() << " " << now << "\r\n"; + str<getDeferredInserts() << " " << now << "\r\n"; + str<getDeferredLookups() << " " << now << "\r\n"; + str<getLookupCollisions() << " " << now << "\r\n"; + str<getInsertCollisions() << " " << now << "\r\n"; + } + } const string msg = str.str(); int ret = waitForRWData(s.getHandle(), false, 1 , 0); diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index f5f30d3d7b..857e91fbce 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -552,7 +552,8 @@ void moreLua(bool client) }); g_lua.registerFunction::*)()>("printStats", [](const std::shared_ptr 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";