Changeset 811c412ce800f3a4eeaa9c2bc4d5c35fe9982384

Show
Ignore:
Timestamp:
08/12/11 04:47:29 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1313124449 -0400
git-parent:

[7b999849cdf5ce592e0b1813f5f4800b1854fecd]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1313124449 -0400
Message:

selfcheck introspection on when data is pulled by stratcon

Files:

Legend:

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

    rf91ddca r811c412  
    4343#include "noit_check.h" 
    4444#include "noit_check_tools.h" 
     45#include "noit_jlog_listener.h" 
    4546#include "utils/noit_log.h" 
    4647#include "utils/noit_hash.h" 
     
    7273  snprintf(buffer, sizeof(buffer), "%s_threads", jobq->queue_name); 
    7374  noit_stats_set_metric(current, buffer, METRIC_INT32, &s32); 
     75} 
     76static int selfcheck_feed_details(jlog_feed_stats_t *s, void *vcurrent) { 
     77  char buff[256]; 
     78  uint64_t ms; 
     79  struct timeval now, diff; 
     80  stats_t *current = (stats_t *)vcurrent; 
     81  gettimeofday(&now, NULL); 
     82 
     83  if(s->last_connection.tv_sec > 0) { 
     84    sub_timeval(now, s->last_connection, &diff); 
     85    ms = diff.tv_sec * 1000 + diff.tv_usec / 1000; 
     86    snprintf(buff, sizeof(buff), "feed`%s`last_connection_ms", s->feed_name); 
     87    noit_stats_set_metric(current, buff, METRIC_UINT64, &ms); 
     88  } 
     89 
     90  if(s->last_checkpoint.tv_sec > 0) { 
     91    sub_timeval(now, s->last_checkpoint, &diff); 
     92    ms = diff.tv_sec * 1000 + diff.tv_usec / 1000; 
     93    snprintf(buff, sizeof(buff), "feed`%s`last_checkpoint_ms", s->feed_name); 
     94    noit_stats_set_metric(current, buff, METRIC_UINT64, &ms); 
     95  } 
     96  return 1; 
    7497} 
    7598static void selfcheck_log_results(noit_module_t *self, noit_check_t *check) { 
     
    113136  u64 = noit_check_completion_count(); 
    114137  noit_stats_set_metric(&current, "checks_run", METRIC_UINT64, &u64); 
     138  /* feed pull info */ 
     139  noit_jlog_foreach_feed_stats(selfcheck_feed_details, &current); 
    115140 
    116141  noit_check_set_stats(self, check, &current); 
  • src/noit_jlog_listener.c

    r8fc8902 r811c412  
    6565  jlog_id start; 
    6666  jlog_id finish; 
     67  jlog_feed_stats_t *feed_stats; 
    6768  int count; 
    6869  int wants_shutdown; 
     
    8990} 
    9091 
     92static noit_hash_table feed_stats = NOIT_HASH_EMPTY; 
     93 
     94jlog_feed_stats_t * 
     95noit_jlog_feed_stats(const char *sub) { 
     96  void *vs = NULL; 
     97  jlog_feed_stats_t *s = NULL; 
     98  if(noit_hash_retrieve(&feed_stats, sub, strlen(sub), &vs)) 
     99    return (jlog_feed_stats_t *)vs; 
     100  s = calloc(1, sizeof(*s)); 
     101  s->feed_name = strdup(sub); 
     102  noit_hash_store(&feed_stats, s->feed_name, strlen(s->feed_name), s); 
     103  return s; 
     104} 
     105int 
     106noit_jlog_foreach_feed_stats(int (*f)(jlog_feed_stats_t *, void *), 
     107                             void *c) { 
     108  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     109  const char *key; 
     110  int klen, cnt = 0; 
     111  void *vs; 
     112  while(noit_hash_next(&feed_stats, &iter, &key, &klen, &vs)) { 
     113    cnt += f((jlog_feed_stats_t *)vs, c); 
     114  } 
     115  return cnt; 
     116} 
    91117static int 
    92118__safe_Ewrite(eventer_t e, void *b, int l, int *mask) { 
     
    214240        goto alldone; 
    215241      } 
     242      gettimeofday(&jcl->feed_stats->last_checkpoint, NULL); 
    216243      jlog_ctx_read_checkpoint(jcl->jlog, &jcl->chkpt); 
    217244    } 
     
    242269 alldone: 
    243270  e->opset->close(e->fd, &mask, e); 
     271  noit_atomic_dec32(&jcl->feed_stats->connections); 
    244272  if(jcl) noit_jlog_closure_free(jcl); 
    245273  if(ac) acceptor_closure_free(ac); 
     
    310338      } 
    311339      strlcpy(subscriber, ac->remote_cn, sizeof(subscriber)); 
     340      jcl->feed_stats = noit_jlog_feed_stats(subscriber); 
    312341    } 
    313342    else { 
     343      jcl->feed_stats = noit_jlog_feed_stats("~"); 
    314344      snprintf(subscriber, sizeof(subscriber), 
    315345               "~%07d", noit_atomic_inc32(&tmpfeedcounter)); 
     
    354384  pthread_attr_init(&tattr); 
    355385  pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); 
     386  gettimeofday(&jcl->feed_stats->last_connection, NULL); 
     387  noit_atomic_inc32(&jcl->feed_stats->connections); 
    356388  if(pthread_create(&tid, &tattr, noit_jlog_thread_main, newe) == 0) { 
    357389    return 0; 
  • src/noit_jlog_listener.h

    r88a7178 r811c412  
    4040#define NOIT_JLOG_DATA_TEMP_FEED 0x7e66feed 
    4141 
     42typedef struct { 
     43  char *feed_name; 
     44  noit_atomic32_t connections; 
     45  struct timeval last_connection; 
     46  struct timeval last_checkpoint; 
     47} jlog_feed_stats_t; 
     48 
    4249API_EXPORT(void) 
    4350  noit_jlog_listener_init(void); 
     
    4754                    struct timeval *now); 
    4855 
     56/* This API call is only safe from the eventer thread */ 
     57API_EXPORT(jlog_feed_stats_t *) 
     58  noit_jlog_feed_stats(const char *sub); 
     59 
     60API_EXPORT(int) 
     61  noit_jlog_foreach_feed_stats(int (*f)(jlog_feed_stats_t *, void *), 
     62                               void *); 
     63 
    4964#endif