]>
Commit | Line | Data |
---|---|---|
12471842 PL |
1 | /* |
2 | * This file is part of PowerDNS or dnsdist. | |
3 | * Copyright -- PowerDNS.COM B.V. and its contributors | |
4 | * | |
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. | |
8 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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. | |
21 | */ | |
6264512b | 22 | #pragma once |
23 | #include "dnsname.hh" | |
6264512b | 24 | #include <map> |
25 | #include "iputils.hh" | |
26 | ||
27 | class StatNode | |
28 | { | |
29 | public: | |
6264512b | 30 | |
aec222df | 31 | struct Stat |
6264512b | 32 | { |
abb11ca4 | 33 | Stat() {}; |
6ecfaee2 RG |
34 | uint64_t queries{0}; |
35 | uint64_t noerrors{0}; | |
36 | uint64_t nxdomains{0}; | |
37 | uint64_t servfails{0}; | |
38 | uint64_t drops{0}; | |
39 | uint64_t bytes{0}; | |
40 | uint64_t hits{0}; | |
41 | using remotes_t = std::map<ComboAddress,int,ComboAddress::addressOnlyLessThan>; | |
42 | remotes_t remotes; | |
6264512b | 43 | |
44 | Stat& operator+=(const Stat& rhs) { | |
6ecfaee2 RG |
45 | queries += rhs.queries; |
46 | noerrors += rhs.noerrors; | |
47 | nxdomains += rhs.nxdomains; | |
48 | servfails += rhs.servfails; | |
49 | drops += rhs.drops; | |
50 | bytes += rhs.bytes; | |
51 | hits += rhs.hits; | |
6264512b | 52 | |
6ecfaee2 RG |
53 | for (const remotes_t::value_type& rem : rhs.remotes) { |
54 | remotes[rem.first] += rem.second; | |
7d07129c | 55 | } |
6264512b | 56 | return *this; |
57 | } | |
6264512b | 58 | }; |
59 | ||
6ecfaee2 RG |
60 | using visitor_t = std::function<void(const StatNode*, const Stat& selfstat, const Stat& childstat)>; |
61 | using children_t = std::map<std::string, StatNode, CIStringCompare>; | |
62 | ||
6264512b | 63 | Stat s; |
431c4359 RG |
64 | std::string name; |
65 | std::string fullname; | |
a4244240 | 66 | uint8_t labelsCount{0}; |
431c4359 | 67 | |
224085cc | 68 | void submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, const boost::optional<const ComboAddress&>& remote); |
431c4359 | 69 | Stat print(unsigned int depth=0, Stat newstat=Stat(), bool silent=false) const; |
224085cc | 70 | void visit(const visitor_t& visitor, Stat& newstat, unsigned int depth = 0) const; |
23adffab RG |
71 | bool empty() const |
72 | { | |
73 | return children.empty() && s.remotes.empty(); | |
74 | } | |
6264512b | 75 | children_t children; |
aec222df RG |
76 | |
77 | private: | |
224085cc | 78 | void submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, const boost::optional<const ComboAddress&>& remote, unsigned int count, bool hit); |
6264512b | 79 | }; |