]> granicus.if.org Git - pdns/commitdiff
enable callback based metrics to statbas, and add 5 such metrics: uptime, sys-msec...
authorbert hubert <bert.hubert@netherlabs.nl>
Tue, 9 Dec 2014 20:34:50 +0000 (21:34 +0100)
committermind04 <mind04@monshouwer.org>
Tue, 23 Dec 2014 07:35:32 +0000 (08:35 +0100)
pdns/common_startup.cc
pdns/dbdnsseckeeper.cc
pdns/dnssecinfra.hh
pdns/dnsseckeeper.hh
pdns/dnssecsigner.cc
pdns/statbag.cc
pdns/statbag.hh

index 70b55988fba60bc325a7f7a4fba41da78b471a96..a4ad8d9d9fe4697ac27daa7718a4fc746d01f1bb 100644 (file)
@@ -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");
index 0efb48a57ef8b9ddb6fd2b6a8215c4dccbec6c2c..4f0e49ba3fef4e6e1e3283852c200590ed82fe65 100644 (file)
@@ -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;
index d81e7bb4d956c62e7e182fdba03fd3fe779f2c2a..cbf4749541f013b92d0a6b7e03f6b1136f93d63b 100644 (file)
@@ -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
index 748ab8e4b9f47656f3200075320eb2e3e2c17fc7..1f3183c391c23a3a49c472d21cb612ce4de9756c 100644 (file)
@@ -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;
index 19a459fa0544e9ecc3f16b90b1af3e31aaac6042..82766ccc996184f8dc21359cfd6b34ee4ea09d83 100644 (file)
@@ -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(); 
index 5a103ac796fc868fca47e5507abc9a12b1bd5663..a2489eb06f509b620e5bfcd91cf47ed745049fb3 100644 (file)
@@ -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)
index 6f669a0bdbe732bd7a7c9d7ce302e53f3a682a57..3920c01a1053f5e1f427496f6014665a5be4b7b6 100644 (file)
@@ -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);