From ddafcf1e664bc9b6341debca0a2236fbffdb5035 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 3 Dec 2015 20:52:37 +0100 Subject: [PATCH] hook up getTopBandwidth() --- pdns/dnsdist-lua2.cc | 8 +++++++- pdns/dnsdist-rings.cc | 3 ++- pdns/dnsdist.hh | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) 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(); }; -- 2.47.2