From: bert hubert Date: Sun, 11 Jan 2015 21:22:35 +0000 (+0100) Subject: hook up several more ringbuffers to the recursor web API, support grouping by public... X-Git-Tag: rec-3.7.0-rc1~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=509196afd141569dbf7508ae0d4b1a954e58015a;p=pdns hook up several more ringbuffers to the recursor web API, support grouping by public suffix, include counts for 'rest', remove dependency on version_generated.cc --- diff --git a/pdns/rec_channel.hh b/pdns/rec_channel.hh index f220d292d..7d320c02d 100644 --- a/pdns/rec_channel.hh +++ b/pdns/rec_channel.hh @@ -6,7 +6,7 @@ #include #include #include - +#include "iputils.hh" /** this class is used both to send and answer channel commands to the PowerDNS Recursor */ class RecursorControlChannel @@ -45,4 +45,8 @@ extern pthread_mutex_t g_carbon_config_lock; void sortPublicSuffixList(); std::vector >* pleaseGetQueryRing(); std::vector >* pleaseGetServfailQueryRing(); +std::vector* pleaseGetRemotes(); +std::vector* pleaseGetServfailRemotes(); +std::vector* pleaseGetLargeAnswerRemotes(); +std::string getRegisteredName(const std::string& dom); #endif diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 0c5600e6d..03a4a9823 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -712,7 +712,7 @@ void sortPublicSuffixList() } -static string getRegisteredName(const std::string& dom) +string getRegisteredName(const std::string& dom) { vector parts; stringtok(parts, dom, "."); @@ -909,7 +909,6 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP if(cmd=="top-pub-queries") return doGenericTopQueries(pleaseGetQueryRing, getRegisteredName); - if(cmd=="top-servfail-queries") return doGenericTopQueries(pleaseGetServfailQueryRing); diff --git a/pdns/ws-api.cc b/pdns/ws-api.cc index 7628fb61b..faae37af0 100644 --- a/pdns/ws-api.cc +++ b/pdns/ws-api.cc @@ -21,7 +21,6 @@ #include #include #include -#include "version_generated.h" #include "namespaces.hh" #include "ws-api.hh" #include "json.hh" @@ -87,7 +86,8 @@ static void fillServerDetail(Value& out, Value::AllocatorType& allocator) out.AddMember("id", "localhost", allocator); out.AddMember("url", "/servers/localhost", allocator); out.AddMember("daemon_type", jdaemonType, allocator); - out.AddMember("version", PDNS_VERSION, allocator); + Value jversion(getPDNSVersion().c_str(), allocator); + out.AddMember("version", jversion, allocator); out.AddMember("config_url", "/servers/localhost/config{/config_setting}", allocator); out.AddMember("zones_url", "/servers/localhost/zones{/zone}", allocator); } diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index ff45004dc..51bf165f4 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -535,6 +535,8 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp) else if(command == "get-query-ring") { typedef pair query_t; vector queries; + bool filter=!req->getvars["public-filtered"].empty(); + if(req->getvars["name"]=="servfail-queries") queries=broadcastAccFunction >(pleaseGetServfailQueryRing); else if(req->getvars["name"]=="queries") @@ -545,7 +547,10 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp) unsigned int total=0; BOOST_FOREACH(const query_t& q, queries) { total++; - counts[make_pair(toLower(q.first), q.second)]++; + if(filter) + counts[make_pair(getRegisteredName(toLower(q.first)), q.second)]++; + else + counts[make_pair(toLower(q.first), q.second)]++; } typedef std::multimap rcounts_t; @@ -554,16 +559,16 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp) for(counts_t::const_iterator i=counts.begin(); i != counts.end(); ++i) rcounts.insert(make_pair(-i->second, i->first)); - Document doc; doc.SetObject(); Value entries; entries.SetArray(); - int tot=0; + unsigned int tot=0, totIncluded=0; BOOST_FOREACH(const rcounts_t::value_type& q, rcounts) { Value arr; arr.SetArray(); + totIncluded-=q.first; arr.PushBack(-q.first, doc.GetAllocator()); arr.PushBack(q.second.first.c_str(), doc.GetAllocator()); arr.PushBack(DNSRecordContent::NumberToType(q.second.second).c_str(), doc.GetAllocator()); @@ -571,6 +576,67 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp) if(tot++>=100) break; } + if(queries.size() != totIncluded) { + Value arr; + arr.SetArray(); + arr.PushBack(queries.size()-totIncluded, doc.GetAllocator()); + arr.PushBack("", doc.GetAllocator()); + arr.PushBack("", doc.GetAllocator()); + entries.PushBack(arr, doc.GetAllocator()); + } + doc.AddMember("entries", entries, doc.GetAllocator()); + resp->setBody(doc); + return; + } + else if(command == "get-remote-ring") { + vector queries; + if(req->getvars["name"]=="remotes") + queries=broadcastAccFunction >(pleaseGetRemotes); + else if(req->getvars["name"]=="servfail-remotes") + queries=broadcastAccFunction >(pleaseGetServfailRemotes); + else if(req->getvars["name"]=="large-answer-remotes") + queries=broadcastAccFunction >(pleaseGetLargeAnswerRemotes); + + typedef map counts_t; + counts_t counts; + unsigned int total=0; + BOOST_FOREACH(const ComboAddress& q, queries) { + total++; + counts[q]++; + } + + typedef std::multimap rcounts_t; + rcounts_t rcounts; + + for(counts_t::const_iterator i=counts.begin(); i != counts.end(); ++i) + rcounts.insert(make_pair(-i->second, i->first)); + + + Document doc; + doc.SetObject(); + Value entries; + entries.SetArray(); + unsigned int tot=0, totIncluded=0; + BOOST_FOREACH(const rcounts_t::value_type& q, rcounts) { + totIncluded-=q.first; + Value arr; + + arr.SetArray(); + arr.PushBack(-q.first, doc.GetAllocator()); + Value jname(q.second.toString().c_str(), doc.GetAllocator()); // copy + arr.PushBack(jname, doc.GetAllocator()); + entries.PushBack(arr, doc.GetAllocator()); + if(tot++>=100) + break; + } + if(queries.size() != totIncluded) { + Value arr; + arr.SetArray(); + arr.PushBack(queries.size()-totIncluded, doc.GetAllocator()); + arr.PushBack("", doc.GetAllocator()); + entries.PushBack(arr, doc.GetAllocator()); + } + doc.AddMember("entries", entries, doc.GetAllocator()); resp->setBody(doc); return;