From 18eeccc9293afa0e03a4609232e490b333b62ff0 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 12 Nov 2015 10:15:38 +0100 Subject: [PATCH] Add a 'name' parameter to newServer(), and display that name instead in the server's address. --- pdns/README-dnsdist.md | 4 ++-- pdns/dnsdist-carbon.cc | 2 +- pdns/dnsdist-lua.cc | 14 +++++++++----- pdns/dnsdist-tcp.cc | 6 +++--- pdns/dnsdist-web.cc | 1 + pdns/dnsdist.cc | 10 +++++----- pdns/dnsdist.hh | 7 +++++++ pdns/dnsdistdist/html/local.js | 4 ++-- 8 files changed, 30 insertions(+), 18 deletions(-) diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index a59e72d08..d4da5e6fa 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -58,7 +58,7 @@ $ cat /etc/dnsdist.conf newServer {address="2001:4860:4860::8888", qps=1} newServer {address="2001:4860:4860::8844", qps=1} newServer {address="2620:0:ccc::2", qps=10} -newServer {address="2620:0:ccd::2", qps=10} +newServer {address="2620:0:ccd::2", name="dns1", qps=10} newServer("192.168.1.2") setServerPolicy(firstAvailable) -- first server within its QPS limit @@ -562,7 +562,7 @@ Here are all functions: * `errlog(string)`: log at level error * Server related: * `newServer("ip:port")`: instantiate a new downstream server with default settings - * `newServer({address="ip:port", qps=1000, order=1, weight=10, pool="abuse", retries=5, tcpSendTimeout=30, tcpRecvTimeout=30})`: instantiate + * `newServer({address="ip:port", name="dns1", qps=1000, order=1, weight=10, pool="abuse", retries=5, tcpSendTimeout=30, tcpRecvTimeout=30})`: instantiate a server with additional parameters * `showServers()`: output all servers * `getServer(n)`: returns server with index n diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index 3a83d1f49..a6242779f 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -58,7 +58,7 @@ try } const auto states = g_dstates.getCopy(); for(const auto& s : states) { - string serverName = s->remote.toString(); + string serverName = s->getName(); boost::replace_all(serverName, ".", "_"); const string base = "dnsdist." + hostname + ".main.servers." + serverName + "."; str<queries.load() << " " << now << "\r\n"; diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 0ef97a5f7..c97be34df 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -164,6 +164,10 @@ vector> setupLua(bool client, const std::string& confi ret->tcpRecvTimeout=boost::lexical_cast(boost::get(vars["tcpRecvTimeout"])); } + if(vars.count("name")) { + ret->name=boost::get(vars["name"]); + } + if(g_launchWork) { g_launchWork->push_back([ret]() { ret->tid = move(thread(responderThread, ret)); @@ -308,9 +312,9 @@ vector> setupLua(bool client, const std::string& confi try { ostringstream ret; - boost::format fmt("%1$-3d %2% %|30t|%3$5s %|36t|%4$7.1f %|41t|%5$7d %|44t|%6$3d %|53t|%7$2d %|55t|%8$10d %|61t|%9$7d %|76t|%10$5.1f %|84t|%11$5.1f %12%" ); - // 1 2 3 4 5 6 7 8 9 10 11 - ret << (fmt % "#" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Pools") << endl; + boost::format fmt("%1$-3d %2$-20s %3% %|40t|%4$5s %|36t|%5$7.1f %|41t|%6$7d %|44t|%7$3d %|53t|%8$2d %|55t|%9$10d %|61t|%10$7d %|76t|%11$5.1f %|84t|%12$5.1f %13%" ); + // 1 2 3 4 5 6 7 8 9 10 11 12 + ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Pools") << endl; uint64_t totQPS{0}, totQueries{0}, totDrops{0}; int counter=0; @@ -331,7 +335,7 @@ vector> setupLua(bool client, const std::string& confi pools+=p; } - ret << (fmt % counter % s->remote.toStringWithPort() % + ret << (fmt % counter % s->name % s->remote.toStringWithPort() % status % s->queryLoad % s->qps.getRate() % s->order % s->weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->latencyUsec/1000.0) % pools) << endl; @@ -340,7 +344,7 @@ vector> setupLua(bool client, const std::string& confi totDrops += s->reuseds.load(); ++counter; } - ret<< (fmt % "All" % "" % "" + ret<< (fmt % "All" % "" % "" % "" % (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" ) << endl; diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 45d12a681..30287084b 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -234,14 +234,14 @@ void* tcpClientThread(int pipefd) } if (ds->retries > 0 && downstream_failures > ds->retries) { - vinfolog("Downstream connection to %s failed %d times in a row, giving up.", ds->remote.toStringWithPort(), downstream_failures); + vinfolog("Downstream connection to %s failed %d times in a row, giving up.", ds->getName(), downstream_failures); close(dsock); sockets.erase(ds->remote); break; } if(!putNonBlockingMsgLen(dsock, qlen, ds->tcpSendTimeout)) { - vinfolog("Downstream connection to %s died on us, getting a new one!", ds->remote.toStringWithPort()); + vinfolog("Downstream connection to %s died on us, getting a new one!", ds->getName()); close(dsock); sockets[ds->remote]=dsock=setupTCPDownstream(ds->remote); downstream_failures++; @@ -251,7 +251,7 @@ void* tcpClientThread(int pipefd) writen2WithTimeout(dsock, query, qlen, ds->tcpSendTimeout); if(!getNonBlockingMsgLen(dsock, &rlen, ds->tcpRecvTimeout)) { - vinfolog("Downstream connection to %s died on us phase 2, getting a new one!", ds->remote.toStringWithPort()); + vinfolog("Downstream connection to %s died on us phase 2, getting a new one!", ds->getName()); close(dsock); sockets[ds->remote]=dsock=setupTCPDownstream(ds->remote); downstream_failures++; diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index 9f677fb98..e3685e9fc 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -126,6 +126,7 @@ static void connectionThread(int sock, ComboAddress remote, string password) pools+=p+" "; Json::object server{ {"id", num++}, + {"name", a->name}, {"address", a->remote.toStringWithPort()}, {"state", status}, {"qps", (int)a->queryLoad}, diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 4fb2e6cec..254d52505 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -531,7 +531,7 @@ try g_stats.downstreamSendErrors++; } - vinfolog("Got query from %s, relayed to %s", remote.toStringWithPort(), ss->remote.toStringWithPort()); + vinfolog("Got query from %s, relayed to %s", remote.toStringWithPort(), ss->getName()); } catch(std::exception& e){ errlog("Got an error in UDP question thread: %s", e.what()); @@ -596,7 +596,7 @@ void* maintThread() if(dss->availability==DownstreamState::Availability::Auto) { bool newState=upCheck(dss->remote); if(newState != dss->upStatus) { - warnlog("Marking downstream %s as '%s'", dss->remote.toStringWithPort(), newState ? "up" : "down"); + warnlog("Marking downstream %s as '%s'", dss->getName(), newState ? "up" : "down"); } dss->upStatus = newState; } @@ -658,7 +658,7 @@ try if(ret) { if (const auto strValue = boost::get>(&*ret)) { - response=(*strValue)->remote.toStringWithPort(); + response=(*strValue)->getName(); } else if (const auto strValue = boost::get(&*ret)) { response=*strValue; @@ -833,7 +833,7 @@ void doConsole() if(ret) { if (const auto strValue = boost::get>(&*ret)) { - cout<<(*strValue)->remote.toStringWithPort()<getName()<(&*ret)) { cout<<*strValue<availability==DownstreamState::Availability::Auto) { bool newState=upCheck(dss->remote); - warnlog("Marking downstream %s as '%s'", dss->remote.toStringWithPort(), newState ? "up" : "down"); + warnlog("Marking downstream %s as '%s'", dss->getName(), newState ? "up" : "down"); dss->upStatus = newState; } } diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 7d68354b3..cc6502ad7 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -241,6 +241,7 @@ struct DownstreamState std::atomic reuseds{0}; std::atomic queries{0}; } prev; + string name; double queryLoad{0.0}; double dropRate{0.0}; double latencyUsec{0.0}; @@ -264,6 +265,12 @@ struct DownstreamState void setUp() { availability = Availability::Up; } void setDown() { availability = Availability::Down; } void setAuto() { availability = Availability::Auto; } + string getName() const { + if (name.empty()) { + return remote.toStringWithPort(); + } + return name; + } }; using servers_t =vector>; diff --git a/pdns/dnsdistdist/html/local.js b/pdns/dnsdistdist/html/local.js index 68089027b..036db1e1f 100644 --- a/pdns/dnsdistdist/html/local.js +++ b/pdns/dnsdistdist/html/local.js @@ -186,9 +186,9 @@ $(document).ready(function() { $.ajax({ url: '/servers/localhost', type: 'GET', dataType: 'json', success: function(data) { $("#version").text("PowerDNS "+data["daemon_type"]+" "+data["version"]); - var bouw=""; + var bouw="
#AddressStatusQueriesDropsQPSOutWeightOrderPools
"; $.each(data["servers"], function(a,b) { - bouw = bouw + (""); + bouw = bouw + (""); bouw = bouw + (""); bouw = bouw + (""); }); -- 2.40.0
#NameAddressStatusQueriesDropsQPSOutWeightOrderPools
"+b["id"]+""+b["address"]+""+b["state"]+"
"+b["id"]+""+b["name"]+""+b["address"]+""+b["state"]+""+b["queries"]+""+b["reuseds"]+""+b["qps"]+""+b["outstanding"]+""+b["weight"]+""+b["order"]+""+b["pools"]+"