]> git.ipfire.org Git - thirdparty/pdns.git/blame_incremental - pdns/responsestats.cc
Merge pull request #14324 from Habbie/auth-lua-docs-backquote-nit
[thirdparty/pdns.git] / pdns / responsestats.cc
... / ...
CommitLineData
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include "responsestats.hh"
6
7#include <limits>
8#include <boost/format.hpp>
9
10#include "namespaces.hh"
11#include "logger.hh"
12
13#include "dnsparser.hh"
14
15static auto sizeBounds()
16{
17 std::vector<uint64_t> bounds;
18
19 bounds.push_back(20);
20 bounds.push_back(40);
21 bounds.push_back(60);
22 bounds.push_back(80);
23 bounds.push_back(100);
24 bounds.push_back(150);
25 for (uint64_t n = 200; n < 65000; n += 200) {
26 bounds.push_back(n);
27 }
28 return bounds;
29}
30
31ResponseStats::ResponseStats() :
32 d_sizecounters("SizeCounters", sizeBounds())
33{
34 for (auto& entry : d_qtypecounters) {
35 entry.value = 0;
36 }
37 for (auto& entry : d_rcodecounters) {
38 entry.value = 0;
39 }
40}
41
42ResponseStats g_rs;
43
44void ResponseStats::submitResponse(uint16_t qtype, uint16_t respsize, uint8_t rcode, bool udpOrTCP) const
45{
46 d_rcodecounters.at(rcode).value++;
47 submitResponse(qtype, respsize, udpOrTCP);
48}
49
50void ResponseStats::submitResponse(uint16_t qtype, uint16_t respsize, bool /* udpOrTCP */) const
51{
52 d_qtypecounters.at(qtype).value++;
53 d_sizecounters(respsize);
54}
55
56map<uint16_t, uint64_t> ResponseStats::getQTypeResponseCounts() const
57{
58 map<uint16_t, uint64_t> ret;
59 uint64_t count;
60 for (unsigned int i = 0; i < d_qtypecounters.size(); ++i) {
61 count = d_qtypecounters.at(i).value;
62 if (count) {
63 ret[i] = count;
64 }
65 }
66 return ret;
67}
68
69map<uint16_t, uint64_t> ResponseStats::getSizeResponseCounts() const
70{
71 map<uint16_t, uint64_t> ret;
72 for (const auto& sizecounter : d_sizecounters.getRawData()) {
73 if (sizecounter.d_count) {
74 ret[sizecounter.d_boundary] = sizecounter.d_count;
75 }
76 }
77 return ret;
78}
79
80map<uint8_t, uint64_t> ResponseStats::getRCodeResponseCounts() const
81{
82 map<uint8_t, uint64_t> ret;
83 uint64_t count;
84 for (unsigned int i = 0; i < d_rcodecounters.size(); ++i) {
85 count = d_rcodecounters.at(i).value;
86 if (count) {
87 ret[i] = count;
88 }
89 }
90 return ret;
91}
92
93string ResponseStats::getQTypeReport() const
94{
95 auto qtypenums = getQTypeResponseCounts();
96 ostringstream os;
97 boost::format fmt("%s\t%d\n");
98 for (const auto& val : qtypenums) {
99 os << (fmt % DNSRecordContent::NumberToType(val.first) % val.second).str();
100 }
101 return os.str();
102}