Permalink
Browse files

enable callback based metrics to statbas, and add 5 such metrics: upt…

…ime, sys-msec, user-msec, key-cache-size, meta-cache-size, signature-cache-size
  • Loading branch information...
1 parent aaff7c8 commit a83257a8b594efacf272f1b1bfaa7533fa8616d4 @ahupowerdns ahupowerdns committed with mind04 Dec 9, 2014
Showing with 70 additions and 3 deletions.
  1. +28 −0 pdns/common_startup.cc
  2. +13 −0 pdns/dbdnsseckeeper.cc
  3. +1 −1 pdns/dnssecinfra.hh
  4. +2 −1 pdns/dnsseckeeper.hh
  5. +6 −0 pdns/dnssecsigner.cc
  6. +16 −1 pdns/statbag.cc
  7. +4 −0 pdns/statbag.hh
@@ -22,6 +22,9 @@
#include "common_startup.hh"
#include "ws-auth.hh"
#include "secpoll-auth.hh"
+#include <sys/time.h>
+#include <sys/resource.h>
+
bool g_anyToTcp;
typedef Distributor<DNSPacket,DNSPacket,PacketHandler> 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");
@@ -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;
View
@@ -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
@@ -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<DNSSECKeeper::keymeta_t> keys_t;
@@ -121,6 +121,12 @@ typedef map<pair<string, string>, 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<shared_ptr<DNSRecordContent> >& toSign)
{
DNSKEYRecordContent drc = dpk.getDNSKEY();
View
@@ -28,6 +28,7 @@
#include <algorithm>
#include "arguments.hh"
#include "lock.hh"
+#include <boost/foreach.hpp>
#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<<i->first<<"="<<*(i->second)<<",";
}
+
+ BOOST_FOREACH(const funcstats_t::value_type& val, d_funcstats) {
+ o << val.first<<"="<<val.second(val.first)<<",";
+ }
dir=o.str();
return dir;
}
@@ -70,6 +75,10 @@ vector<string>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)
View
@@ -63,12 +63,16 @@ class StatBag
map<string, AtomicCounter *> d_stats;
map<string, string> d_keyDescrips;
map<string,StatRing>d_rings;
+ typedef boost::function<uint64_t(const std::string&)> func_t;
+ typedef map<string, func_t> 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<pair<string, unsigned int> >getRing(const string &name);

0 comments on commit a83257a

Please sign in to comment.