Skip to content

Commit

Permalink
OPS-9 (Self Diagnosis): Complete support for DNS diagnosis
Browse files Browse the repository at this point in the history
    * also time the DNS A record lookups in addition to NAPTR and SRV
    * export some relevant DNS-related statistics
  • Loading branch information
liviuchircu committed Apr 12, 2019
1 parent d677db3 commit 42697dc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion main.c
Expand Up @@ -1214,7 +1214,10 @@ int main(int argc, char** argv)
}

/* init the resolver, before fixing the config */
resolv_init();
if (resolv_init() != 0) {
LM_ERR("failed to init DNS resolver\n");
return -1;
}

fix_poll_method( &io_poll_method );

Expand Down
27 changes: 26 additions & 1 deletion resolve.c
Expand Up @@ -89,6 +89,9 @@ static char hostbuf[MAX_BUFF_SIZE];
static char *h_addr_ptrs[MAXADDRS];
static char *host_aliases[MAXALIASES];

stat_var *dns_total_queries;
stat_var *dns_slow_queries;

typedef union {
int32_t al;
char ac;
Expand Down Expand Up @@ -452,6 +455,8 @@ inline struct hostent* resolvehost(char* name, int no_ip_test)
int err;
static struct hostent* he2=0;
#endif
int usdiff;
struct timeval start;
struct ip_addr* ip;
str s;

Expand All @@ -468,6 +473,8 @@ inline struct hostent* resolvehost(char* name, int no_ip_test)
}
}

start_expire_timer(start, execdnsthreshold);

if(dns_try_ipv6){
/*try ipv6*/
#ifdef HAVE_GETHOSTBYNAME2
Expand All @@ -489,7 +496,7 @@ inline struct hostent* resolvehost(char* name, int no_ip_test)
#endif
if (he != 0)
/* return the inet6 result if exists */
return he;
goto out;
}

if (dnscache_fetch_func != NULL) {
Expand All @@ -498,6 +505,15 @@ inline struct hostent* resolvehost(char* name, int no_ip_test)
else {
he=gethostbyname(name);
}

out:
usdiff = get_time_diff(&start);
if (execdnsthreshold && usdiff > execdnsthreshold) {
log_expiry(usdiff, execdnsthreshold, "dns", name, strlen(name), 0);
inc_stat(dns_slow_queries);
}

inc_stat(dns_total_queries);
return he;
}

Expand Down Expand Up @@ -682,6 +698,13 @@ int resolv_init(void)
#warning "no resolv timeout support"
LM_WARN("no resolv options support - resolv options will be ignored\n");
#endif

if (register_stat("dns", "dns_total_queries", &dns_total_queries, 0) ||
register_stat("dns", "dns_slow_queries", &dns_slow_queries, 0)) {
LM_ERR("failed to register DNS stats\n");
return -1;
}

return 0;
}

Expand Down Expand Up @@ -1083,6 +1106,8 @@ struct rdata* get_record(char* name, int type)
start_expire_timer(start,execdnsthreshold);
size=res_search(name, C_IN, type, buff.buff, sizeof(buff));
stop_expire_timer(start,execdnsthreshold,"dns",name,strlen(name),0);
inc_stat(dns_total_queries);

if (size<0) {
LM_DBG("lookup(%s, %d) failed\n", name, type);
if (dnscache_put_func != NULL) {
Expand Down
1 change: 1 addition & 0 deletions statistics.h
Expand Up @@ -240,5 +240,6 @@ extern gen_lock_t *stat_lock;
#define if_reset_stat( _c, _var)
#endif /*STATISTICS*/

#define inc_stat(_var) update_stat(_var, 1)

#endif

0 comments on commit 42697dc

Please sign in to comment.