From: bert hubert Date: Fri, 8 May 2015 19:51:50 +0000 (+0200) Subject: add support for graphite/carbon to dnsdist, plus document it X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~28^2~52^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42fae3263aab77fce99dd21eec954e6169805f3e;p=thirdparty%2Fpdns.git add support for graphite/carbon to dnsdist, plus document it --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index e126cb82e2..0e6ee5972e 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -565,6 +565,7 @@ dnsdist_SOURCES = \ base32.cc \ base64.hh \ dnsdist.cc \ + dnsdist-carbon.cc \ dnsdist-lua.cc \ dnsdist-tcp.cc \ dnsdist-web.cc \ diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index e9d6724514..a3c872c13a 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -412,6 +412,19 @@ fe80::/10 ::/0 ``` +Carbon/Graphite/Metronome +------------------------- +To emit metrics to Graphite, or any other software supporting the Carbon protocol, use: +``` +carbonServer('ip-address-of-carbon-server', 'ourname', 30) +``` + +Where 'ourname' can be used to override your hostname, and '30' is the +reporting interval in seconds. The last two arguments can be omitted. The +latest version of [PowerDNS +Metronome](https://github.com/ahupowerdns/metronome) comes with attractive +graphs for dnsdist by default. + All functions and types ----------------------- Within `dnsdist` several core object types exist: @@ -445,6 +458,8 @@ Here are all functions: * `showACL()`: show our ACL set * Blocking related: * `addDomainBlock(domain)`: block queries within this domain + * Carbon/Graphite/Metronome statistics related: + * `carbonServer(serverIP, [ourname], [interval])`: report statistics to serverIP using our hostname, or 'ourname' if provided, every 'interval' seconds * Control socket related: * `makeKey()`: generate a new server access key, emit configuration line ready for pasting * `setKey(key)`: set access key to that key. diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 6d1c162c52..b27d85f36c 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -461,6 +461,19 @@ vector> setupLua(bool client, const std::string& confi g_lua.registerFunction("add",(void (SuffixMatchNode::*)(const DNSName&)) &SuffixMatchNode::add); g_lua.registerFunction("check",(bool (SuffixMatchNode::*)(const DNSName&) const) &SuffixMatchNode::check); + g_lua.writeFunction("carbonServer", [](const std::string& address, boost::optional ourName, + boost::optional interval) { + auto ours = g_carbon.getCopy(); + ours.server=ComboAddress(address, 2003); + if(ourName) + ours.ourname=*ourName; + if(interval) + ours.interval=*interval; + if(!ours.interval) + ours.interval=1; + g_carbon.setState(ours); + }); + g_lua.writeFunction("webserver", [client](const std::string& address, const std::string& password) { if(client) return; diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index a11b9a1bbe..28a489b521 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -65,7 +65,6 @@ GlobalStateHolder g_ACL; string g_outputBuffer; vector g_locals; - /* UDP: the grand design. Per socket we listen on for incoming queries there is one thread. Then we have a bunch of connected sockets for talking to downstream servers. We send directly to those sockets. @@ -161,6 +160,13 @@ void* responderThread(std::shared_ptr state) g_stats.servfailResponses++; state->latencyUsec = (127.0 * state->latencyUsec / 128.0) + udiff/128.0; + if(udiff < 1000) g_stats.latency0_1++; + else if(udiff < 10000) g_stats.latency1_10++; + else if(udiff < 50000) g_stats.latency10_50++; + else if(udiff < 100000) g_stats.latency50_100++; + else if(udiff < 1000000) g_stats.latency100_1000++; + else g_stats.latencySlow++; + g_stats.latency = (1023.0*g_stats.latency/1024.0) + udiff/1024.0; ids->origFD = -1; @@ -1066,6 +1072,9 @@ try t1.detach(); } + thread carbonthread(carbonDumpThread); + carbonthread.detach(); + thread stattid(maintThread); if(g_cmdLine.beDaemon || g_cmdLine.beSupervised) { diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 387f961b5e..4c0840c1dc 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -9,7 +9,7 @@ #include #include #include "sholder.hh" - +void* carbonDumpThread(); struct DNSDistStats { using stat_t=std::atomic; // aww yiss ;-) @@ -25,8 +25,20 @@ struct DNSDistStats stat_t downstreamSendErrors{0}; stat_t truncFail{0}; stat_t noPolicy{0}; - double latency{0}; + stat_t latency0_1{0}, latency1_10{0}, latency10_50{0}, latency50_100{0}, latency100_1000{0}, latencySlow{0}; + double latency{0}; + std::vector> entries{ + {"responses", &responses}, {"servfail-responses", &servfailResponses}, + {"queries", &queries}, {"acl-drops", &aclDrops}, + {"block-filter", &blockFilter}, {"rule-drop", &ruleDrop}, + {"rule-nxdomain", &ruleNXDomain}, {"self-answered", &selfAnswered}, + {"downstream-timeouts", &downstreamTimeouts}, {"downstream-send-errors", &downstreamSendErrors}, + {"trunc-failures", &truncFail}, {"no-policy", &noPolicy}, + {"latency0-1", &latency0_1}, {"latency1-10", &latency1_10}, + {"latency10-50", &latency10_50}, {"latency50-100", &latency50_100}, + {"latency100-1000", &latency100_1000}, {"latency-slow", &latencySlow} + }; }; extern struct DNSDistStats g_stats; @@ -281,6 +293,14 @@ struct ServerPolicy policy_t policy; }; +struct CarbonConfig +{ + ComboAddress server{"0.0.0.0", 0}; + std::string ourname; + unsigned int interval{30}; +}; + +extern GlobalStateHolder g_carbon; extern GlobalStateHolder g_policy; extern GlobalStateHolder g_dstates; extern GlobalStateHolder, std::shared_ptr > > > g_rulactions; diff --git a/pdns/dnsdistconf.lua b/pdns/dnsdistconf.lua index ca45a22cd5..cafe0a9d6f 100644 --- a/pdns/dnsdistconf.lua +++ b/pdns/dnsdistconf.lua @@ -3,6 +3,7 @@ webserver("0.0.0.0:8083", "geheim2") addLocal("0.0.0.0:5200") setKey("MXNeLFWHUe4363BBKrY06cAsH8NWNb+Se2eXU5+Bb74=") truncateTC(true) -- fix up possibly badly truncated answers from pdns 2.9.22 +carbonServer("2001:888:2000:1d::2") warnlog(string.format("Script starting %s", "up!")) @@ -16,7 +17,7 @@ newServer("2001:4860:4860::8844",1) newServer("2620:0:ccc::2", 10) newServer("2620:0:ccd::2", 10) newServer{address="192.168.1.2", qps=1000, order=2} - +newServer{address="192.168.1.79:5300", order=2} newServer{address="127.0.0.1:5300", order=3} newServer{address="192.168.1.30:5300", pool="abuse"}