Module: sip-router Branch: master Commit: 4e0402173999fcb95257ebb000f3a8b951d1f68c URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4e040217...
Author: Marius Zbihlei marius.zbihlei@1and1.ro Committer: Marius Zbihlei marius.zbihlei@1and1.ro Date: Wed Aug 11 17:54:27 2010 +0300
core:dns Added failed DNS requests statistics when dns cache is not used
DNS statistics can be seen with:
sercmd> cnt.get dns failed_dns_request
Still TODO: failed statistics for DNS cache
---
resolve.c | 37 +++++++++++++++++++++++++++++++++---- resolve.h | 9 +++++++++ 2 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/resolve.c b/resolve.c index b68aadc..9aedd85 100644 --- a/resolve.c +++ b/resolve.c @@ -77,7 +77,13 @@ #include "dns_cache.h" #endif
- +/* counters framework */ +struct dns_counters_h dns_cnts_h; +counter_def_t dns_cnt_defs[] = { + {&dns_cnts_h.failed_dns_req, "failed_dns_request", 0, 0, 0, + "incremented each time a DNS request has failed."}, + {0, 0, 0, 0, 0, 0 } +};
/* mallocs for local stuff */ #define local_malloc pkg_malloc @@ -119,6 +125,18 @@ int register_resolv_reinit_cb(on_resolv_reinit cb) } #endif
+/* counter init function + must be called before fork +*/ +static int stat_init() +{ + if (counter_register_array("dns", dns_cnt_defs) < 0) + goto error; + return 0; +error: + return -1; +} + /* init. the resolver * params: retr_time - time before retransmitting (must be >0) * retr_no - retransmissions number @@ -157,12 +175,17 @@ static int _resolv_init() /* wrapper function to initialize the resolver at startup */ int resolv_init() { + int res = -1; _resolv_init();
#ifdef USE_NAPTR init_naptr_proto_prefs(); #endif - return 0; + /* init counter API only at startup + * This function must be called before DNS cache init method (if available) + */ + res = stat_init(); + return res; }
/* wrapper function to reinitialize the resolver @@ -1486,11 +1509,17 @@ end: */ struct hostent* _sip_resolvehost(str* name, unsigned short* port, char* proto) { + struct hostent* res = NULL; #ifdef USE_NAPTR if (cfg_get(core, core_cfg, dns_try_naptr)) - return naptr_sip_resolvehost(name, port, proto); + res = naptr_sip_resolvehost(name, port, proto); #endif - return srv_sip_resolvehost(name, 0, port, proto, 0, 0); + res = srv_sip_resolvehost(name, 0, port, proto, 0, 0); + if( unlikely(!res) ){ + /* failed DNS request */ + counter_inc(dns_cnts_h.failed_dns_req); + } + return res; }
diff --git a/resolve.h b/resolve.h index 9f0d4ef..5611c9d 100644 --- a/resolve.h +++ b/resolve.h @@ -47,6 +47,7 @@ #include <netdb.h> #include <arpa/nameser.h> #include <resolv.h> +#include "counters.h"
#ifdef __OS_darwin #include <arpa/nameser_compat.h> @@ -78,6 +79,14 @@ #define RES_ONLY_TYPE 1 /* return only the specified type records */ #define RES_AR 2 /* return also the additional records */
+/* counter for failed DNS requests +*/ +struct dns_counters_h { + counter_handle_t failed_dns_req; +}; + +extern struct dns_counters_h dns_cnts_h; + /* query union*/ union dns_query{ HEADER hdr;