]> granicus.if.org Git - pdns/commitdiff
Add a 'name' parameter to newServer(), and display that name instead in the server...
authorRemi Gacogne <rgacogne-github@coredump.fr>
Thu, 12 Nov 2015 09:15:38 +0000 (10:15 +0100)
committerRemi Gacogne <rgacogne-github@coredump.fr>
Thu, 12 Nov 2015 10:53:10 +0000 (11:53 +0100)
pdns/README-dnsdist.md
pdns/dnsdist-carbon.cc
pdns/dnsdist-lua.cc
pdns/dnsdist-tcp.cc
pdns/dnsdist-web.cc
pdns/dnsdist.cc
pdns/dnsdist.hh
pdns/dnsdistdist/html/local.js

index a59e72d08c9d87ddd510d216c42ca4d6e4751484..d4da5e6fa2202c813271aba76ea306beb22d39bc 100644 (file)
@@ -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 
index 3a83d1f49736beef8a746221157651b25ef528f8..a6242779f52d7d6a73552c68fc1fabefaf4df189 100644 (file)
@@ -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<<base<<"queries" << ' ' << s->queries.load() << " " << now << "\r\n";
index 0ef97a5f7d37039b4283d534cc2e4184c1a78a2e..c97be34df787606ed7c59cd9437a1f4f7932137f 100644 (file)
@@ -164,6 +164,10 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
                          ret->tcpRecvTimeout=boost::lexical_cast<int>(boost::get<string>(vars["tcpRecvTimeout"]));
                        }
 
+                       if(vars.count("name")) {
+                         ret->name=boost::get<string>(vars["name"]);
+                       }
+
                        if(g_launchWork) {
                          g_launchWork->push_back([ret]() {
                              ret->tid = move(thread(responderThread, ret));
@@ -308,9 +312,9 @@ vector<std::function<void(void)>> 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<std::function<void(void)>> 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<std::function<void(void)>> setupLua(bool client, const std::string& confi
        totDrops += s->reuseds.load();
        ++counter;
       }
-      ret<< (fmt % "All" % "" % "" 
+      ret<< (fmt % "All" % "" % "" % ""
                % 
             (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" ) << endl;
 
index 45d12a681b119e08b15f3a027cc81c42d88e77c2..30287084bf8780d3ecb5e693b32fbfff42402278 100644 (file)
@@ -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++;
index 9f677fb98290935aa24a7622b305aa40387140f3..e3685e9fc239ace1b8400a59ff16907d0944d003 100644 (file)
@@ -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}, 
index 4fb2e6cec64787278e5a7d0f15dd832e1e1faf97..254d525053522d4e7d5ca733de7f605b57d7977f 100644 (file)
@@ -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<shared_ptr<DownstreamState>>(&*ret)) {
-         response=(*strValue)->remote.toStringWithPort();
+         response=(*strValue)->getName();
        }
        else if (const auto strValue = boost::get<string>(&*ret)) {
          response=*strValue;
@@ -833,7 +833,7 @@ void doConsole()
 
       if(ret) {
        if (const auto strValue = boost::get<shared_ptr<DownstreamState>>(&*ret)) {
-         cout<<(*strValue)->remote.toStringWithPort()<<endl;
+         cout<<(*strValue)->getName()<<endl;
        }
        else if (const auto strValue = boost::get<string>(&*ret)) {
          cout<<*strValue<<endl;
@@ -1100,7 +1100,7 @@ try
   for(auto& dss : g_dstates.getCopy()) { // it is a copy, but the internal shared_ptrs are the real deal
     if(dss->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;
     }
   }
index 7d68354b3dbe3bf869e075666821ccd9a0bbb447..cc6502ad7f509d171ab3e4740f820ce1eae1c964 100644 (file)
@@ -241,6 +241,7 @@ struct DownstreamState
     std::atomic<uint64_t> reuseds{0};
     std::atomic<uint64_t> 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<std::shared_ptr<DownstreamState>>;
 
index 68089027bf939695d6c8bd54d47ed0a808e68ad7..036db1e1f20f6fb04ab8e9e34ade2418331562e7 100644 (file)
@@ -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="<table><tr align=right><th>#</th><th align=left>Address</th><th>Status</th><th>Queries</th><th>Drops</th><th>QPS</th><th>Out</th><th>Weight</th><th>Order</th><th align=left>Pools</th></tr>";
+                    var bouw="<table><tr align=right><th>#</th><th align=left>Name</th><th align=left>Address</th><th>Status</th><th>Queries</th><th>Drops</th><th>QPS</th><th>Out</th><th>Weight</th><th>Order</th><th align=left>Pools</th></tr>";
                     $.each(data["servers"], function(a,b) {
-                        bouw = bouw + ("<tr align=right><td>"+b["id"]+"</td><td align=left>"+b["address"]+"</td><td>"+b["state"]+"</td>");
+                        bouw = bouw + ("<tr align=right><td>"+b["id"]+"</td><td align=left>"+b["name"]+"</td><td align=left>"+b["address"]+"</td><td>"+b["state"]+"</td>");
                          bouw = bouw + ("<td>"+b["queries"]+"</td><td>"+b["reuseds"]+"</td><td>"+b["qps"]+"</td><td>"+b["outstanding"]+"</td>");
                          bouw = bouw + ("<td>"+b["weight"]+"</td><td>"+b["order"]+"</td><td align=left>"+b["pools"]+"</td></tr>");
                         });