Changeset fb90c74b988a187602cf743f22813de38cb8dd94

Show
Ignore:
Timestamp:
01/28/08 15:39:56 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1201534796 +0000
git-parent:

[b09f3a7643ce0f65ba32059bec4c7971b369b03c]

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

change detection and keeping old status

Files:

Legend:

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

    rb09f3a7 rfb90c74  
    8282  float avail, min = MAXFLOAT, max = 0.0, avg = 0.0, cnt; 
    8383  int i, points = 0; 
     84  char human_buffer[256]; 
     85  stats_t current; 
     86  struct timeval duration; 
    8487 
    8588  data = (struct check_info *)check->closure; 
     
    99102  avail = (float)points /cnt; 
    100103  avg /= (float)points; 
    101   noit_log(nldeb, NULL, "ping_icmp(%s) [cnt=%d,avail=%0.0f,min=%0.4f,max=%0.4f,avg=%0.4f]\n", check->target, (int)cnt, 100.0*avail, min, max, avg); 
     104 
     105  snprintf(human_buffer, sizeof(human_buffer), 
     106           "cnt=%d,avail=%0.0f,min=%0.4f,max=%0.4f,avg=%0.4f", 
     107           (int)cnt, 100.0*avail, min, max, avg); 
     108  noit_log(nldeb, NULL, "ping_icmp(%s) [%s]\n", check->target, human_buffer); 
     109 
     110  gettimeofday(&current.whence, NULL); 
     111  sub_timeval(current.whence, check->last_fire_time, &duration); 
     112  current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; 
     113  current.available = (avail > 0.0) ? NP_AVAILABLE : NP_UNAVAILABLE; 
     114  current.state = (avail < 1.0) ? NP_BAD : NP_GOOD; 
     115  current.status = human_buffer; 
     116  noit_poller_set_state(check, &current); 
    102117} 
    103118static int ping_icmp_timeout(eventer_t e, int mask, 
     
    108123  data = (struct check_info *)pcl->check->closure; 
    109124  data->timeout_event = NULL; 
     125  pcl->check->flags &= ~NP_RUNNING; 
    110126  free(pcl); 
    111127  return 0; 
     
    127143 
    128144  while(1) { 
    129     float t1, t2; 
    130145    int inlen, iphlen; 
    131146    noit_check_t check; 
     
    154169      continue; 
    155170    } 
    156     if(icp->icmp_id != (unsigned short)self) { 
     171    if(icp->icmp_id != (((vpsized_uint)self) & 0xffff)) { 
    157172      noit_log(nlerr, now, 
    158173               "ping_icmp not sent from this instance (%d:%d) vs. %d\n", 
    159                icp->icmp_id, ntohs(icp->icmp_seq), (unsigned short)self); 
     174               icp->icmp_id, ntohs(icp->icmp_seq), 
     175               (((vpsized_uint)self) & 0xffff)); 
    160176      continue; 
    161177    } 
     
    181197 
    182198    sub_timeval(*now, payload->whence, &tt); 
    183     t1 = (float)tt.tv_sec + (float)tt.tv_usec / 1000000.0; 
    184     data->turnaround[payload->check_pack_no] = t1
     199    data->turnaround[payload->check_pack_no] = 
     200      (float)tt.tv_sec + (float)tt.tv_usec / 1000000.0
    185201    if(ping_icmp_is_complete(self, check)) { 
    186202      ping_icmp_log_results(self, check); 
     
    189205      eventer_free(data->timeout_event); 
    190206      data->timeout_event = NULL; 
     207      check->flags &= ~NP_RUNNING; 
    191208    } 
    192209  } 
     
    313330  eventer_t newe; 
    314331 
     332  check->flags |= NP_RUNNING; 
    315333  noit_log(nldeb, NULL, "ping_icmp_send(%p,%s,%d,%d)\n", 
    316334           self, check->target, interval, count); 
     
    354372    icp->icmp_cksum = 0; 
    355373    icp->icmp_seq = htons(ci->seq++); 
    356     icp->icmp_id = (unsigned short)self
     374    icp->icmp_id = (((vpsized_uint)self) & 0xffff)
    357375 
    358376    uuid_copy(payload->checkid, check->checkid); 
  • src/noit_config.h.in

    r2c65def rfb90c74  
    195195#endif 
    196196 
    197 #endif 
     197#if (SIZEOF_VOID_P == 8) 
     198typedef u_int64_t vpsized_uint; 
     199typedef int64_t vpsized_int; 
     200#elif (SIZEOF_VOID_P == 4) 
     201typedef u_int32_t vpsized_uint; 
     202typedef int32_t vpsized_int; 
     203#else 
     204#error Unsupported size of void ptr 
     205#endif 
     206 
     207#endif 
  • src/noit_poller.c

    rb09f3a7 rfb90c74  
    2525#define UUID_SIZE sizeof(struct uuid_dummy) 
    2626 
     27static const char * 
     28__noit_check_available_string(int16_t available) { 
     29  switch(available) { 
     30    case NP_AVAILABLE:    return "available"; 
     31    case NP_UNAVAILABLE:  return "unavailable"; 
     32    case NP_UNKNOWN:      return "unknown"; 
     33  } 
     34  return "???"; 
     35} 
     36static const char * 
     37__noit_check_state_string(int16_t state) { 
     38  switch(state) { 
     39    case NP_GOOD:         return "good"; 
     40    case NP_BAD:          return "bad"; 
     41    case NP_UNKNOWN:      return "unknown"; 
     42  } 
     43  return "???"; 
     44} 
    2745void 
    2846noit_poller_load_checks() { 
     
    213231} 
    214232 
     233 
     234void 
     235noit_poller_set_state(noit_check_t check, stats_t *newstate) { 
     236  int report_change = 0; 
     237  if(check->stats.previous.status) 
     238    free(check->stats.previous.status); 
     239  memcpy(&check->stats.previous, &check->stats.current, sizeof(stats_t)); 
     240  memcpy(&check->stats.current, newstate, sizeof(stats_t)); 
     241  if(check->stats.current.status) 
     242    check->stats.current.status = strdup(check->stats.current.status); 
     243 
     244  /* check for state changes */ 
     245  if(check->stats.current.available != 0 && 
     246     check->stats.previous.available != 0 && 
     247     check->stats.current.available != check->stats.previous.available) 
     248    report_change = 1; 
     249  if(check->stats.current.state != 0 && 
     250     check->stats.previous.state != 0 && 
     251     check->stats.current.state != check->stats.previous.state) 
     252    report_change = 1; 
     253 
     254  if(report_change) { 
     255    noit_log(noit_debug, NULL, "%s/%s -> [%s/%s]\n", 
     256             check->target, check->module, 
     257             __noit_check_available_string(check->stats.current.available), 
     258             __noit_check_state_string(check->stats.current.state)); 
     259  } 
     260} 
  • src/noit_poller.h

    rb09f3a7 rfb90c74  
    3636#define NP_DISABLED 0x00000004 
    3737 
     38#define NP_UNKNOWN 0               /* stats_t.{available,state} */ 
     39#define NP_AVAILABLE 1             /* stats_t.available */ 
     40#define NP_UNAVAILABLE -1          /* stats_t.available */ 
     41#define NP_BAD 1                   /* stats_t.state */ 
     42#define NP_GOOD 2                  /* stats_t.state */ 
     43 
    3844typedef struct { 
    3945  struct timeval whence; 
     46  int16_t available; 
     47  int16_t state; 
    4048  u_int32_t duration; 
    4149  char *status; 
     
    6068  struct timeval last_fire_time; 
    6169  struct { 
    62     stats_t in_progress
    63     stats_t last
     70    stats_t current
     71    stats_t previous
    6472  } stats; 
    6573  void *closure; 
     
    8593  noit_poller_lookup(uuid_t in); 
    8694 
     95API_EXPORT(void) 
     96  noit_poller_set_state(noit_check_t check, stats_t *newstate); 
     97 
    8798#endif 
  • src/sample.conf

    rb09f3a7 rfb90c74  
    2929  <checks> 
    3030    <checkgroup> 
    31       <module>ping_icmp</module>> 
     31      <module>ping_icmp</module> 
    3232      <period>30000</period> 
    3333      <timeout>20000</timeout>