From: Remi Gacogne Date: Wed, 8 Jan 2020 15:54:08 +0000 (+0100) Subject: auth: Add metrics about the size of our in-memory rings X-Git-Tag: auth-4.3.0-beta1~13^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=74e38357b583a63b3538d54e0f861625e408f06d;p=thirdparty%2Fpdns.git auth: Add metrics about the size of our in-memory rings --- diff --git a/pdns/statbag.cc b/pdns/statbag.cc index 35242e79aa..6aad23b1d2 100644 --- a/pdns/statbag.cc +++ b/pdns/statbag.cc @@ -184,12 +184,19 @@ void StatRing::account(const T& t) } template -unsigned int StatRing::getSize() +uint64_t StatRing::getSize() const { std::lock_guard l(d_lock); return d_items.capacity(); } +template +uint64_t StatRing::getEntriesCount() const +{ + std::lock_guard l(d_lock); + return d_items.size(); +} + template void StatRing::resize(unsigned int newsize) { @@ -197,7 +204,6 @@ void StatRing::resize(unsigned int newsize) d_items.set_capacity(newsize); } - template void StatRing::setHelp(const string &str) { @@ -229,25 +235,33 @@ vector >StatRing::get() const return tmp; } +void StatBag::registerRingStats(const string& name) +{ + declare("ring-" + name + "-size", "Number of entries in the " + name + " ring", [this,name](const std::string&) { return static_cast(getRingEntriesCount(name)); }); + declare("ring-" + name + "-capacity", "Maximum number of entries in the " + name + " ring", [this,name](const std::string&) { return static_cast(getRingSize(name)); }); +} + void StatBag::declareRing(const string &name, const string &help, unsigned int size) { d_rings.emplace(name, size); d_rings[name].setHelp(help); + registerRingStats(name); } void StatBag::declareComboRing(const string &name, const string &help, unsigned int size) { d_comborings.emplace(name, size); d_comborings[name].setHelp(help); + registerRingStats(name); } void StatBag::declareDNSNameQTypeRing(const string &name, const string &help, unsigned int size) { d_dnsnameqtyperings.emplace(name, size); d_dnsnameqtyperings[name].setHelp(help); + registerRingStats(name); } - vector > StatBag::getRing(const string &name) { if(d_rings.count(name)) { @@ -298,7 +312,7 @@ void StatBag::resizeRing(const string &name, unsigned int newsize) } -unsigned int StatBag::getRingSize(const string &name) +uint64_t StatBag::getRingSize(const string &name) { if(d_rings.count(name)) return d_rings[name].getSize(); @@ -309,6 +323,17 @@ unsigned int StatBag::getRingSize(const string &name) return 0; } +uint64_t StatBag::getRingEntriesCount(const string &name) +{ + if(d_rings.count(name)) + return d_rings[name].getEntriesCount(); + if(d_comborings.count(name)) + return d_comborings[name].getEntriesCount(); + if(d_dnsnameqtyperings.count(name)) + return d_dnsnameqtyperings[name].getEntriesCount(); + return 0; +} + string StatBag::getRingTitle(const string &name) { if(d_rings.count(name)) diff --git a/pdns/statbag.hh b/pdns/statbag.hh index 1ac49f53fe..4d8bd3a308 100644 --- a/pdns/statbag.hh +++ b/pdns/statbag.hh @@ -45,7 +45,8 @@ public: void account(const T &item); - unsigned int getSize(); + uint64_t getSize() const; + uint64_t getEntriesCount() const; void resize(unsigned int newsize); void reset(); void setHelp(const string &str); @@ -78,6 +79,8 @@ class StatBag bool d_doRings; std::set d_blacklist; + void registerRingStats(const string& name); + public: StatBag(); //!< Naked constructor. You need to declare keys before this class becomes useful ~StatBag(); @@ -124,7 +127,8 @@ public: bool ringExists(const string &name); void resetRing(const string &name); void resizeRing(const string &name, unsigned int newsize); - unsigned int getRingSize(const string &name); + uint64_t getRingSize(const string &name); + uint64_t getRingEntriesCount(const string &name); string directory(); //!< Returns a list of all data stored vector getEntries(); //!< returns a vector with datums (items)