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.
29 #include "pdnsexception.hh"
34 progStats.startTime = time(nullptr);
37 std::string getStats();
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;
44 void incrementSOAChecks(const DNSName& d, const uint64_t amount = 1) {
45 getRegisteredDomain(d)->second.numSOAChecks += amount;
47 void incrementSOAChecksFailed(const DNSName& d, const uint64_t amount = 1) {
48 getRegisteredDomain(d)->second.numSOAChecksFailed += amount;
50 void incrementSOAinQueries(const DNSName& d, const uint64_t amount = 1) {
51 getRegisteredDomain(d)->second.numSOAinQueries += amount;
53 void incrementAXFRinQueries(const DNSName& d, const uint64_t amount = 1) {
54 getRegisteredDomain(d)->second.numAXFRinQueries += amount;
56 void incrementIXFRinQueries(const DNSName& d, const uint64_t amount = 1) {
57 getRegisteredDomain(d)->second.numIXFRinQueries += amount;
59 void incrementAXFRFailures(const DNSName& d, const uint64_t amount = 1) {
60 getRegisteredDomain(d)->second.numAXFRFailures += amount;
62 void incrementIXFRFailures(const DNSName& d, const uint64_t amount = 1) {
63 getRegisteredDomain(d)->second.numIXFRFailures += amount;
65 void registerDomain(const DNSName& d) {
66 domainStats[d].haveZone = false;
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;
74 void incrementNotImplemented(uint8_t opcode)
76 notimpStats.at(opcode) ++;
83 std::atomic<uint32_t> currentSOA{0}; // NOTE: this will wrongly be zero for unavailable zones
85 std::atomic<uint32_t> numSOAChecks{0};
86 std::atomic<uint32_t> numSOAChecksFailed{0};
88 std::atomic<uint64_t> numSOAinQueries{0};
89 std::atomic<uint64_t> numAXFRinQueries{0};
90 std::atomic<uint64_t> numIXFRinQueries{0};
92 std::atomic<uint64_t> numAXFRFailures{0};
93 std::atomic<uint64_t> numIXFRFailures{0};
98 std::atomic<uint32_t> unknownDomainInQueries{0};
101 std::map<DNSName, perDomainStat> domainStats;
102 std::array<std::atomic<uint64_t>, 16> notimpStats{};
103 programStats progStats;
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");
114 extern string doGetStats();