#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;
::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");
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");
}
}
+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;
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
}
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);
void getFromMeta(const std::string& zname, const std::string& key, std::string& value);
private:
-
+
struct KeyCacheEntry
{
typedef vector<DNSSECKeeper::keymeta_t> keys_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();
#include <algorithm>
#include "arguments.hh"
#include "lock.hh"
+#include <boost/foreach.hpp>
#include "namespaces.hh"
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+"'");
}
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;
}
i++)
ret.push_back(i->first);
+ BOOST_FOREACH(const funcstats_t::value_type& val, d_funcstats) {
+ ret.push_back(val.first);
+ }
+
return ret;
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)
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);