uint16_t g_maxUdpSourcePort;
double g_balancingFactor;
-RecursorStats g_stats;
bool g_lowercaseOutgoing;
unsigned int g_networkTimeoutMsec;
uint16_t g_outgoingEDNSBufsize;
{
/* don't account truncate actions for TCP queries, since they are not applied */
if (appliedPolicy.d_kind != DNSFilterEngine::PolicyKind::Truncate || !dc->d_tcp) {
- //++g_stats.policyResults[appliedPolicy.d_kind];
- t_Counters.at(rec::PolicyHistogram::policy).at(appliedPolicy.d_kind)++;
- ++(g_stats.policyHits.lock()->operator[](appliedPolicy.getName()));
+ ++t_Counters.at(rec::PolicyHistogram::policy).at(appliedPolicy.d_kind);
+ ++t_Counters.at(rec::PolicyNameHits::policyName).counts[appliedPolicy.getName()];
}
if (sr.doLog() && appliedPolicy.d_type != DNSFilterEngine::PolicyType::None) {
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);
- avg = weight == 0 ? 0 : avg / weight;
+ avg = weight == 0 ? 0 : avg / static_cast<double>(weight);
lhs.avg = avg;
lhs.weight = weight;
}
+
// Rcode Counters are simply added
for (size_t i = 0; i < auth.rcodeCounters.size(); i++) {
auth.rcodeCounters.at(i) += data.auth.rcodeCounters.at(i);
}
+
// Histograms counts are added by += operator on Histograms
for (size_t i = 0; i < histograms.size(); i++) {
histograms.at(i) += data.histograms.at(i);
}
+
+ // ResponseStats knows how to add
responseStats += data.responseStats;
// DNSSEC histograms: add individual entries
lhs.counts.at(j) += rhs.counts.at(j);
}
}
+
+ // policy kind counters: add individual entries
for (size_t i = 0; i < policyCounters.counts.size(); i++) {
policyCounters.counts.at(i) += data.policyCounters.counts.at(i);
}
+ // Policy name counts knows how to add
+ policyNameHits += data.policyNameHits;
+
return *this;
}
}
stream << "Histograms: ";
for (const auto& element : histograms) {
- stream << element.getName() << ": NYI";
+ stream << element.getName() << ": NYI ";
}
stream << "DNSSEC Histograms: ";
- stream << "NYI";
+ stream << "NYI ";
+ stream << "Policy Counters: ";
+ stream << "NYI ";
+ stream << "Policy Name Counters: ";
+ stream << "NYI ";
stream << std::endl;
return stream.str();
enum class PolicyHistogram : uint8_t
{
policy,
-
+
+ numberOfCounters
+};
+
+enum class PolicyNameHits : uint8_t
+{
+ policyName,
+
numberOfCounters
};
};
PolicyCounters policyCounters{};
+ // Policy hits by name
+ struct PolicyNameCounters
+ {
+ PolicyNameCounters& operator+=(const PolicyNameCounters& rhs)
+ {
+ for (const auto& [name, count] : rhs.counts) {
+ counts[name] += count;
+ }
+ return *this;
+ }
+ std::unordered_map<std::string, uint64_t> counts;
+ };
+ PolicyNameCounters policyNameHits;
+
Counters()
{
for (auto& elem : uint64Count) {
for (auto& elem : policyCounters.counts) {
elem = 0;
}
+ // 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
return doubleWAvg.at(static_cast<size_t>(index));
}
- RCodeCounters& at(RCode index)
+ RCodeCounters& at(RCode /*unused*/)
{
// We only have a single RCode indexed Histogram, so no need to select a specific one
return auth;
}
- RecResponseStats& at(ResponseStats index)
+ RecResponseStats& at(ResponseStats /*unused*/)
{
// We only have a single ResponseStats indexed RecResponseStats, so no need to select a specific one
return responseStats;
return dnssecCounters.at(static_cast<size_t>(index));
}
- PolicyCounters& at(PolicyHistogram index)
+ // We only have a single PolicyHistogram indexed PolicyCounters, so no need to select a specific one
+ PolicyCounters& at(PolicyHistogram)
{
return policyCounters;
}
+ // We only have a single policyNameHits indexed PolicyNameCounters, so no need to select a specific one
+ PolicyNameCounters& at(PolicyNameHits /*unused*/)
+ {
+ return policyNameHits;
+ }
+
// Mainly for debugging purposes
[[nodiscard]] std::string toString() const;
};
return entries;
}
-static StatsMap toRPZStatsMap(const string& name, LockGuarded<std::unordered_map<std::string, pdns::stat_t>>& map)
+static StatsMap toRPZStatsMap(const string& name, const std::unordered_map<std::string, uint64_t>& map)
{
const string pbasename = getPrometheusName(name);
StatsMap entries;
uint64_t total = 0;
- for (const auto& entry : *map.lock()) {
- auto& key = entry.first;
- auto count = entry.second.load();
+ for (const auto& entry : map) {
+ const auto& key = entry.first;
+ auto count = entry.second;
std::string sname, pname;
if (key.empty()) {
sname = name + "-filter";
return toStatsMap(t_Counters.at(rec::Histogram::cumulativeAuth4Answers).getName(), g_Counters.sum(rec::Histogram::cumulativeAuth4Answers), g_Counters.sum(rec::Histogram::cumulativeAuth6Answers));
});
addGetStat("policy-hits", []() {
- return toRPZStatsMap("policy-hits", g_stats.policyHits);
+ return toRPZStatsMap("policy-hits", g_Counters.sum(rec::PolicyNameHits::policyName).counts);
});
addGetStat("proxy-mapping-total", []() {
return toProxyMappingStatsMap("proxy-mapping-total");
/* don't account truncate actions for TCP queries, since they are not applied */
if (d_appliedPolicy.d_kind != DNSFilterEngine::PolicyKind::Truncate || !d_queryReceivedOverTCP) {
- t_Counters.at(rec::PolicyHistogram::policy).at(d_appliedPolicy.d_kind)++;
- //++g_stats.policyResults[d_appliedPolicy.d_kind];
- ++(g_stats.policyHits.lock()->operator[](d_appliedPolicy.getName()));
+ ++t_Counters.at(rec::PolicyHistogram::policy).at(d_appliedPolicy.d_kind);
+ ++t_Counters.at(rec::PolicyNameHits::policyName).counts[d_appliedPolicy.getName()];
}
if (d_appliedPolicy.d_type != DNSFilterEngine::PolicyType::None) {
extern rec::GlobalCounters g_Counters;
extern thread_local rec::TCounters t_Counters;
-struct RecursorStats
-{
- // XXX Convert counters below to be part of rec::Counters
- LockGuarded<std::unordered_map<std::string, pdns::stat_t>> policyHits;
-};
-
//! represents a running TCP/IP client session
class TCPConnection : public boost::noncopyable
{
extern thread_local std::shared_ptr<NetmaskGroup> t_allowFrom;
extern thread_local std::shared_ptr<NetmaskGroup> t_allowNotifyFrom;
string doTraceRegex(vector<string>::const_iterator begin, vector<string>::const_iterator end);
-extern RecursorStats g_stats;
extern unsigned int g_networkTimeoutMsec;
extern uint16_t g_outgoingEDNSBufsize;
extern std::atomic<uint32_t> g_maxCacheEntries, g_maxPacketCacheEntries;
#include "rec-taskqueue.hh"
#include "test-syncres_cc.hh"
-RecursorStats g_stats;
GlobalStateHolder<LuaConfigItems> g_luaconfs;
GlobalStateHolder<SuffixMatchNode> g_xdnssec;
GlobalStateHolder<SuffixMatchNode> g_dontThrottleNames;