]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/ixfrdist-stats.hh
Merge pull request #7870 from omoerbeek/stubquery-fix-arg
[thirdparty/pdns.git] / pdns / ixfrdist-stats.hh
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"
28 #include "pdnsexception.hh"
29
30 class ixfrdistStats {
31 public:
32 ixfrdistStats() {
33 progStats.startTime = time(nullptr);
34 }
35
36 std::string getStats();
37
38 void setSOASerial(const DNSName& d, const uint32_t serial) {
39 auto stat = getRegisteredDomain(d);
40 stat->second.currentSOA = serial;
41 stat->second.haveZone = true;
42 }
43 void incrementSOAChecks(const DNSName& d, const uint64_t amount = 1) {
44 getRegisteredDomain(d)->second.numSOAChecks += amount;
45 }
46 void incrementSOAChecksFailed(const DNSName& d, const uint64_t amount = 1) {
47 getRegisteredDomain(d)->second.numSOAChecksFailed += amount;
48 }
49 void incrementSOAinQueries(const DNSName& d, const uint64_t amount = 1) {
50 getRegisteredDomain(d)->second.numSOAinQueries += amount;
51 }
52 void incrementAXFRinQueries(const DNSName& d, const uint64_t amount = 1) {
53 getRegisteredDomain(d)->second.numAXFRinQueries += amount;
54 }
55 void incrementIXFRinQueries(const DNSName& d, const uint64_t amount = 1) {
56 getRegisteredDomain(d)->second.numIXFRinQueries += amount;
57 }
58 void incrementAXFRFailures(const DNSName& d, const uint64_t amount = 1) {
59 getRegisteredDomain(d)->second.numAXFRFailures += amount;
60 }
61 void incrementIXFRFailures(const DNSName& d, const uint64_t amount = 1) {
62 getRegisteredDomain(d)->second.numIXFRFailures += amount;
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;
77 std::atomic<uint64_t> numAXFRinQueries;
78 std::atomic<uint64_t> numIXFRinQueries;
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;
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 };
98 };