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.
28 #include "pdnsexception.hh"
33 progStats.startTime = time(nullptr);
36 std::string getStats();
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;
43 void incrementSOAChecks(const DNSName& d, const uint64_t amount = 1) {
44 getRegisteredDomain(d)->second.numSOAChecks += amount;
46 void incrementSOAChecksFailed(const DNSName& d, const uint64_t amount = 1) {
47 getRegisteredDomain(d)->second.numSOAChecksFailed += amount;
49 void incrementSOAinQueries(const DNSName& d, const uint64_t amount = 1) {
50 getRegisteredDomain(d)->second.numSOAinQueries += amount;
52 void incrementAXFRinQueries(const DNSName& d, const uint64_t amount = 1) {
53 getRegisteredDomain(d)->second.numAXFRinQueries += amount;
55 void incrementIXFRinQueries(const DNSName& d, const uint64_t amount = 1) {
56 getRegisteredDomain(d)->second.numIXFRinQueries += amount;
58 void incrementAXFRFailures(const DNSName& d, const uint64_t amount = 1) {
59 getRegisteredDomain(d)->second.numAXFRFailures += amount;
61 void incrementIXFRFailures(const DNSName& d, const uint64_t amount = 1) {
62 getRegisteredDomain(d)->second.numIXFRFailures += amount;
64 void registerDomain(const DNSName& d) {
65 domainStats[d].haveZone = false;
71 std::atomic<uint32_t> currentSOA; // NOTE: this will wrongly be zero for unavailable zones
73 std::atomic<uint32_t> numSOAChecks;
74 std::atomic<uint32_t> numSOAChecksFailed;
76 std::atomic<uint64_t> numSOAinQueries;
77 std::atomic<uint64_t> numAXFRinQueries;
78 std::atomic<uint64_t> numIXFRinQueries;
80 std::atomic<uint64_t> numAXFRFailures;
81 std::atomic<uint64_t> numIXFRFailures;
88 std::map<DNSName, perDomainStat> domainStats;
89 programStats progStats;
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");