]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
hook up getTopBandwidth()
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 3 Dec 2015 19:52:37 +0000 (20:52 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 3 Dec 2015 19:52:37 +0000 (20:52 +0100)
pdns/dnsdist-lua2.cc
pdns/dnsdist-rings.cc
pdns/dnsdist.hh

index be0069f1b3b71f8230dc37a861002456ac04d609..d6b0325353a221c5e7c63ed33afa912c134ecdca 100644 (file)
@@ -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();
+      }
+    });
 }
index 828935a3222d7fa0ce887e4f32c9d0fff8e71261..787260a663b5fa412848175f26682c2ccbbfccb4 100644 (file)
@@ -10,7 +10,7 @@ unsigned int Rings::numDistinctRequestors()
   return s.size();
 }
 
-vector<pair<unsigned int,ComboAddress> > Rings::getTopBandwidth(int numentries)
+vector<pair<unsigned int,ComboAddress> > Rings::getTopBandwidth(unsigned int numentries)
 {
   map<ComboAddress, unsigned int, ComboAddress::addressOnlyLessThan> counts;
   {
@@ -29,6 +29,7 @@ vector<pair<unsigned int,ComboAddress> > 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);
index edc9d15f0bcf442f0e07c18c103e37c751ee2cd6..d1ca2dd5d9b11e7db70be9e55cde3e8a5e0fdb17 100644 (file)
@@ -212,7 +212,7 @@ struct Rings {
   std::mutex respMutex;
   pthread_rwlock_t queryLock;
 
-  vector<pair<unsigned int, ComboAddress> > getTopBandwidth(int numentries);
+  vector<pair<unsigned int, ComboAddress> > getTopBandwidth(unsigned int numentries);
   unsigned int numDistinctRequestors();
 };