1 /* $NetBSD: stats.h,v 1.7 2014/12/10 04:37:58 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2004-2009, 2012, 2014 Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 2000, 2001 Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* Id */ 21 22 #ifndef DNS_STATS_H 23 #define DNS_STATS_H 1 24 25 /*! \file dns/stats.h */ 26 27 #include <dns/types.h> 28 29 /*% 30 * Statistics counters. Used as isc_statscounter_t values. 31 */ 32 enum { 33 /*% 34 * Resolver statistics counters. 35 */ 36 dns_resstatscounter_queryv4 = 0, 37 dns_resstatscounter_queryv6 = 1, 38 dns_resstatscounter_responsev4 = 2, 39 dns_resstatscounter_responsev6 = 3, 40 dns_resstatscounter_nxdomain = 4, 41 dns_resstatscounter_servfail = 5, 42 dns_resstatscounter_formerr = 6, 43 dns_resstatscounter_othererror = 7, 44 dns_resstatscounter_edns0fail = 8, 45 dns_resstatscounter_mismatch = 9, 46 dns_resstatscounter_truncated = 10, 47 dns_resstatscounter_lame = 11, 48 dns_resstatscounter_retry = 12, 49 dns_resstatscounter_gluefetchv4 = 13, 50 dns_resstatscounter_gluefetchv6 = 14, 51 dns_resstatscounter_gluefetchv4fail = 15, 52 dns_resstatscounter_gluefetchv6fail = 16, 53 dns_resstatscounter_val = 17, 54 dns_resstatscounter_valsuccess = 18, 55 dns_resstatscounter_valnegsuccess = 19, 56 dns_resstatscounter_valfail = 20, 57 dns_resstatscounter_dispabort = 21, 58 dns_resstatscounter_dispsockfail = 22, 59 dns_resstatscounter_querytimeout = 23, 60 dns_resstatscounter_queryrtt0 = 24, 61 dns_resstatscounter_queryrtt1 = 25, 62 dns_resstatscounter_queryrtt2 = 26, 63 dns_resstatscounter_queryrtt3 = 27, 64 dns_resstatscounter_queryrtt4 = 28, 65 dns_resstatscounter_queryrtt5 = 29, 66 dns_resstatscounter_nfetch = 30, 67 dns_resstatscounter_disprequdp = 31, 68 dns_resstatscounter_dispreqtcp = 32, 69 dns_resstatscounter_buckets = 33, 70 dns_resstatscounter_refused = 34, 71 #ifdef ISC_PLATFORM_USESIT 72 dns_resstatscounter_sitcc = 35, 73 dns_resstatscounter_sitout = 36, 74 dns_resstatscounter_sitin = 37, 75 dns_resstatscounter_sitok = 38, 76 77 dns_resstatscounter_badvers = 39, 78 dns_resstatscounter_max = 40, 79 #else 80 dns_resstatscounter_badvers = 35, 81 dns_resstatscounter_max = 36, 82 #endif 83 84 /* 85 * DNSSEC stats. 86 */ 87 dns_dnssecstats_asis = 0, 88 dns_dnssecstats_downcase = 1, 89 dns_dnssecstats_wildcard = 2, 90 dns_dnssecstats_fail = 3, 91 92 dns_dnssecstats_max = 4, 93 94 /*% 95 * Zone statistics counters. 96 */ 97 dns_zonestatscounter_notifyoutv4 = 0, 98 dns_zonestatscounter_notifyoutv6 = 1, 99 dns_zonestatscounter_notifyinv4 = 2, 100 dns_zonestatscounter_notifyinv6 = 3, 101 dns_zonestatscounter_notifyrej = 4, 102 dns_zonestatscounter_soaoutv4 = 5, 103 dns_zonestatscounter_soaoutv6 = 6, 104 dns_zonestatscounter_axfrreqv4 = 7, 105 dns_zonestatscounter_axfrreqv6 = 8, 106 dns_zonestatscounter_ixfrreqv4 = 9, 107 dns_zonestatscounter_ixfrreqv6 = 10, 108 dns_zonestatscounter_xfrsuccess = 11, 109 dns_zonestatscounter_xfrfail = 12, 110 111 dns_zonestatscounter_max = 13, 112 113 /* 114 * Adb statistics values. 115 */ 116 dns_adbstats_nentries = 0, 117 dns_adbstats_entriescnt = 1, 118 dns_adbstats_nnames = 2, 119 dns_adbstats_namescnt = 3, 120 121 dns_adbstats_max = 4, 122 123 /* 124 * Cache statistics values. 125 */ 126 dns_cachestatscounter_hits = 1, 127 dns_cachestatscounter_misses = 2, 128 dns_cachestatscounter_queryhits = 3, 129 dns_cachestatscounter_querymisses = 4, 130 dns_cachestatscounter_deletelru = 5, 131 dns_cachestatscounter_deletettl = 6, 132 133 dns_cachestatscounter_max = 7, 134 135 /*% 136 * Query statistics counters (obsolete). 137 */ 138 dns_statscounter_success = 0, /*%< Successful lookup */ 139 dns_statscounter_referral = 1, /*%< Referral result */ 140 dns_statscounter_nxrrset = 2, /*%< NXRRSET result */ 141 dns_statscounter_nxdomain = 3, /*%< NXDOMAIN result */ 142 dns_statscounter_recursion = 4, /*%< Recursion was used */ 143 dns_statscounter_failure = 5, /*%< Some other failure */ 144 dns_statscounter_duplicate = 6, /*%< Duplicate query */ 145 dns_statscounter_dropped = 7 /*%< Duplicate query (dropped) */ 146 }; 147 148 #define DNS_STATS_NCOUNTERS 8 149 150 #if 0 151 /*%< 152 * Flag(s) for dns_xxxstats_dump(). DNS_STATSDUMP_VERBOSE is obsolete. 153 * ISC_STATSDUMP_VERBOSE should be used instead. These two values are 154 * intentionally defined to be the same value to ensure binary compatibility. 155 */ 156 #define DNS_STATSDUMP_VERBOSE 0x00000001 /*%< dump 0-value counters */ 157 #endif 158 159 /*%< 160 * (Obsoleted) 161 */ 162 LIBDNS_EXTERNAL_DATA extern const char *dns_statscounter_names[]; 163 164 /*% 165 * Attributes for statistics counters of RRset and Rdatatype types. 166 * 167 * _OTHERTYPE 168 * The rdata type is not explicitly supported and the corresponding counter 169 * is counted for other such types, too. When this attribute is set, 170 * the base type is of no use. 171 * 172 * _NXRRSET 173 * RRset type counters only. Indicates the RRset is non existent. 174 * 175 * _NXDOMAIN 176 * RRset type counters only. Indicates a non existent name. When this 177 * attribute is set, the base type is of no use. 178 * 179 * _STALE 180 * RRset type counters only. This indicates a record that marked for 181 * removal. 182 * 183 * Note: incrementing _STALE will decrement the corresponding non-stale 184 * counter. 185 */ 186 #define DNS_RDATASTATSTYPE_ATTR_OTHERTYPE 0x0001 187 #define DNS_RDATASTATSTYPE_ATTR_NXRRSET 0x0002 188 #define DNS_RDATASTATSTYPE_ATTR_NXDOMAIN 0x0004 189 #define DNS_RDATASTATSTYPE_ATTR_STALE 0x0008 190 191 /*%< 192 * Conversion macros among dns_rdatatype_t, attributes and isc_statscounter_t. 193 */ 194 #define DNS_RDATASTATSTYPE_BASE(type) ((dns_rdatatype_t)((type) & 0xFFFF)) 195 #define DNS_RDATASTATSTYPE_ATTR(type) ((type) >> 16) 196 #define DNS_RDATASTATSTYPE_VALUE(b, a) (((a) << 16) | (b)) 197 198 /*%< 199 * Types of dump callbacks. 200 */ 201 typedef void (*dns_generalstats_dumper_t)(isc_statscounter_t, isc_uint64_t, 202 void *); 203 typedef void (*dns_rdatatypestats_dumper_t)(dns_rdatastatstype_t, isc_uint64_t, 204 void *); 205 typedef void (*dns_opcodestats_dumper_t)(dns_opcode_t, isc_uint64_t, void *); 206 207 ISC_LANG_BEGINDECLS 208 209 isc_result_t 210 dns_generalstats_create(isc_mem_t *mctx, dns_stats_t **statsp, int ncounters); 211 /*%< 212 * Create a statistics counter structure of general type. It counts a general 213 * set of counters indexed by an ID between 0 and ncounters -1. 214 * This function is obsolete. A more general function, isc_stats_create(), 215 * should be used. 216 * 217 * Requires: 218 *\li 'mctx' must be a valid memory context. 219 * 220 *\li 'statsp' != NULL && '*statsp' == NULL. 221 * 222 * Returns: 223 *\li ISC_R_SUCCESS -- all ok 224 * 225 *\li anything else -- failure 226 */ 227 228 isc_result_t 229 dns_rdatatypestats_create(isc_mem_t *mctx, dns_stats_t **statsp); 230 /*%< 231 * Create a statistics counter structure per rdatatype. 232 * 233 * Requires: 234 *\li 'mctx' must be a valid memory context. 235 * 236 *\li 'statsp' != NULL && '*statsp' == NULL. 237 * 238 * Returns: 239 *\li ISC_R_SUCCESS -- all ok 240 * 241 *\li anything else -- failure 242 */ 243 244 isc_result_t 245 dns_rdatasetstats_create(isc_mem_t *mctx, dns_stats_t **statsp); 246 /*%< 247 * Create a statistics counter structure per RRset. 248 * 249 * Requires: 250 *\li 'mctx' must be a valid memory context. 251 * 252 *\li 'statsp' != NULL && '*statsp' == NULL. 253 * 254 * Returns: 255 *\li ISC_R_SUCCESS -- all ok 256 * 257 *\li anything else -- failure 258 */ 259 260 isc_result_t 261 dns_opcodestats_create(isc_mem_t *mctx, dns_stats_t **statsp); 262 /*%< 263 * Create a statistics counter structure per opcode. 264 * 265 * Requires: 266 *\li 'mctx' must be a valid memory context. 267 * 268 *\li 'statsp' != NULL && '*statsp' == NULL. 269 * 270 * Returns: 271 *\li ISC_R_SUCCESS -- all ok 272 * 273 *\li anything else -- failure 274 */ 275 276 void 277 dns_stats_attach(dns_stats_t *stats, dns_stats_t **statsp); 278 /*%< 279 * Attach to a statistics set. 280 * 281 * Requires: 282 *\li 'stats' is a valid dns_stats_t. 283 * 284 *\li 'statsp' != NULL && '*statsp' == NULL 285 */ 286 287 void 288 dns_stats_detach(dns_stats_t **statsp); 289 /*%< 290 * Detaches from the statistics set. 291 * 292 * Requires: 293 *\li 'statsp' != NULL and '*statsp' is a valid dns_stats_t. 294 */ 295 296 void 297 dns_generalstats_increment(dns_stats_t *stats, isc_statscounter_t counter); 298 /*%< 299 * Increment the counter-th counter of stats. This function is obsolete. 300 * A more general function, isc_stats_increment(), should be used. 301 * 302 * Requires: 303 *\li 'stats' is a valid dns_stats_t created by dns_generalstats_create(). 304 * 305 *\li counter is less than the maximum available ID for the stats specified 306 * on creation. 307 */ 308 309 void 310 dns_rdatatypestats_increment(dns_stats_t *stats, dns_rdatatype_t type); 311 /*%< 312 * Increment the statistics counter for 'type'. 313 * 314 * Requires: 315 *\li 'stats' is a valid dns_stats_t created by dns_rdatatypestats_create(). 316 */ 317 318 void 319 dns_rdatasetstats_increment(dns_stats_t *stats, dns_rdatastatstype_t rrsettype); 320 /*%< 321 * Increment the statistics counter for 'rrsettype'. 322 * 323 * Note: if 'rrsettype' has the _STALE attribute set the corresponding 324 * non-stale counter will be decremented. 325 * 326 * Requires: 327 *\li 'stats' is a valid dns_stats_t created by dns_rdatasetstats_create(). 328 */ 329 330 void 331 dns_rdatasetstats_decrement(dns_stats_t *stats, dns_rdatastatstype_t rrsettype); 332 /*%< 333 * Decrement the statistics counter for 'rrsettype'. 334 * 335 * Requires: 336 *\li 'stats' is a valid dns_stats_t created by dns_rdatasetstats_create(). 337 */ 338 339 void 340 dns_opcodestats_increment(dns_stats_t *stats, dns_opcode_t code); 341 /*%< 342 * Increment the statistics counter for 'code'. 343 * 344 * Requires: 345 *\li 'stats' is a valid dns_stats_t created by dns_opcodestats_create(). 346 */ 347 348 void 349 dns_generalstats_dump(dns_stats_t *stats, dns_generalstats_dumper_t dump_fn, 350 void *arg, unsigned int options); 351 /*%< 352 * Dump the current statistics counters in a specified way. For each counter 353 * in stats, dump_fn is called with its current value and the given argument 354 * arg. By default counters that have a value of 0 is skipped; if options has 355 * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped. 356 * 357 * This function is obsolete. A more general function, isc_stats_dump(), 358 * should be used. 359 * 360 * Requires: 361 *\li 'stats' is a valid dns_stats_t created by dns_generalstats_create(). 362 */ 363 364 void 365 dns_rdatatypestats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn, 366 void *arg, unsigned int options); 367 /*%< 368 * Dump the current statistics counters in a specified way. For each counter 369 * in stats, dump_fn is called with the corresponding type in the form of 370 * dns_rdatastatstype_t, the current counter value and the given argument 371 * arg. By default counters that have a value of 0 is skipped; if options has 372 * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped. 373 * 374 * Requires: 375 *\li 'stats' is a valid dns_stats_t created by dns_generalstats_create(). 376 */ 377 378 void 379 dns_rdatasetstats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn, 380 void *arg, unsigned int options); 381 /*%< 382 * Dump the current statistics counters in a specified way. For each counter 383 * in stats, dump_fn is called with the corresponding type in the form of 384 * dns_rdatastatstype_t, the current counter value and the given argument 385 * arg. By default counters that have a value of 0 is skipped; if options has 386 * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped. 387 * 388 * Requires: 389 *\li 'stats' is a valid dns_stats_t created by dns_generalstats_create(). 390 */ 391 392 void 393 dns_opcodestats_dump(dns_stats_t *stats, dns_opcodestats_dumper_t dump_fn, 394 void *arg, unsigned int options); 395 /*%< 396 * Dump the current statistics counters in a specified way. For each counter 397 * in stats, dump_fn is called with the corresponding opcode, the current 398 * counter value and the given argument arg. By default counters that have a 399 * value of 0 is skipped; if options has the ISC_STATSDUMP_VERBOSE flag, even 400 * such counters are dumped. 401 * 402 * Requires: 403 *\li 'stats' is a valid dns_stats_t created by dns_generalstats_create(). 404 */ 405 406 isc_result_t 407 dns_stats_alloccounters(isc_mem_t *mctx, isc_uint64_t **ctrp); 408 /*%< 409 * Allocate an array of query statistics counters from the memory 410 * context 'mctx'. 411 * 412 * This function is obsoleted. Use dns_xxxstats_create() instead. 413 */ 414 415 void 416 dns_stats_freecounters(isc_mem_t *mctx, isc_uint64_t **ctrp); 417 /*%< 418 * Free an array of query statistics counters allocated from the memory 419 * context 'mctx'. 420 * 421 * This function is obsoleted. Use dns_stats_destroy() instead. 422 */ 423 424 ISC_LANG_ENDDECLS 425 426 #endif /* DNS_STATS_H */ 427