]>
Commit | Line | Data |
---|---|---|
870a0fe4 AT |
1 | #ifdef HAVE_CONFIG_H |
2 | #include "config.h" | |
3 | #endif | |
a48e03da | 4 | |
46c6975c | 5 | #include "responsestats.hh" |
a48e03da | 6 | |
46c6975c | 7 | #include <limits> |
a48e03da OM |
8 | #include <boost/format.hpp> |
9 | ||
46c6975c | 10 | #include "namespaces.hh" |
79332bff | 11 | #include "logger.hh" |
fa8fd4d2 | 12 | |
09425ce1 | 13 | #include "dnsparser.hh" |
46c6975c | 14 | |
097b1e68 | 15 | static auto sizeBounds() |
46c6975c | 16 | { |
097b1e68 OM |
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 | ||
31 | ResponseStats::ResponseStats() : | |
32 | d_sizecounters("SizeCounters", sizeBounds()) | |
33 | { | |
7902cc09 PD |
34 | for (auto& entry : d_qtypecounters) { |
35 | entry.value = 0; | |
097b1e68 | 36 | } |
7902cc09 PD |
37 | for (auto& entry : d_rcodecounters) { |
38 | entry.value = 0; | |
097b1e68 | 39 | } |
46c6975c | 40 | } |
41 | ||
c3064e57 | 42 | ResponseStats g_rs; |
b552d7b1 | 43 | |
26f41a96 | 44 | void ResponseStats::submitResponse(uint16_t qtype, uint16_t respsize, uint8_t rcode, bool udpOrTCP) const |
87798d5e | 45 | { |
26f41a96 | 46 | d_rcodecounters.at(rcode).value++; |
097b1e68 | 47 | submitResponse(qtype, respsize, udpOrTCP); |
87798d5e | 48 | } |
46c6975c | 49 | |
d73de874 | 50 | void ResponseStats::submitResponse(uint16_t qtype, uint16_t respsize, bool /* udpOrTCP */) const |
46c6975c | 51 | { |
26f41a96 | 52 | d_qtypecounters.at(qtype).value++; |
097b1e68 | 53 | d_sizecounters(respsize); |
46c6975c | 54 | } |
55 | ||
dad777b6 | 56 | map<uint16_t, uint64_t> ResponseStats::getQTypeResponseCounts() const |
46c6975c | 57 | { |
58 | map<uint16_t, uint64_t> ret; | |
59 | uint64_t count; | |
7902cc09 | 60 | for (unsigned int i = 0; i < d_qtypecounters.size(); ++i) { |
26f41a96 | 61 | count = d_qtypecounters.at(i).value; |
097b1e68 OM |
62 | if (count) { |
63 | ret[i] = count; | |
64 | } | |
46c6975c | 65 | } |
66 | return ret; | |
67 | } | |
93698ef3 | 68 | |
dad777b6 | 69 | map<uint16_t, uint64_t> ResponseStats::getSizeResponseCounts() const |
93698ef3 PD |
70 | { |
71 | map<uint16_t, uint64_t> ret; | |
097b1e68 OM |
72 | for (const auto& sizecounter : d_sizecounters.getRawData()) { |
73 | if (sizecounter.d_count) { | |
74 | ret[sizecounter.d_boundary] = sizecounter.d_count; | |
75 | } | |
93698ef3 PD |
76 | } |
77 | return ret; | |
a31fe060 | 78 | } |
09425ce1 | 79 | |
dad777b6 | 80 | map<uint8_t, uint64_t> ResponseStats::getRCodeResponseCounts() const |
87798d5e TB |
81 | { |
82 | map<uint8_t, uint64_t> ret; | |
83 | uint64_t count; | |
7902cc09 | 84 | for (unsigned int i = 0; i < d_rcodecounters.size(); ++i) { |
26f41a96 | 85 | count = d_rcodecounters.at(i).value; |
097b1e68 OM |
86 | if (count) { |
87 | ret[i] = count; | |
88 | } | |
87798d5e TB |
89 | } |
90 | return ret; | |
91 | } | |
92 | ||
dad777b6 | 93 | string ResponseStats::getQTypeReport() const |
09425ce1 | 94 | { |
097b1e68 | 95 | auto qtypenums = getQTypeResponseCounts(); |
09425ce1 F |
96 | ostringstream os; |
97 | boost::format fmt("%s\t%d\n"); | |
097b1e68 OM |
98 | for (const auto& val : qtypenums) { |
99 | os << (fmt % DNSRecordContent::NumberToType(val.first) % val.second).str(); | |
09425ce1 F |
100 | } |
101 | return os.str(); | |
a7acf71b | 102 | } |