]>
Commit | Line | Data |
---|---|---|
42d4d25b PD |
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 | */ | |
22 | #pragma once | |
23 | #include <atomic> | |
24 | #include <map> | |
25 | #include <string> | |
26 | ||
27 | #include "dnsname.hh" | |
47de343d | 28 | #include "pdnsexception.hh" |
42d4d25b PD |
29 | |
30 | class ixfrdistStats { | |
31 | public: | |
32 | ixfrdistStats() { | |
33 | progStats.startTime = time(nullptr); | |
34 | } | |
35 | ||
ef9ebc82 | 36 | std::string getStats(); |
42d4d25b PD |
37 | |
38 | void setSOASerial(const DNSName& d, const uint32_t serial) { | |
47de343d PL |
39 | auto stat = getRegisteredDomain(d); |
40 | stat->second.currentSOA = serial; | |
41 | stat->second.haveZone = true; | |
42d4d25b PD |
42 | } |
43 | void incrementSOAChecks(const DNSName& d, const uint64_t amount = 1) { | |
47de343d | 44 | getRegisteredDomain(d)->second.numSOAChecks += amount; |
42d4d25b PD |
45 | } |
46 | void incrementSOAChecksFailed(const DNSName& d, const uint64_t amount = 1) { | |
47de343d | 47 | getRegisteredDomain(d)->second.numSOAChecksFailed += amount; |
42d4d25b PD |
48 | } |
49 | void incrementSOAinQueries(const DNSName& d, const uint64_t amount = 1) { | |
47de343d | 50 | getRegisteredDomain(d)->second.numSOAinQueries += amount; |
42d4d25b | 51 | } |
4140208a | 52 | void incrementAXFRinQueries(const DNSName& d, const uint64_t amount = 1) { |
47de343d | 53 | getRegisteredDomain(d)->second.numAXFRinQueries += amount; |
42d4d25b | 54 | } |
4140208a | 55 | void incrementIXFRinQueries(const DNSName& d, const uint64_t amount = 1) { |
47de343d | 56 | getRegisteredDomain(d)->second.numIXFRinQueries += amount; |
42d4d25b PD |
57 | } |
58 | void incrementAXFRFailures(const DNSName& d, const uint64_t amount = 1) { | |
47de343d | 59 | getRegisteredDomain(d)->second.numAXFRFailures += amount; |
42d4d25b PD |
60 | } |
61 | void incrementIXFRFailures(const DNSName& d, const uint64_t amount = 1) { | |
47de343d | 62 | getRegisteredDomain(d)->second.numIXFRFailures += amount; |
42d4d25b PD |
63 | } |
64 | void registerDomain(const DNSName& d) { | |
65 | domainStats[d].haveZone = false; | |
66 | } | |
67 | private: | |
68 | class perDomainStat { | |
69 | public: | |
70 | bool haveZone; | |
71 | std::atomic<uint32_t> currentSOA; // NOTE: this will wrongly be zero for unavailable zones | |
72 | ||
73 | std::atomic<uint32_t> numSOAChecks; | |
74 | std::atomic<uint32_t> numSOAChecksFailed; | |
75 | ||
76 | std::atomic<uint64_t> numSOAinQueries; | |
42d4d25b | 77 | std::atomic<uint64_t> numAXFRinQueries; |
4140208a | 78 | std::atomic<uint64_t> numIXFRinQueries; |
42d4d25b PD |
79 | |
80 | std::atomic<uint64_t> numAXFRFailures; | |
81 | std::atomic<uint64_t> numIXFRFailures; | |
82 | }; | |
83 | class programStats { | |
84 | public: | |
85 | time_t startTime; | |
86 | }; | |
87 | ||
88 | std::map<DNSName, perDomainStat> domainStats; | |
89 | programStats progStats; | |
47de343d PL |
90 | |
91 | std::map<DNSName, perDomainStat>::iterator getRegisteredDomain(const DNSName& d) { | |
92 | auto ret = domainStats.find(d); | |
93 | if (ret == domainStats.end()) { | |
94 | throw PDNSException("Domain '" + d.toLogString() + "' not defined in the statistics map"); | |
95 | } | |
96 | return ret; | |
97 | }; | |
42d4d25b | 98 | }; |