From: bert hubert Date: Wed, 11 Mar 2015 19:17:04 +0000 (+0100) Subject: add topClients() X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~88^2~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e5b3cffbfd43686df0ecefb6e17eab6746ff0a2;p=pdns add topClients() --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 416c62944..0a53ba552 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -398,6 +398,33 @@ vector> setupLua(bool client) } }); + // something needs to be done about this, unlocked will 'mostly' work + g_lua.writeFunction("topClients", [](unsigned int top) { + map counts; + unsigned int total=0; + for(const auto& c : g_rings.clientRing) { + counts[c]++; + total++; + } + vector> rcounts; + for(const auto& c : counts) + rcounts.push_back(make_pair(c.second, c.first)); + + sort(rcounts.begin(), rcounts.end(), [](const decltype(rcounts)::value_type& a, + const decltype(rcounts)::value_type& b) { + return b.first < a.first; + }); + unsigned int count=1, rest=0; + boost::format fmt("%4d %-40s %4d %4.1f%%\n"); + for(const auto& rc : rcounts) { + if(count==top+1) + rest+=rc.first; + else + g_outputBuffer += (fmt % (count++) % rc.second.toString() % rc.first % (100.0*rc.first/total)).str(); + } + g_outputBuffer += (fmt % (count) % "Rest" % rest % (100.0*rest/total)).str(); + }); + // something needs to be done about this, unlocked will 'mostly' work g_lua.writeFunction("getTopQueries", [](unsigned int top, boost::optional labels) {