]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsdist-rings.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "dnsdist-rings.hh"
25 size_t Rings::numDistinctRequestors()
27 std::set
<ComboAddress
, ComboAddress::addressOnlyLessThan
> s
;
28 for (const auto& shard
: d_shards
) {
29 std::lock_guard
<std::mutex
> rl(shard
->queryLock
);
30 for(const auto& q
: shard
->queryRing
) {
31 s
.insert(q
.requestor
);
37 std::unordered_map
<int, vector
<boost::variant
<string
,double>>> Rings::getTopBandwidth(unsigned int numentries
)
39 map
<ComboAddress
, unsigned int, ComboAddress::addressOnlyLessThan
> counts
;
41 for (const auto& shard
: d_shards
) {
43 std::lock_guard
<std::mutex
> rl(shard
->queryLock
);
44 for(const auto& q
: shard
->queryRing
) {
45 counts
[q
.requestor
]+=q
.size
;
50 std::lock_guard
<std::mutex
> rl(shard
->respLock
);
51 for(const auto& r
: shard
->respRing
) {
52 counts
[r
.requestor
]+=r
.size
;
58 typedef vector
<pair
<unsigned int, ComboAddress
>> ret_t
;
60 rcounts
.reserve(counts
.size());
61 for(const auto& p
: counts
)
62 rcounts
.push_back({p
.second
, p
.first
});
63 numentries
= rcounts
.size() < numentries
? rcounts
.size() : numentries
;
64 partial_sort(rcounts
.begin(), rcounts
.begin()+numentries
, rcounts
.end(), [](const ret_t::value_type
&a
, const ret_t::value_type
&b
)
66 return(b
.first
< a
.first
);
68 std::unordered_map
<int, vector
<boost::variant
<string
,double>>> ret
;
70 unsigned int count
= 1;
71 for(const auto& rc
: rcounts
) {
72 if(count
==numentries
+1) {
76 ret
.insert({count
++, {rc
.second
.toString(), rc
.first
, 100.0*rc
.first
/total
}});
79 ret
.insert({count
, {"Rest", rest
, total
> 0 ? 100.0*rest
/total
: 100.0}});