]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/ixfrdist-stats.hh
rec: allow exception to proxy protocal usage for specific listen addresses
[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 "dns.hh"
28 #include "dnsname.hh"
29 #include "pdnsexception.hh"
30
31 class ixfrdistStats {
32 public:
33 ixfrdistStats() {
34 progStats.startTime = time(nullptr);
35 }
36
37 std::string getStats();
38
39 void setSOASerial(const DNSName& d, const uint32_t serial) {
40 auto stat = getRegisteredDomain(d);
41 stat->second.currentSOA = serial;
42 stat->second.haveZone = true;
43 }
44 void incrementSOAChecks(const DNSName& d, const uint64_t amount = 1) {
45 getRegisteredDomain(d)->second.numSOAChecks += amount;
46 }
47 void incrementSOAChecksFailed(const DNSName& d, const uint64_t amount = 1) {
48 getRegisteredDomain(d)->second.numSOAChecksFailed += amount;
49 }
50 void incrementSOAinQueries(const DNSName& d, const uint64_t amount = 1) {
51 getRegisteredDomain(d)->second.numSOAinQueries += amount;
52 }
53 void incrementAXFRinQueries(const DNSName& d, const uint64_t amount = 1) {
54 getRegisteredDomain(d)->second.numAXFRinQueries += amount;
55 }
56 void incrementIXFRinQueries(const DNSName& d, const uint64_t amount = 1) {
57 getRegisteredDomain(d)->second.numIXFRinQueries += amount;
58 }
59 void incrementAXFRFailures(const DNSName& d, const uint64_t amount = 1) {
60 getRegisteredDomain(d)->second.numAXFRFailures += amount;
61 }
62 void incrementIXFRFailures(const DNSName& d, const uint64_t amount = 1) {
63 getRegisteredDomain(d)->second.numIXFRFailures += amount;
64 }
65 void registerDomain(const DNSName& d) {
66 domainStats[d].haveZone = false;
67 }
68
69 void incrementUnknownDomainInQueries(const DNSName& /* d */)
70 { // the name is ignored. It would be great to report it, but we don't want to blow up Prometheus
71 progStats.unknownDomainInQueries += 1;
72 }
73
74 void incrementNotImplemented(uint8_t opcode)
75 {
76 notimpStats.at(opcode) ++;
77 }
78
79 private:
80 class perDomainStat {
81 public:
82 bool haveZone;
83 std::atomic<uint32_t> currentSOA{0}; // NOTE: this will wrongly be zero for unavailable zones
84
85 std::atomic<uint32_t> numSOAChecks{0};
86 std::atomic<uint32_t> numSOAChecksFailed{0};
87
88 std::atomic<uint64_t> numSOAinQueries{0};
89 std::atomic<uint64_t> numAXFRinQueries{0};
90 std::atomic<uint64_t> numIXFRinQueries{0};
91
92 std::atomic<uint64_t> numAXFRFailures{0};
93 std::atomic<uint64_t> numIXFRFailures{0};
94 };
95 class programStats {
96 public:
97 time_t startTime;
98 std::atomic<uint32_t> unknownDomainInQueries{0};
99 };
100
101 std::map<DNSName, perDomainStat> domainStats;
102 std::array<std::atomic<uint64_t>, 16> notimpStats{};
103 programStats progStats;
104
105 std::map<DNSName, perDomainStat>::iterator getRegisteredDomain(const DNSName& d) {
106 auto ret = domainStats.find(d);
107 if (ret == domainStats.end()) {
108 throw PDNSException("Domain '" + d.toLogString() + "' not defined in the statistics map");
109 }
110 return ret;
111 };
112 };
113
114 extern string doGetStats();