]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/statnode.cc
Make the constructors taking a pthread_rwlock_t * private.
[thirdparty/pdns.git] / pdns / statnode.cc
CommitLineData
6264512b 1#include "statnode.hh"
2
431c4359 3StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) const
6264512b 4{
5 if(!silent) {
6 cout<<string(depth, ' ');
7 cout<<name<<": "<<endl;
8 }
9 Stat childstat;
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;
92375564
RG
15 childstat.bytes += s.bytes;
16
6264512b 17 if(children.size()>1024 && !silent) {
18 cout<<string(depth, ' ')<<name<<": too many to print"<<endl;
19 }
20 for(const children_t::value_type& child : children) {
21 childstat=child.second.print(depth+8, childstat, silent || children.size()>1024);
22 }
23 if(!silent || children.size()>1)
24 cout<<string(depth, ' ')<<childstat.queries<<" queries, " <<
25 childstat.noerrors<<" noerrors, "<<
26 childstat.nxdomains<<" nxdomains, "<<
27 childstat.servfails<<" servfails, "<<
92375564
RG
28 childstat.drops<<" drops, "<<
29 childstat.bytes<<" bytes"<<endl;
6264512b 30
31 newstat+=childstat;
32
33 return newstat;
34}
35
36
431c4359 37void StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) const
6264512b 38{
39 Stat childstat;
40 childstat.queries += s.queries;
41 childstat.noerrors += s.noerrors;
42 childstat.nxdomains += s.nxdomains;
43 childstat.servfails += s.servfails;
44 childstat.drops += s.drops;
92375564 45 childstat.bytes += s.bytes;
7d07129c 46 childstat.remotes = s.remotes;
6264512b 47
c5983d8d 48 Stat selfstat(childstat);
6264512b 49
50 for(const children_t::value_type& child : children) {
51 child.second.visit(visitor, childstat, depth+8);
52 }
53
54 visitor(this, selfstat, childstat);
55
56 newstat+=childstat;
57}
58
59
92375564 60void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, boost::optional<const ComboAddress&> remote)
6264512b 61{
62 // cerr<<"FIRST submit called on '"<<domain<<"'"<<endl;
1b7c449b 63 std::vector<string> tmp = domain.getRawLabels();
6264512b 64 if(tmp.empty())
65 return;
66
1b7c449b 67 auto last = tmp.end() - 1;
92375564 68 children[*last].submit(last, tmp.begin(), "", rcode, bytes, remote, 1);
6264512b 69}
70
71/* www.powerdns.com. ->
72 . <- fullnames
73 com.
74 powerdns.com
75 www.powerdns.com.
76*/
77
92375564 78void 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)
6264512b 79{
6264512b 80 // cerr<<"Submit called for domain='"<<domain<<"': ";
81 // for(const std::string& n : labels)
82 // cerr<<n<<".";
83 // cerr<<endl;
84 if(name.empty()) {
85
1b7c449b 86 name=*end;
6264512b 87 // cerr<<"Set short name to '"<<name<<"'"<<endl;
88 }
2010ac95
RG
89 else {
90 // cerr<<"Short name was already set to '"<<name<<"'"<<endl;
91 }
6264512b 92
1b7c449b 93 if(end == begin) {
431c4359
RG
94 if (fullname.empty()) {
95 fullname=name+"."+domain;
96 labelsCount = count;
97 }
6264512b 98 // cerr<<"Hit the end, set our fullname to '"<<fullname<<"'"<<endl<<endl;
99 s.queries++;
92375564 100 s.bytes += bytes;
6264512b 101 if(rcode<0)
102 s.drops++;
103 else if(rcode==0)
104 s.noerrors++;
105 else if(rcode==2)
106 s.servfails++;
107 else if(rcode==3)
108 s.nxdomains++;
7d07129c
RG
109
110 if (remote) {
111 s.remotes[*remote]++;
112 }
6264512b 113 }
114 else {
431c4359
RG
115 if (fullname.empty()) {
116 fullname=name+"."+domain;
117 labelsCount = count;
118 }
6264512b 119 // cerr<<"Not yet end, set our fullname to '"<<fullname<<"', recursing"<<endl;
4b5da564 120 --end;
92375564 121 children[*end].submit(end, begin, fullname, rcode, bytes, remote, count+1);
6264512b 122 }
123}
124