}
});
- // something needs to be done about this, unlocked will 'mostly' work
+
g_lua.writeFunction("topClients", [](unsigned int top) {
map<ComboAddress, int,ComboAddress::addressOnlyLessThan > counts;
unsigned int total=0;
--- /dev/null
+#include "dnsdist.hh"
+#include "lock.hh"
+
+unsigned int Rings::numDistinctRequestors()
+{
+ std::set<ComboAddress, ComboAddress::addressOnlyLessThan> s;
+ WriteLock wl(&queryLock);
+ for(const auto& q : queryRing)
+ s.insert(q.requestor);
+ return s.size();
+}
+
+vector<pair<unsigned int,ComboAddress> > Rings::getTopBandwidth(int numentries)
+{
+ map<ComboAddress, unsigned int, ComboAddress::addressOnlyLessThan> counts;
+ {
+ WriteLock wl(&queryLock);
+ for(const auto& q : queryRing)
+ counts[q.requestor]+=q.size;
+ }
+
+ {
+ std::lock_guard<std::mutex> lock(respMutex);
+ for(const auto& r : respRing)
+ counts[r.requestor]+=r.size;
+ }
+
+ typedef vector<pair<unsigned int, ComboAddress>> ret_t;
+ ret_t ret;
+ for(const auto& p : counts)
+ ret.push_back({p.second, p.first});
+ 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);
+ });
+ ret.resize(numentries);
+ return ret;
+}
struct timespec when;
ComboAddress requestor;
DNSName name;
+ uint16_t size;
uint16_t qtype;
};
boost::circular_buffer<Query> queryRing;
boost::circular_buffer<Response> respRing;
std::mutex respMutex;
pthread_rwlock_t queryLock;
+
+ vector<pair<unsigned int, ComboAddress> > getTopBandwidth(int numentries);
+ unsigned int numDistinctRequestors();
};
extern Rings g_rings;