Changeset 7fbea6436b3d271e41e913291bb1bd2f606358e3

Show
Ignore:
Timestamp:
12/21/10 22:39:59 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1292971199 +0000
git-parent:

[92a48807012238729af2563033f6753ce03b460e]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1292971199 +0000
Message:

correct refcnt tracking and add some console introspection, refs #333

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/snmp.c

    ra5e761d r7fbea64  
    129129  int in_table; 
    130130  int refcnt; 
     131  struct timeval last_open; 
    131132}; 
    132133 
     
    149150  noit_module_t *self; 
    150151  noit_check_t *check; 
     152  struct target_session *ts; 
    151153}; 
    152154 
     
    340342  struct check_info *info = closure; 
    341343  info->timedout = 1; 
     344  if(info->ts) { 
     345    info->ts->refcnt--; 
     346    noit_snmp_session_cleanse(info->ts); 
     347    info->ts = NULL; 
     348  } 
    342349  remove_check(info); 
    343350  /* Log our findings */ 
     
    739746  current.available = NP_AVAILABLE; 
    740747 
     748  /* Rate limit */ 
     749  if(((current.whence.tv_sec * 1000 + 
     750       current.whence.tv_usec / 1000) - 
     751      (check->last_fire_time.tv_sec * 1000 + 
     752       check->last_fire_time.tv_usec / 1000)) < check->period) goto cleanup; 
     753 
     754  /* update the last fire time... */ 
     755  gettimeofday(&check->last_fire_time, NULL); 
     756 
    741757  for(; var != NULL; var = var->next_variable) 
    742758    if(noit_snmp_trapvars_to_stats(&current, var) == 0) success++; 
     
    762778                                     void *magic) { 
    763779  struct check_info *info; 
    764   struct target_session *ts = magic; 
    765  
    766780  /* We don't deal with refcnt hitting zero here.  We could only be hit from 
    767781   * the snmp read/timeout stuff.  Handle it there. 
    768782   */ 
    769   ts->refcnt--;  
    770783 
    771784  info = get_check(reqid); 
    772785  if(!info) return 1; 
     786  if(info->ts) { 
     787    info->ts->refcnt--; 
     788    info->ts = NULL; 
     789  } 
    773790  remove_check(info); 
    774791  if(info->timeoutevent) { 
     
    800817  sess.callback_magic = ts; 
    801818  ts->sess_handle = snmp_sess_open(&sess); 
     819  gettimeofday(&ts->last_open, NULL); 
    802820} 
    803821 
     
    909927     (info->reqid = snmp_sess_send(ts->sess_handle, req)) != 0) { 
    910928    struct timeval when, to; 
     929    info->ts = ts; 
    911930    info->timeoutevent = eventer_alloc(); 
    912931    info->timeoutevent->callback = noit_snmp_check_timeout; 
     
    9871006} 
    9881007 
     1008static void 
     1009nc_printf_snmpts_brief(noit_console_closure_t ncct, 
     1010                       struct target_session *ts) { 
     1011  struct timeval now, diff; 
     1012  gettimeofday(&now, NULL); 
     1013  sub_timeval(now, ts->last_open, &diff); 
     1014  nc_printf(ncct, "[%s]\n\topened: %0.3fs ago\n\tFD: %d\n\trefcnt: %d\n", 
     1015            ts->target, diff.tv_sec + (float)diff.tv_usec/1000000, 
     1016            ts->fd, ts->refcnt); 
     1017} 
     1018 
     1019static int 
     1020noit_console_show_snmp(noit_console_closure_t ncct, 
     1021                       int argc, char **argv, 
     1022                       noit_console_state_t *dstate, 
     1023                       void *closure) { 
     1024  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     1025  uuid_t key_id; 
     1026  int klen; 
     1027  void *vts; 
     1028  snmp_mod_config_t *conf = closure; 
     1029 
     1030  while(noit_hash_next(&conf->target_sessions, &iter, 
     1031                       (const char **)key_id, &klen, 
     1032                       &vts)) { 
     1033    struct target_session *ts = vts; 
     1034    nc_printf_snmpts_brief(ncct, ts); 
     1035  } 
     1036  return 0; 
     1037} 
     1038 
     1039static void 
     1040register_console_snmp_commands(snmp_mod_config_t *conf) { 
     1041  noit_console_state_t *tl; 
     1042  cmd_info_t *showcmd; 
     1043 
     1044  tl = noit_console_state_initial(); 
     1045  showcmd = noit_console_state_get_cmd(tl, "show"); 
     1046  assert(showcmd && showcmd->dstate); 
     1047  noit_console_state_add_cmd(showcmd->dstate, 
     1048    NCSCMD("snmp", noit_console_show_snmp, NULL, NULL, conf)); 
     1049} 
     1050 
    9891051static int noit_snmp_init(noit_module_t *self) { 
    9901052  const char *opt; 
     
    9991061    init_snmp("noitd"); 
    10001062    __snmp_initialize_once = 1; 
     1063  } 
     1064  if(strcmp(self->hdr.name, "snmp") == 0) { 
     1065    register_console_snmp_commands(conf); 
    10011066  } 
    10021067