From: Remi Gacogne Date: Fri, 29 Sep 2023 13:52:10 +0000 (+0200) Subject: dnsdist: Fix eBPF metrics in the internal web server X-Git-Tag: rec-5.0.0-alpha2~35^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F13310%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Fix eBPF metrics in the internal web server We used to only display eBPF dynamic blocks for the Dynamic BPF registered via `registerDynBPFFilter()`, which does not play well with the new DynBlockRulesGroup approach. This commit fixes it by making exporting / displaying metric for the default BPF filter (`setDefaultBPFFilter`) as well. --- diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index 5037985972..58053aa045 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -964,33 +964,42 @@ static void handleJSONStats(const YaHTTP::Request& req, YaHTTP::Response& resp) auto nmg = g_dynblockNMG.getLocal(); struct timespec now; gettime(&now); - for (const auto& e: *nmg) { - if(now < e.second.until ) { - Json::object thing{ - {"reason", e.second.reason}, - {"seconds", (double)(e.second.until.tv_sec - now.tv_sec)}, - {"blocks", (double)e.second.blocks}, - {"action", DNSAction::typeToString(e.second.action != DNSAction::Action::None ? e.second.action : g_dynBlockAction) }, - {"warning", e.second.warning } - }; - obj.emplace(e.first.toString(), thing); + for (const auto& entry: *nmg) { + if (!(now < entry.second.until)) { + continue; + } + uint64_t counter = entry.second.blocks; + if (entry.second.bpf && g_defaultBPFFilter) { + counter += g_defaultBPFFilter->getHits(entry.first.getNetwork()); } + Json::object thing{ + {"reason", entry.second.reason}, + {"seconds", static_cast(entry.second.until.tv_sec - now.tv_sec)}, + {"blocks", static_cast(counter)}, + {"action", DNSAction::typeToString(entry.second.action != DNSAction::Action::None ? entry.second.action : g_dynBlockAction)}, + {"warning", entry.second.warning}, + {"ebpf", entry.second.bpf} + }; + obj.emplace(entry.first.toString(), thing); } auto smt = g_dynblockSMT.getLocal(); smt->visit([&now,&obj](const SuffixMatchTree& node) { - if(now (node.d_value.until.tv_sec - now.tv_sec)}, + {"blocks", static_cast(node.d_value.blocks)}, + {"action", DNSAction::typeToString(node.d_value.action != DNSAction::Action::None ? node.d_value.action : g_dynBlockAction)}, + {"ebpf", node.d_value.bpf} + }; + obj.emplace(dom, thing); }); #endif /* DISABLE_DYNBLOCKS */ Json my_json = obj; @@ -1013,6 +1022,23 @@ static void handleJSONStats(const YaHTTP::Request& req, YaHTTP::Response& resp) obj.emplace(std::get<0>(entry).toString(), thing ); } } + if (g_defaultBPFFilter) { + auto nmg = g_dynblockNMG.getLocal(); + for (const auto& entry: *nmg) { + if (!(now < entry.second.until) || !entry.second.bpf) { + continue; + } + uint64_t counter = entry.second.blocks + g_defaultBPFFilter->getHits(entry.first.getNetwork()); + Json::object thing{ + {"reason", entry.second.reason}, + {"seconds", static_cast(entry.second.until.tv_sec - now.tv_sec)}, + {"blocks", static_cast(counter)}, + {"action", DNSAction::typeToString(entry.second.action != DNSAction::Action::None ? entry.second.action : g_dynBlockAction)}, + {"warning", entry.second.warning}, + }; + obj.emplace(entry.first.toString(), thing); + } + } #endif /* HAVE_EBPF */ Json my_json = obj; resp.body = my_json.dump(); diff --git a/pdns/dnsdistdist/docs/advanced/ebpf.rst b/pdns/dnsdistdist/docs/advanced/ebpf.rst index e50dfbf472..2905b95e96 100644 --- a/pdns/dnsdistdist/docs/advanced/ebpf.rst +++ b/pdns/dnsdistdist/docs/advanced/ebpf.rst @@ -93,6 +93,7 @@ The dynamic eBPF blocks and the number of queries they blocked can be seen in th registerDynBPFFilter(dbpf) They can be unregistered at a later point using the :func:`unregisterDynBPFFilter` function. +Since 1.8.2, the metrics for the BPF filter registered via :func:`setDefaultBPFFilter` are exported as well. Requirements ------------ diff --git a/pdns/dnsdistdist/html/local.js b/pdns/dnsdistdist/html/local.js index 81c1b061fa..cefb0a4d96 100644 --- a/pdns/dnsdistdist/html/local.js +++ b/pdns/dnsdistdist/html/local.js @@ -237,10 +237,10 @@ $(document).ready(function() { $.ajax({ url: 'jsonstat?command=dynblocklist', type: 'GET', dataType: 'json', jsonp: false, success: function(data) { - var bouw=''; + var bouw='
Dyn blocked netmaskSecondsBlocksReason
'; var gotsome=false; $.each(data, function(a,b) { - bouw=bouw+(""); + bouw=bouw+(""); gotsome=true; });
Dyn blocked netmaskSecondsBlockseBPFReason
"+a+""+b.seconds+""+b.blocks+""+b.reason+"
"+a+""+b.seconds+""+b.blocks+""+b.ebpf+""+b.reason+"