From: bert hubert Date: Thu, 3 Dec 2015 19:52:37 +0000 (+0100) Subject: hook up getTopBandwidth() X-Git-Tag: dnsdist-1.0.0-alpha1~126^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddafcf1e664bc9b6341debca0a2236fbffdb5035;p=thirdparty%2Fpdns.git hook up getTopBandwidth() --- diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index be0069f1b3..d6b0325353 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -156,5 +156,11 @@ void moreLua() }); - + g_lua.writeFunction("topBandwidth", [](unsigned int top) { + auto res = g_rings.getTopBandwidth(top); + boost::format fmt("%7d %s\n"); + for(const auto& l : res) { + g_outputBuffer += (fmt % l.first % l.second.toString()).str(); + } + }); } diff --git a/pdns/dnsdist-rings.cc b/pdns/dnsdist-rings.cc index 828935a322..787260a663 100644 --- a/pdns/dnsdist-rings.cc +++ b/pdns/dnsdist-rings.cc @@ -10,7 +10,7 @@ unsigned int Rings::numDistinctRequestors() return s.size(); } -vector > Rings::getTopBandwidth(int numentries) +vector > Rings::getTopBandwidth(unsigned int numentries) { map counts; { @@ -29,6 +29,7 @@ vector > Rings::getTopBandwidth(int numentries) ret_t ret; for(const auto& p : counts) ret.push_back({p.second, p.first}); + numentries = ret.size() < numentries ? ret.size() : numentries; partial_sort(ret.begin(), ret.begin()+numentries, ret.end(), [](const ret_t::value_type&a, const ret_t::value_type&b) { return(b.second < a.second); diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index edc9d15f0b..d1ca2dd5d9 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -212,7 +212,7 @@ struct Rings { std::mutex respMutex; pthread_rwlock_t queryLock; - vector > getTopBandwidth(int numentries); + vector > getTopBandwidth(unsigned int numentries); unsigned int numDistinctRequestors(); };