base32.cc \
base64.hh \
dnsdist.cc \
+ dnsdist-carbon.cc \
dnsdist-lua.cc \
dnsdist-tcp.cc \
dnsdist-web.cc \
::/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:
* `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.
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<string> ourName,
+ boost::optional<int> 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;
string g_outputBuffer;
vector<ComboAddress> 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.
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;
t1.detach();
}
+ thread carbonthread(carbonDumpThread);
+ carbonthread.detach();
+
thread stattid(maintThread);
if(g_cmdLine.beDaemon || g_cmdLine.beSupervised) {
#include <mutex>
#include <thread>
#include "sholder.hh"
-
+void* carbonDumpThread();
struct DNSDistStats
{
using stat_t=std::atomic<uint64_t>; // aww yiss ;-)
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<std::pair<std::string, stat_t*>> 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;
policy_t policy;
};
+struct CarbonConfig
+{
+ ComboAddress server{"0.0.0.0", 0};
+ std::string ourname;
+ unsigned int interval{30};
+};
+
+extern GlobalStateHolder<CarbonConfig> g_carbon;
extern GlobalStateHolder<ServerPolicy> g_policy;
extern GlobalStateHolder<servers_t> g_dstates;
extern GlobalStateHolder<vector<pair<std::shared_ptr<DNSRule>, std::shared_ptr<DNSAction> > > > g_rulactions;
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!"))
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"}