From: bert hubert Date: Tue, 9 Dec 2014 20:34:50 +0000 (+0100) Subject: enable callback based metrics to statbas, and add 5 such metrics: uptime, sys-msec... X-Git-Tag: auth-3.4.2~15^2~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a83257a8b594efacf272f1b1bfaa7533fa8616d4;p=pdns enable callback based metrics to statbas, and add 5 such metrics: uptime, sys-msec, user-msec, key-cache-size, meta-cache-size, signature-cache-size --- diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 70b55988f..a4ad8d9d9 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -22,6 +22,9 @@ #include "common_startup.hh" #include "ws-auth.hh" #include "secpoll-auth.hh" +#include +#include + bool g_anyToTcp; typedef Distributor DNSDistributor; @@ -164,6 +167,24 @@ void declareArguments() ::arg().set("security-poll-suffix","Domain name from which to query security update notifications")="secpoll.powerdns.com."; } +static uint64_t uptimeOfProcess(const std::string& str) +{ + static time_t start=time(0); + return time(0) - start; +} + +static uint64_t getSysUserTimeMsec(const std::string& str) +{ + struct rusage ru; + getrusage(RUSAGE_SELF, &ru); + + if(str=="sys-msec") + return (ru.ru_stime.tv_sec*1000ULL + ru.ru_stime.tv_usec/1000); + else + return (ru.ru_utime.tv_sec*1000ULL + ru.ru_utime.tv_usec/1000); + +} + void declareStats(void) { S.declare("udp-queries","Number of UDP queries received"); @@ -198,6 +219,13 @@ void declareStats(void) S.declare("dnsupdate-refused", "DNS update packets that are refused."); S.declare("dnsupdate-changes", "DNS update changes to records in total."); + S.declare("uptime", "Uptime of process in seconds", uptimeOfProcess); + S.declare("sys-msec", "Number of msec spent in system time", getSysUserTimeMsec); + S.declare("user-msec", "Number of msec spent in user time", getSysUserTimeMsec); + S.declare("meta-cache-size", "Number of entries in the metadata cache", DNSSECKeeper::dbdnssecCacheSizes); + S.declare("key-cache-size", "Number of entries in the key cache", DNSSECKeeper::dbdnssecCacheSizes); + S.declare("signature-cache-size", "Number of entries in the signature cache", signatureCacheSize); + S.declare("servfail-packets","Number of times a server-failed packet was sent out"); S.declare("latency","Average number of microseconds needed to answer a question"); S.declare("timedout-packets","Number of packets which weren't answered within timeout set"); diff --git a/pdns/dbdnsseckeeper.cc b/pdns/dbdnsseckeeper.cc index 0efb48a57..4f0e49ba3 100644 --- a/pdns/dbdnsseckeeper.cc +++ b/pdns/dbdnsseckeeper.cc @@ -212,6 +212,19 @@ void DNSSECKeeper::getFromMeta(const std::string& zname, const std::string& key, } } +uint64_t DNSSECKeeper::dbdnssecCacheSizes(const std::string& str) +{ + if(str=="meta-cache-size") { + ReadLock l(&s_metacachelock); + return s_metacache.size(); + } + else if(str=="key-cache-size") { + ReadLock l(&s_keycachelock); + return s_keycache.size(); + } + return (uint64_t)-1; +} + bool DNSSECKeeper::getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordContent* ns3p, bool* narrow) { string value; diff --git a/pdns/dnssecinfra.hh b/pdns/dnssecinfra.hh index d81e7bb4d..cbf474954 100644 --- a/pdns/dnssecinfra.hh +++ b/pdns/dnssecinfra.hh @@ -138,5 +138,5 @@ string calculateHMAC(const std::string& key, const std::string& text, TSIGHashEn string makeTSIGMessageFromTSIGPacket(const string& opacket, unsigned int tsigoffset, const string& keyname, const TSIGRecordContent& trc, const string& previous, bool timersonly, unsigned int dnsHeaderOffset=0); bool getTSIGHashEnum(const string &algoName, TSIGHashEnum& algoEnum); void addTSIG(DNSPacketWriter& pw, TSIGRecordContent* trc, const string& tsigkeyname, const string& tsigsecret, const string& tsigprevious, bool timersonly); - +uint64_t signatureCacheSize(const std::string& str); #endif diff --git a/pdns/dnsseckeeper.hh b/pdns/dnsseckeeper.hh index 748ab8e4b..1f3183c39 100644 --- a/pdns/dnsseckeeper.hh +++ b/pdns/dnsseckeeper.hh @@ -71,6 +71,7 @@ public: } bool isSecuredZone(const std::string& zone); + static uint64_t dbdnssecCacheSizes(const std::string& str); keyset_t getKeys(const std::string& zone, boost::tribool allOrKeyOrZone = boost::indeterminate, bool useCache = true); DNSSECPrivateKey getKeyById(const std::string& zone, unsigned int id); bool addKey(const std::string& zname, bool keyOrZone, int algorithm=5, int bits=0, bool active=true); @@ -107,7 +108,7 @@ public: void getFromMeta(const std::string& zname, const std::string& key, std::string& value); private: - + struct KeyCacheEntry { typedef vector keys_t; diff --git a/pdns/dnssecsigner.cc b/pdns/dnssecsigner.cc index 19a459fa0..82766ccc9 100644 --- a/pdns/dnssecsigner.cc +++ b/pdns/dnssecsigner.cc @@ -121,6 +121,12 @@ typedef map, string> signaturecache_t; static signaturecache_t g_signatures; static int g_cacheweekno; +uint64_t signatureCacheSize(const std::string& str) +{ + ReadLock l(&g_signatures_lock); + return g_signatures.size(); +} + void fillOutRRSIG(DNSSECPrivateKey& dpk, const std::string& signQName, RRSIGRecordContent& rrc, vector >& toSign) { DNSKEYRecordContent drc = dpk.getDNSKEY(); diff --git a/pdns/statbag.cc b/pdns/statbag.cc index 5a103ac79..a2489eb06 100644 --- a/pdns/statbag.cc +++ b/pdns/statbag.cc @@ -28,6 +28,7 @@ #include #include "arguments.hh" #include "lock.hh" +#include #include "namespaces.hh" @@ -38,7 +39,7 @@ StatBag::StatBag() void StatBag::exists(const string &key) { - if(!d_stats.count(key)) + if(!d_keyDescrips.count(key)) { throw PDNSException("Trying to deposit into unknown StatBag key '"+key+"'"); } @@ -56,6 +57,10 @@ string StatBag::directory() o<first<<"="<<*(i->second)<<","; } + + BOOST_FOREACH(const funcstats_t::value_type& val, d_funcstats) { + o << val.first<<"="<StatBag::getEntries() i++) ret.push_back(i->first); + BOOST_FOREACH(const funcstats_t::value_type& val, d_funcstats) { + ret.push_back(val.first); + } + return ret; @@ -88,6 +97,12 @@ void StatBag::declare(const string &key, const string &descrip) d_keyDescrips[key]=descrip; } +void StatBag::declare(const string &key, const string &descrip, StatBag::func_t func) +{ + + d_funcstats[key]=func; + d_keyDescrips[key]=descrip; +} void StatBag::set(const string &key, AtomicCounter::native_t value) diff --git a/pdns/statbag.hh b/pdns/statbag.hh index 6f669a0bd..3920c01a1 100644 --- a/pdns/statbag.hh +++ b/pdns/statbag.hh @@ -63,12 +63,16 @@ class StatBag map d_stats; map d_keyDescrips; mapd_rings; + typedef boost::function func_t; + typedef map funcstats_t; + funcstats_t d_funcstats; bool d_doRings; public: StatBag(); //!< Naked constructor. You need to declare keys before this class becomes useful ~StatBag(); void declare(const string &key, const string &descrip=""); //!< Before you can store or access a key, you need to declare it + void declare(const string &key, const string &descrip, func_t func); //!< Before you can store or access a key, you need to declare it void declareRing(const string &name, const string &title, unsigned int size=10000); vector >getRing(const string &name);