-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
#include "rec-responsestats.hh"
-#include <limits>
-
-#include "namespaces.hh"
-#include "logger.hh"
-
#include "dnsparser.hh"
static auto sizeBounds()
bounds.push_back(80);
bounds.push_back(100);
bounds.push_back(150);
- for (uint64_t n = 200; n < 65000; n += 200) {
- bounds.push_back(n);
+ for (uint64_t count = 200; count < 65000; count += 200) {
+ bounds.push_back(count);
}
return bounds;
}
RecResponseStats::RecResponseStats() :
d_sizecounters("SizeCounters", sizeBounds())
{
- for (auto& entry : d_qtypecounters) {
- entry = 0;
- }
- for (auto& entry : d_rcodecounters) {
- entry = 0;
- }
}
RecResponseStats& RecResponseStats::operator+=(const RecResponseStats& rhs)
return *this;
}
-map<uint16_t, uint64_t> RecResponseStats::getQTypeResponseCounts() const
+std::map<uint16_t, uint64_t> RecResponseStats::getQTypeResponseCounts() const
{
- map<uint16_t, uint64_t> ret;
+ std::map<uint16_t, uint64_t> ret;
for (size_t i = 0; i < d_qtypecounters.size(); ++i) {
auto count = d_qtypecounters.at(i);
if (count != 0) {
return ret;
}
-map<uint16_t, uint64_t> RecResponseStats::getSizeResponseCounts() const
+std::map<uint16_t, uint64_t> RecResponseStats::getSizeResponseCounts() const
{
- map<uint16_t, uint64_t> ret;
+ std::map<uint16_t, uint64_t> ret;
for (const auto& sizecounter : d_sizecounters.getRawData()) {
if (sizecounter.d_count > 0) {
ret[sizecounter.d_boundary] = sizecounter.d_count;
return ret;
}
-map<uint8_t, uint64_t> RecResponseStats::getRCodeResponseCounts() const
+std::map<uint8_t, uint64_t> RecResponseStats::getRCodeResponseCounts() const
{
- map<uint8_t, uint64_t> ret;
+ std::map<uint8_t, uint64_t> ret;
for (size_t i = 0; i < d_rcodecounters.size(); ++i) {
auto count = d_rcodecounters.at(i);
if (count != 0) {
return ret;
}
-string RecResponseStats::getQTypeReport() const
+std::string RecResponseStats::getQTypeReport() const
{
auto qtypenums = getQTypeResponseCounts();
- ostringstream ostr;
+ std::ostringstream ostr;
for (const auto& val : qtypenums) {
ostr << DNSRecordContent::NumberToType(val.first) << '\t' << std::to_string(val.second) << endl;
}
#pragma once
#include <array>
+#include <map>
+#include <string>
#include "histogram.hh"
-#include "dnspacket.hh"
class RecResponseStats
{
}
d_sizecounters(respsize);
}
- map<uint16_t, uint64_t> getQTypeResponseCounts() const;
- map<uint16_t, uint64_t> getSizeResponseCounts() const;
- map<uint8_t, uint64_t> getRCodeResponseCounts() const;
- string getQTypeReport() const;
+ std::map<uint16_t, uint64_t> getQTypeResponseCounts() const;
+ std::map<uint16_t, uint64_t> getSizeResponseCounts() const;
+ std::map<uint8_t, uint64_t> getRCodeResponseCounts() const;
+ std::string getQTypeReport() const;
private:
std::array<uint64_t, maxQType + 1> d_qtypecounters{};
auto& lhs = doubleWAvg.at(i);
const auto& rhs = data.doubleWAvg.at(i);
auto weight = lhs.weight + rhs.weight;
- auto avg = lhs.avg * static_cast<double>(lhs.weight) + rhs.avg * static_cast<double>(rhs.weight);
+ auto avg = (lhs.avg * static_cast<double>(lhs.weight)) + (rhs.avg * static_cast<double>(rhs.weight));
avg = weight == 0 ? 0 : avg / static_cast<double>(weight);
lhs.avg = avg;
lhs.weight = weight;
void addToRollingAvg(double value, uint64_t rollsize)
{
- add((1.0 - 1.0 / static_cast<double>(rollsize)) * avg + value / static_cast<double>(rollsize));
+ add(((1.0 - 1.0 / static_cast<double>(rollsize)) * avg) + (value / static_cast<double>(rollsize)));
}
};
// And an array of weighted averaged values
return *this;
}
static const size_t numberOfRCodes = 16;
- std::array<uint64_t, numberOfRCodes> rcodeCounters;
+ std::array<uint64_t, numberOfRCodes> rcodeCounters{};
};
// An RCodes histogram
- RCodeCounters auth{};
+ RCodeCounters auth;
std::array<pdns::Histogram, static_cast<size_t>(Histogram::numberOfCounters)> histograms = {
pdns::Histogram{"answers", {1000, 10000, 100000, 1000000}},
pdns::Histogram{"cumul-authanswers-", 1000, 13}};
// Response stats
- RecResponseStats responseStats{};
+ RecResponseStats responseStats;
// DNSSEC stats
struct DNSSECCounters
{
return counts.at(static_cast<size_t>(index));
}
- std::array<uint64_t, static_cast<size_t>(vState::BogusInvalidDNSKEYProtocol) + 1> counts;
+ std::array<uint64_t, static_cast<size_t>(vState::BogusInvalidDNSKEYProtocol) + 1> counts{};
};
std::array<DNSSECCounters, static_cast<size_t>(DNSSECHistogram::numberOfCounters)> dnssecCounters{};
{
return counts.at(static_cast<size_t>(index));
}
- std::array<uint64_t, static_cast<size_t>(DNSFilterEngine::PolicyKind::Custom) + 1> counts;
+ std::array<uint64_t, static_cast<size_t>(DNSFilterEngine::PolicyKind::Custom) + 1> counts{};
};
- PolicyCounters policyCounters{};
+ PolicyCounters policyCounters;
// Policy hits by name
struct PolicyNameCounters
};
PolicyNameCounters policyNameHits;
- Counters()
- {
- for (auto& elem : uint64Count) {
- elem = 0;
- }
- // doubleWAvg has a default constructor that initializes
- for (auto& elem : auth.rcodeCounters) {
- elem = 0;
- }
- // Histogram has a constructor that initializes
- // RecResponseStats has a default constructor that initializes
- for (auto& histogram : dnssecCounters) {
- for (auto& elem : histogram.counts) {
- elem = 0;
- }
- }
- for (auto& elem : policyCounters.counts) {
- elem = 0;
- }
- // PolicyNameCounters has a default constuctor that initializes
- }
+ Counters() = default;
+ // {
+ // // uint64Count field has initalizer
+ // // doubleWAvg has a default constructor that initializes
+ // // auth.RCodeCounters field is initalized
+ // // Histogram has a constructor that initializes
+ // // RecResponseStats has a default constructor that initializes
+ // // dnssecCounters field is initialized
+ // // PolicyNameCounters has a default constuctor that initializes
+ // }
// Merge a set of counters into an existing set of counters. For simple counters, that will be additions
// for averages, we should take the weights into account. Histograms need to sum all individual counts.
}
// We only have a single PolicyHistogram indexed PolicyCounters, so no need to select a specific one
- PolicyCounters& at(PolicyHistogram)
+ PolicyCounters& at(PolicyHistogram /* unused */)
{
return policyCounters;
}
#pragma once
#include <sys/time.h>
-#include <array>
#include <set>
#include <unistd.h>