]>
Commit | Line | Data |
---|---|---|
870a0fe4 AT |
1 | #ifdef HAVE_CONFIG_H |
2 | #include "config.h" | |
3 | #endif | |
46c6975c | 4 | #include "responsestats.hh" |
5 | #include <limits> | |
6 | #include "namespaces.hh" | |
79332bff | 7 | #include "logger.hh" |
fa8fd4d2 | 8 | |
09425ce1 | 9 | #include "dnsparser.hh" |
46c6975c | 10 | |
87798d5e | 11 | ResponseStats::ResponseStats() : d_qtypecounters(new std::atomic<unsigned long>[65536]), d_rcodecounters(new std::atomic<unsigned long>[256]) |
46c6975c | 12 | { |
46c6975c | 13 | d_sizecounters.push_back(make_pair(20,0)); |
14 | d_sizecounters.push_back(make_pair(40,0)); | |
15 | d_sizecounters.push_back(make_pair(60,0)); | |
16 | d_sizecounters.push_back(make_pair(80,0)); | |
17 | d_sizecounters.push_back(make_pair(100,0)); | |
18 | d_sizecounters.push_back(make_pair(150,0)); | |
19 | for(int n=200; n < 65000 ; n+=200) | |
20 | d_sizecounters.push_back(make_pair(n,0)); | |
21 | d_sizecounters.push_back(make_pair(std::numeric_limits<uint16_t>::max(),0)); | |
8fdfa2c5 | 22 | for(unsigned int n =0 ; n < 65535; ++n) |
23 | d_qtypecounters[n] = 0; | |
87798d5e TB |
24 | for(unsigned int n =0 ; n < 256; ++n) |
25 | d_rcodecounters[n] = 0; | |
46c6975c | 26 | } |
27 | ||
c3064e57 | 28 | ResponseStats g_rs; |
b552d7b1 | 29 | |
46c6975c | 30 | static bool pcomp(const pair<uint16_t, uint64_t>&a , const pair<uint16_t, uint64_t>&b) |
31 | { | |
32 | return a.first < b.first; | |
87798d5e TB |
33 | } |
34 | ||
35 | void ResponseStats::submitResponse(uint16_t qtype,uint16_t respsize, uint8_t rcode, bool udpOrTCP) | |
36 | { | |
37 | d_rcodecounters[rcode]++; | |
38 | submitResponse(qtype, respsize, udpOrTCP); | |
39 | } | |
46c6975c | 40 | |
87798d5e | 41 | void ResponseStats::submitResponse(uint16_t qtype,uint16_t respsize, bool udpOrTCP) |
46c6975c | 42 | { |
43 | d_qtypecounters[qtype]++; | |
44 | pair<uint16_t, uint64_t> s(respsize, 0); | |
45 | sizecounters_t::iterator iter = std::upper_bound(d_sizecounters.begin(), d_sizecounters.end(), s, pcomp); | |
46 | if(iter!= d_sizecounters.begin()) | |
47 | --iter; | |
48 | iter->second++; | |
49 | } | |
50 | ||
51 | map<uint16_t, uint64_t> ResponseStats::getQTypeResponseCounts() | |
52 | { | |
53 | map<uint16_t, uint64_t> ret; | |
54 | uint64_t count; | |
c3064e57 | 55 | for(unsigned int i = 0 ; i < 65535 ; ++i) { |
46c6975c | 56 | count= d_qtypecounters[i]; |
57 | if(count) | |
58 | ret[i]=count; | |
59 | } | |
60 | return ret; | |
61 | } | |
93698ef3 PD |
62 | |
63 | map<uint16_t, uint64_t> ResponseStats::getSizeResponseCounts() | |
64 | { | |
65 | map<uint16_t, uint64_t> ret; | |
66 | for(sizecounters_t::const_iterator iter = d_sizecounters.begin(); | |
67 | iter != d_sizecounters.end(); | |
68 | ++iter) { | |
69 | ret[iter->first]=iter->second; | |
70 | } | |
71 | return ret; | |
a31fe060 | 72 | } |
09425ce1 | 73 | |
87798d5e TB |
74 | map<uint8_t, uint64_t> ResponseStats::getRCodeResponseCounts() |
75 | { | |
76 | map<uint8_t, uint64_t> ret; | |
77 | uint64_t count; | |
78 | for(unsigned int i = 0 ; i < 256 ; ++i) { | |
79 | count= d_rcodecounters[i]; | |
80 | if(count) | |
81 | ret[i]=count; | |
82 | } | |
83 | return ret; | |
84 | } | |
85 | ||
09425ce1 F |
86 | string ResponseStats::getQTypeReport() |
87 | { | |
88 | typedef map<uint16_t, uint64_t> qtypenums_t; | |
89 | qtypenums_t qtypenums = getQTypeResponseCounts(); | |
90 | ostringstream os; | |
91 | boost::format fmt("%s\t%d\n"); | |
ef7cd021 | 92 | for(const qtypenums_t::value_type& val : qtypenums) { |
09425ce1 F |
93 | os << (fmt %DNSRecordContent::NumberToType( val.first) % val.second).str(); |
94 | } | |
95 | return os.str(); | |
a7acf71b | 96 | } |