]>
Commit | Line | Data |
---|---|---|
89c4ed63 A |
1 | /* |
2 | * daemon/stats.h - collect runtime performance indicators. | |
3 | * | |
4 | * Copyright (c) 2007, NLnet Labs. All rights reserved. | |
5 | * | |
6 | * This software is open source. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * | |
12 | * Redistributions of source code must retain the above copyright notice, | |
13 | * this list of conditions and the following disclaimer. | |
14 | * | |
15 | * Redistributions in binary form must reproduce the above copyright notice, | |
16 | * this list of conditions and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the distribution. | |
18 | * | |
19 | * Neither the name of the NLNET LABS nor the names of its contributors may | |
20 | * be used to endorse or promote products derived from this software without | |
21 | * specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
27 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | |
29 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
34 | */ | |
35 | ||
36 | /** | |
37 | * \file | |
38 | * | |
39 | * This file describes the data structure used to collect runtime performance | |
40 | * numbers. These 'statistics' may be of interest to the operator. | |
41 | */ | |
42 | ||
43 | #ifndef DAEMON_STATS_H | |
44 | #define DAEMON_STATS_H | |
45 | #include "util/timehist.h" | |
46 | struct worker; | |
47 | struct config_file; | |
48 | struct comm_point; | |
49 | struct comm_reply; | |
50 | struct edns_data; | |
51 | struct sldns_buffer; | |
52 | ||
53 | /** number of qtype that is stored for in array */ | |
54 | #define STATS_QTYPE_NUM 256 | |
55 | /** number of qclass that is stored for in array */ | |
56 | #define STATS_QCLASS_NUM 256 | |
57 | /** number of rcodes in stats */ | |
58 | #define STATS_RCODE_NUM 16 | |
59 | /** number of opcodes in stats */ | |
60 | #define STATS_OPCODE_NUM 16 | |
61 | ||
62 | /** per worker statistics */ | |
63 | struct server_stats { | |
64 | /** number of queries from clients received. */ | |
65 | size_t num_queries; | |
66 | /** number of queries that had a cache-miss. */ | |
67 | size_t num_queries_missed_cache; | |
68 | /** number of prefetch queries - cachehits with prefetch */ | |
69 | size_t num_queries_prefetch; | |
70 | ||
71 | /** | |
72 | * Sum of the querylistsize of the worker for | |
73 | * every query that missed cache. To calculate average. | |
74 | */ | |
75 | size_t sum_query_list_size; | |
76 | /** max value of query list size reached. */ | |
77 | size_t max_query_list_size; | |
78 | ||
79 | /** Extended stats below (bool) */ | |
80 | int extended; | |
81 | ||
82 | /** qtype stats */ | |
83 | size_t qtype[STATS_QTYPE_NUM]; | |
84 | /** bigger qtype values not in array */ | |
85 | size_t qtype_big; | |
86 | /** qclass stats */ | |
87 | size_t qclass[STATS_QCLASS_NUM]; | |
88 | /** bigger qclass values not in array */ | |
89 | size_t qclass_big; | |
90 | /** query opcodes */ | |
91 | size_t qopcode[STATS_OPCODE_NUM]; | |
92 | /** number of queries over TCP */ | |
93 | size_t qtcp; | |
94 | /** number of outgoing queries over TCP */ | |
95 | size_t qtcp_outgoing; | |
96 | /** number of queries over IPv6 */ | |
97 | size_t qipv6; | |
98 | /** number of queries with QR bit */ | |
99 | size_t qbit_QR; | |
100 | /** number of queries with AA bit */ | |
101 | size_t qbit_AA; | |
102 | /** number of queries with TC bit */ | |
103 | size_t qbit_TC; | |
104 | /** number of queries with RD bit */ | |
105 | size_t qbit_RD; | |
106 | /** number of queries with RA bit */ | |
107 | size_t qbit_RA; | |
108 | /** number of queries with Z bit */ | |
109 | size_t qbit_Z; | |
110 | /** number of queries with AD bit */ | |
111 | size_t qbit_AD; | |
112 | /** number of queries with CD bit */ | |
113 | size_t qbit_CD; | |
114 | /** number of queries with EDNS OPT record */ | |
115 | size_t qEDNS; | |
116 | /** number of queries with EDNS with DO flag */ | |
117 | size_t qEDNS_DO; | |
118 | /** answer rcodes */ | |
119 | size_t ans_rcode[STATS_RCODE_NUM]; | |
120 | /** answers with pseudo rcode 'nodata' */ | |
121 | size_t ans_rcode_nodata; | |
122 | /** answers that were secure (AD) */ | |
123 | size_t ans_secure; | |
124 | /** answers that were bogus (withheld as SERVFAIL) */ | |
125 | size_t ans_bogus; | |
126 | /** rrsets marked bogus by validator */ | |
127 | size_t rrset_bogus; | |
128 | /** unwanted traffic received on server-facing ports */ | |
129 | size_t unwanted_replies; | |
130 | /** unwanted traffic received on client-facing ports */ | |
131 | size_t unwanted_queries; | |
132 | ||
133 | /** histogram data exported to array | |
134 | * if the array is the same size, no data is lost, and | |
135 | * if all histograms are same size (is so by default) then | |
136 | * adding up works well. */ | |
137 | size_t hist[NUM_BUCKETS_HIST]; | |
138 | ||
139 | /** number of message cache entries */ | |
140 | size_t msg_cache_count; | |
141 | /** number of rrset cache entries */ | |
142 | size_t rrset_cache_count; | |
143 | /** number of infra cache entries */ | |
144 | size_t infra_cache_count; | |
145 | /** number of key cache entries */ | |
146 | size_t key_cache_count; | |
147 | }; | |
148 | ||
149 | /** | |
150 | * Statistics to send over the control pipe when asked | |
151 | * This struct is made to be memcpied, sent in binary. | |
152 | */ | |
153 | struct stats_info { | |
154 | /** the thread stats */ | |
155 | struct server_stats svr; | |
156 | ||
157 | /** mesh stats: current number of states */ | |
158 | size_t mesh_num_states; | |
159 | /** mesh stats: current number of reply (user) states */ | |
160 | size_t mesh_num_reply_states; | |
161 | /** mesh stats: number of reply states overwritten with a new one */ | |
162 | size_t mesh_jostled; | |
163 | /** mesh stats: number of incoming queries dropped */ | |
164 | size_t mesh_dropped; | |
165 | /** mesh stats: replies sent */ | |
166 | size_t mesh_replies_sent; | |
167 | /** mesh stats: sum of waiting times for the replies */ | |
168 | struct timeval mesh_replies_sum_wait; | |
169 | /** mesh stats: median of waiting times for replies (in sec) */ | |
170 | double mesh_time_median; | |
171 | }; | |
172 | ||
173 | /** | |
174 | * Initialize server stats to 0. | |
175 | * @param stats: what to init (this is alloced by the caller). | |
176 | * @param cfg: with extended statistics option. | |
177 | */ | |
178 | void server_stats_init(struct server_stats* stats, struct config_file* cfg); | |
179 | ||
180 | /** add query if it missed the cache */ | |
181 | void server_stats_querymiss(struct server_stats* stats, struct worker* worker); | |
182 | ||
183 | /** add query if was cached and also resulted in a prefetch */ | |
184 | void server_stats_prefetch(struct server_stats* stats, struct worker* worker); | |
185 | ||
186 | /** display the stats to the log */ | |
187 | void server_stats_log(struct server_stats* stats, struct worker* worker, | |
188 | int threadnum); | |
189 | ||
190 | /** | |
191 | * Obtain the stats info for a given thread. Uses pipe to communicate. | |
192 | * @param worker: the worker that is executing (the first worker). | |
193 | * @param who: on who to get the statistics info. | |
194 | * @param s: the stats block to fill in. | |
195 | * @param reset: if stats can be reset. | |
196 | */ | |
197 | void server_stats_obtain(struct worker* worker, struct worker* who, | |
198 | struct stats_info* s, int reset); | |
199 | ||
200 | /** | |
201 | * Compile stats into structure for this thread worker. | |
202 | * Also clears the statistics counters (if that is set by config file). | |
203 | * @param worker: the worker to compile stats for, also the executing worker. | |
204 | * @param s: stats block. | |
205 | * @param reset: if true, depending on config stats are reset. | |
206 | * if false, statistics are not reset. | |
207 | */ | |
208 | void server_stats_compile(struct worker* worker, struct stats_info* s, | |
209 | int reset); | |
210 | ||
211 | /** | |
212 | * Send stats over comm tube in reply to query cmd | |
213 | * @param worker: this worker. | |
214 | * @param reset: if true, depending on config stats are reset. | |
215 | * if false, statistics are not reset. | |
216 | */ | |
217 | void server_stats_reply(struct worker* worker, int reset); | |
218 | ||
219 | /** | |
220 | * Addup stat blocks. | |
221 | * @param total: sum of the two entries. | |
222 | * @param a: to add to it. | |
223 | */ | |
224 | void server_stats_add(struct stats_info* total, struct stats_info* a); | |
225 | ||
226 | /** | |
227 | * Add stats for this query | |
228 | * @param stats: the stats | |
229 | * @param c: commpoint with type and buffer. | |
230 | * @param qtype: query type | |
231 | * @param qclass: query class | |
232 | * @param edns: edns record | |
233 | * @param repinfo: reply info with remote address | |
234 | */ | |
235 | void server_stats_insquery(struct server_stats* stats, struct comm_point* c, | |
236 | uint16_t qtype, uint16_t qclass, struct edns_data* edns, | |
237 | struct comm_reply* repinfo); | |
238 | ||
239 | /** | |
240 | * Add rcode for this query. | |
241 | * @param stats: the stats | |
242 | * @param buf: buffer with rcode. If buffer is length0: not counted. | |
243 | */ | |
244 | void server_stats_insrcode(struct server_stats* stats, struct sldns_buffer* buf); | |
245 | ||
246 | #endif /* DAEMON_STATS_H */ |