]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/statnode.cc
3 StatNode::Stat
StatNode::print(unsigned int depth
, Stat newstat
, bool silent
) const
6 cout
<<string(depth
, ' ');
7 cout
<<name
<<": "<<endl
;
10 childstat
.queries
+= s
.queries
;
11 childstat
.noerrors
+= s
.noerrors
;
12 childstat
.nxdomains
+= s
.nxdomains
;
13 childstat
.servfails
+= s
.servfails
;
14 childstat
.drops
+= s
.drops
;
15 childstat
.bytes
+= s
.bytes
;
16 childstat
.hits
+= s
.hits
;
18 if(children
.size()>1024 && !silent
) {
19 cout
<<string(depth
, ' ')<<name
<<": too many to print"<<endl
;
21 for(const children_t::value_type
& child
: children
) {
22 childstat
=child
.second
.print(depth
+8, childstat
, silent
|| children
.size()>1024);
24 if(!silent
|| children
.size()>1)
25 cout
<<string(depth
, ' ')<<childstat
.queries
<<" queries, " <<
26 childstat
.noerrors
<<" noerrors, "<<
27 childstat
.nxdomains
<<" nxdomains, "<<
28 childstat
.servfails
<<" servfails, "<<
29 childstat
.drops
<<" drops, "<<
30 childstat
.bytes
<<" bytes, "<<
31 childstat
.hits
<<" hits"<<endl
;
39 void StatNode::visit(visitor_t visitor
, Stat
&newstat
, unsigned int depth
) const
43 for (const auto& child
: children
) {
44 child
.second
.visit(visitor
, childstat
, depth
+8);
47 visitor(this, s
, childstat
);
53 void StatNode::submit(const DNSName
& domain
, int rcode
, unsigned int bytes
, bool hit
, boost::optional
<const ComboAddress
&> remote
)
55 // cerr<<"FIRST submit called on '"<<domain<<"'"<<endl;
56 std::vector
<string
> tmp
= domain
.getRawLabels();
61 auto last
= tmp
.end() - 1;
62 children
[*last
].submit(last
, tmp
.begin(), "", rcode
, bytes
, remote
, 1, hit
);
65 /* www.powerdns.com. ->
72 void StatNode::submit(std::vector
<string
>::const_iterator end
, std::vector
<string
>::const_iterator begin
, const std::string
& domain
, int rcode
, unsigned int bytes
, boost::optional
<const ComboAddress
&> remote
, unsigned int count
, bool hit
)
74 // cerr<<"Submit called for domain='"<<domain<<"': ";
75 // for(const std::string& n : labels)
81 // cerr<<"Set short name to '"<<name<<"'"<<endl;
84 // cerr<<"Short name was already set to '"<<name<<"'"<<endl;
88 if (fullname
.empty()) {
89 size_t needed
= name
.size() + 1 + domain
.size();
90 if (fullname
.capacity() < needed
) {
91 fullname
.reserve(needed
);
95 fullname
.append(domain
);
98 // cerr<<"Hit the end, set our fullname to '"<<fullname<<"'"<<endl<<endl;
104 else if (rcode
== RCode::NoError
) {
107 else if (rcode
== RCode::ServFail
) {
110 else if (rcode
== RCode::NXDomain
) {
115 s
.remotes
[*remote
]++;
123 if (fullname
.empty()) {
124 size_t needed
= name
.size() + 1 + domain
.size();
125 if (fullname
.capacity() < needed
) {
126 fullname
.reserve(needed
);
129 fullname
.append(".");
130 fullname
.append(domain
);
133 // cerr<<"Not yet end, set our fullname to '"<<fullname<<"', recursing"<<endl;
135 children
[*end
].submit(end
, begin
, fullname
, rcode
, bytes
, remote
, count
+1, hit
);