} );
g_lua.registerMember("fullname", &StatNode::fullname);
+ g_lua.registerMember("labelsCount", &StatNode::labelsCount);
g_lua.registerMember("servfails", &StatNode::Stat::servfails);
g_lua.registerMember("nxdomains", &StatNode::Stat::nxdomains);
g_lua.registerMember("queries", &StatNode::Stat::queries);
#include "statnode.hh"
-StatNode::Stat StatNode::print(int depth, Stat newstat, bool silent) const
+StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) const
{
if(!silent) {
cout<<string(depth, ' ');
}
-void StatNode::visit(visitor_t visitor, Stat &newstat, int depth) const
+void StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) const
{
Stat childstat;
childstat.queries += s.queries;
for(auto const i : tmp) {
parts.push_back(i);
}
- children[parts.back()].submit(parts, "", rcode, remote);
+ children[parts.back()].submit(parts, "", rcode, remote, 1);
}
/* www.powerdns.com. ->
www.powerdns.com.
*/
-void StatNode::submit(deque<string>& labels, const std::string& domain, int rcode, const ComboAddress& remote)
+void StatNode::submit(deque<string>& labels, const std::string& domain, int rcode, const ComboAddress& remote, unsigned int count)
{
if(labels.empty())
return;
; // cerr<<"Short name was already set to '"<<name<<"'"<<endl;
if(labels.size()==1) {
- fullname=name+"."+domain;
+ if (fullname.empty()) {
+ fullname=name+"."+domain;
+ labelsCount = count;
+ }
// cerr<<"Hit the end, set our fullname to '"<<fullname<<"'"<<endl<<endl;
s.queries++;
if(rcode<0)
s.remotes[remote]++;
}
else {
- fullname=name+"."+domain;
+ if (fullname.empty()) {
+ fullname=name+"."+domain;
+ labelsCount = count;
+ }
// cerr<<"Not yet end, set our fullname to '"<<fullname<<"', recursing"<<endl;
labels.pop_back();
- children[labels.back()].submit(labels, fullname, rcode, remote);
+ children[labels.back()].submit(labels, fullname, rcode, remote, count+1);
}
}
class StatNode
{
public:
- void submit(const DNSName& domain, int rcode, const ComboAddress& remote);
- void submit(std::deque<std::string>& labels, const std::string& domain, int rcode, const ComboAddress& remote);
- std::string name;
- std::string fullname;
struct Stat
{
Stat() : queries(0), noerrors(0), nxdomains(0), servfails(0), drops(0){}
}
return *this;
}
-typedef std::map<ComboAddress,int,ComboAddress::addressOnlyLessThan> remotes_t;
+ typedef std::map<ComboAddress,int,ComboAddress::addressOnlyLessThan> remotes_t;
remotes_t remotes;
};
Stat s;
- Stat print(int depth=0, Stat newstat=Stat(), bool silent=false) const;
+ std::string name;
+ std::string fullname;
+ unsigned int labelsCount{0};
+
+ void submit(const DNSName& domain, int rcode, const ComboAddress& remote);
+ void submit(std::deque<std::string>& labels, const std::string& domain, int rcode, const ComboAddress& remote, unsigned int count);
+
+ Stat print(unsigned int depth=0, Stat newstat=Stat(), bool silent=false) const;
typedef boost::function<void(const StatNode*, const Stat& selfstat, const Stat& childstat)> visitor_t;
- void visit(visitor_t visitor, Stat& newstat, int depth=0) const;
+ void visit(visitor_t visitor, Stat& newstat, unsigned int depth=0) const;
typedef std::map<std::string,StatNode, CIStringCompare> children_t;
children_t children;