Show
Ignore:
Timestamp:
08/15/11 19:36:52 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1313437012 -0400
git-parent:

[93c0f7d278d008139c3282dbbff1ed58c15d8dfa], [633221873749ec0a7b4c5550e3aed3c991ec5126]

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

merge dtrace branch to master

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/jlog/jlog_io.c

    re153d26 rb394de2  
    236236{ 
    237237  struct stat sb; 
    238   if (fstat(f->fd, &sb) != 0) 
    239     return -1; 
     238  int rv; 
     239  while ((rv = fstat(f->fd, &sb) != 0) == -1 && errno == EINTR) ; 
     240  if (rv != 0) return -1; 
    240241  return sb.st_size; 
    241242} 
  • src/modules-lua/noit/module/jezebel.lua

    rb553f9a r6b499c5  
    161161    local doc = noit.parsexml(output) 
    162162    if doc == nil then 
    163         noit.log("error", "bad xml: %s\n", output) 
     163        noit.log("debug", "bad xml: %s\n", output) 
    164164        check.status("bad xml from jezebel") 
    165165        return 
  • src/modules/collectd.c

    rb8cf70c rf91ddca  
    13001300} 
    13011301 
    1302 static int collectd_submit(noit_module_t *self, noit_check_t *check) { 
     1302static int collectd_submit(noit_module_t *self, noit_check_t *check, 
     1303                           noit_check_t *cause) { 
    13031304  collectd_closure_t *ccl; 
    13041305  struct timeval duration; 
     
    14711472   * Then we can warn people if no stats where written in a period of time 
    14721473   */ 
    1473   INITIATE_CHECK(collectd_submit, self, check); 
     1474  INITIATE_CHECK(collectd_submit, self, check, cause); 
    14741475  return 0; 
    14751476} 
  • src/modules/dns.c

    rb8cf70c rf91ddca  
    596596} 
    597597 
    598 static int dns_check_send(noit_module_t *self, noit_check_t *check) { 
     598static int dns_check_send(noit_module_t *self, noit_check_t *check, 
     599                          noit_check_t *cause) { 
    599600  void *vnv_pair = NULL; 
    600601  struct dns_nameval *nv_pair; 
     
    758759  ci->check = check; 
    759760  ci->self = self; 
    760   INITIATE_CHECK(dns_check_send, self, check); 
     761  INITIATE_CHECK(dns_check_send, self, check, cause); 
    761762  return 0; 
    762763} 
  • src/modules/external.c

    r9679460 rf91ddca  
    443443  return 0; 
    444444} 
    445 static int external_invoke(noit_module_t *self, noit_check_t *check) { 
     445static int external_invoke(noit_module_t *self, noit_check_t *check, 
     446                           noit_check_t *cause) { 
    446447  struct timeval when, p_int; 
    447448  external_closure_t *ecl; 
     
    593594                                    int once, noit_check_t *cause) { 
    594595  if(!check->closure) check->closure = calloc(1, sizeof(struct check_info)); 
    595   INITIATE_CHECK(external_invoke, self, check); 
     596  INITIATE_CHECK(external_invoke, self, check, cause); 
    596597  return 0; 
    597598} 
  • src/modules/httptrap.c

    r659d7f7 rf91ddca  
    146146} 
    147147 
    148 static int httptrap_submit(noit_module_t *self, noit_check_t *check) { 
     148static int httptrap_submit(noit_module_t *self, noit_check_t *check, 
     149                           noit_check_t *cause) { 
    149150  httptrap_closure_t *ccl; 
    150151  struct timeval duration; 
     
    382383    ccl->self = self; 
    383384  } 
    384   INITIATE_CHECK(httptrap_submit, self, check); 
     385  INITIATE_CHECK(httptrap_submit, self, check, cause); 
    385386  return 0; 
    386387} 
  • src/modules/lua.c

    r87e8a7c re437d46  
    249249} 
    250250static int 
     251noit_lua_get_available(lua_State *L) { 
     252  char av[2] = { '\0', '\0' }; 
     253  noit_check_t *check; 
     254  noit_lua_check_info_t *ci; 
     255  if(lua_gettop(L)) luaL_error(L, "wrong number of arguments"); 
     256  check = lua_touserdata(L, lua_upvalueindex(1)); 
     257  av[0] = (char)check->stats.current.available; 
     258  lua_pushstring(L, av); 
     259  return 1; 
     260} 
     261static int 
    251262noit_lua_set_available(lua_State *L) { 
    252263  noit_check_t *check; 
     
    257268  ci->current.available = lua_tointeger(L, lua_upvalueindex(2)); 
    258269  return 0; 
     270} 
     271static int 
     272noit_lua_get_state(lua_State *L) { 
     273  char status[2] = { '\0', '\0' }; 
     274  noit_check_t *check; 
     275  noit_lua_check_info_t *ci; 
     276  if(lua_gettop(L)) luaL_error(L, "wrong number of arguments"); 
     277  check = lua_touserdata(L, lua_upvalueindex(1)); 
     278  status[0] = (char)check->stats.current.state; 
     279  lua_pushstring(L, status); 
     280  return 1; 
    259281} 
    260282static int 
     
    373395        lua_pushcclosure(L, noit_lua_set_available, 2); 
    374396      } 
     397      else if(!strcmp(k, "availability")) { 
     398        lua_pushlightuserdata(L, check); 
     399        lua_pushcclosure(L, noit_lua_get_available, 1); 
     400      } 
    375401      else break; 
    376402      return 1; 
     
    423449      return 1; 
    424450    case 's': 
    425       if(!strcmp(k, "status")) { 
     451      if(!strcmp(k, "state")) { 
     452        lua_pushlightuserdata(L, check); 
     453        lua_pushcclosure(L, noit_lua_get_state, 1); 
     454      } 
     455      else if(!strcmp(k, "status")) { 
    426456        lua_pushlightuserdata(L, check); 
    427457        lua_pushcclosure(L, noit_lua_set_status, 1); 
     
    612642  ci->current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; 
    613643 
    614   noit_check_set_stats(self, check, &ci->current); 
     644  /* Only set out stats/log if someone has actually performed a check */ 
     645  if(ci->current.state != NP_UNKNOWN || 
     646     ci->current.available != NP_UNKNOWN) 
     647    noit_check_set_stats(self, check, &ci->current); 
    615648  free(ci->current.status); 
    616649} 
     
    705738} 
    706739static int 
    707 noit_lua_initiate(noit_module_t *self, noit_check_t *check) { 
     740noit_lua_initiate(noit_module_t *self, noit_check_t *check, 
     741                  noit_check_t *cause) { 
    708742  LMC_DECL(L, self); 
    709743  struct nl_intcl *int_cl; 
     
    721755  ci->self = self; 
    722756  ci->check = check; 
     757  ci->cause = cause; 
    723758  noit_check_stats_clear(&ci->current); 
    724759 
     
    753788  noit_lua_setup_module(ci->coro_state, ci->self); 
    754789  noit_lua_setup_check(ci->coro_state, ci->check); 
    755   noit_lua_resume(ci, 2); 
     790  if(cause) noit_lua_setup_check(ci->coro_state, ci->cause); 
     791  else lua_pushnil(L); 
     792  noit_lua_resume(ci, 3); 
    756793 
    757794  return 0; 
     
    768805                               int once, noit_check_t *cause) { 
    769806  if(!check->closure) check->closure = calloc(1, sizeof(noit_lua_check_info_t)); 
    770   INITIATE_CHECK(noit_lua_initiate, self, check); 
     807  INITIATE_CHECK(noit_lua_initiate, self, check, cause); 
    771808  return 0; 
    772809} 
  • src/modules/lua_noit.h

    ra719cb6 rf91ddca  
    5757  noit_module_t *self; 
    5858  noit_check_t *check; 
     59  noit_check_t *cause; 
    5960  int timed_out; 
    6061  eventer_t timeout_event; 
  • src/modules/mysql.c

    r45f2d70 r8b4fa37  
    354354} 
    355355 
    356 static int mysql_initiate(noit_module_t *self, noit_check_t *check) { 
     356static int mysql_initiate(noit_module_t *self, noit_check_t *check, 
     357                          noit_check_t *cause) { 
    357358  mysql_check_info_t *ci = check->closure; 
    358359  struct timeval __now; 
     
    377378 
    378379static int mysql_initiate_check(noit_module_t *self, noit_check_t *check, 
    379                                    int once, noit_check_t *parent) { 
     380                                   int once, noit_check_t *cause) { 
    380381  if(!check->closure) check->closure = calloc(1, sizeof(mysql_check_info_t)); 
    381   INITIATE_CHECK(mysql_initiate, self, check); 
     382  INITIATE_CHECK(mysql_initiate, self, check, cause); 
    382383  return 0; 
    383384} 
  • src/modules/ping_icmp.c

    r25cb63a rf91ddca  
    500500  } 
    501501} 
    502 static int ping_icmp_send(noit_module_t *self, noit_check_t *check) { 
     502static int ping_icmp_send(noit_module_t *self, noit_check_t *check, 
     503                          noit_check_t *cause) { 
    503504  struct timeval when, p_int; 
    504505  struct ping_payload *payload; 
     
    626627                                    int once, noit_check_t *cause) { 
    627628  if(!check->closure) check->closure = calloc(1, sizeof(struct check_info)); 
    628   INITIATE_CHECK(ping_icmp_send, self, check); 
     629  INITIATE_CHECK(ping_icmp_send, self, check, cause); 
    629630  return 0; 
    630631} 
  • src/modules/postgres.c

    rd8c3f54 rf91ddca  
    287287} 
    288288 
    289 static int postgres_initiate(noit_module_t *self, noit_check_t *check) { 
     289static int postgres_initiate(noit_module_t *self, noit_check_t *check, 
     290                             noit_check_t *cause) { 
    290291  postgres_check_info_t *ci = check->closure; 
    291292  struct timeval __now; 
     
    310311 
    311312static int postgres_initiate_check(noit_module_t *self, noit_check_t *check, 
    312                                    int once, noit_check_t *parent) { 
     313                                   int once, noit_check_t *cause) { 
    313314  if(!check->closure) check->closure = calloc(1, sizeof(postgres_check_info_t)); 
    314   INITIATE_CHECK(postgres_initiate, self, check); 
     315  INITIATE_CHECK(postgres_initiate, self, check, cause); 
    315316  return 0; 
    316317} 
  • src/modules/postgres_ingestor.c

    r4a653ea rd390b7a  
    14601460  size = pathconf(path, _PC_NAME_MAX); 
    14611461#endif 
    1462   size = MIN(size, PATH_MAX + 128); 
     1462  size = MAX(size, PATH_MAX + 128); 
    14631463  de = alloca(size); 
    14641464  root = opendir(path); 
  • src/modules/selfcheck.c

    rcc25c43 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); 
     
    161186} 
    162187 
    163 static int selfcheck_initiate(noit_module_t *self, noit_check_t *check) { 
     188static int selfcheck_initiate(noit_module_t *self, noit_check_t *check, 
     189                              noit_check_t *cause) { 
    164190  selfcheck_info_t *ci = check->closure; 
    165191  struct timeval __now; 
     
    183209 
    184210static int selfcheck_initiate_check(noit_module_t *self, noit_check_t *check, 
    185                                    int once, noit_check_t *parent) { 
     211                                   int once, noit_check_t *cause) { 
    186212  if(!check->closure) check->closure = calloc(1, sizeof(selfcheck_info_t)); 
    187   INITIATE_CHECK(selfcheck_initiate, self, check); 
     213  INITIATE_CHECK(selfcheck_initiate, self, check, cause); 
    188214  return 0; 
    189215} 
  • src/modules/snmp.c

    rb553f9a rf91ddca  
    876876  return info->noids; 
    877877} 
    878 static int noit_snmp_send(noit_module_t *self, noit_check_t *check) { 
     878static int noit_snmp_send(noit_module_t *self, noit_check_t *check, 
     879                          noit_check_t *cause) { 
    879880  struct snmp_pdu *req; 
    880881  struct target_session *ts; 
     
    958959                                    int once, noit_check_t *cause) { 
    959960  if(!check->closure) check->closure = calloc(1, sizeof(struct check_info)); 
    960   INITIATE_CHECK(noit_snmp_send, self, check); 
     961  INITIATE_CHECK(noit_snmp_send, self, check, cause); 
    961962  return 0; 
    962963} 
  • src/modules/ssh2.c

    rb553f9a rf91ddca  
    277277  return 0; 
    278278} 
    279 static int ssh2_initiate(noit_module_t *self, noit_check_t *check) { 
     279static int ssh2_initiate(noit_module_t *self, noit_check_t *check, 
     280                         noit_check_t *cause) { 
    280281  ssh2_check_info_t *ci = check->closure; 
    281282  struct timeval p_int, __now; 
     
    385386 
    386387static int ssh2_initiate_check(noit_module_t *self, noit_check_t *check, 
    387                                int once, noit_check_t *parent) { 
     388                               int once, noit_check_t *cause) { 
    388389  if(!check->closure) check->closure = calloc(1, sizeof(ssh2_check_info_t)); 
    389   INITIATE_CHECK(ssh2_initiate, self, check); 
     390  INITIATE_CHECK(ssh2_initiate, self, check, cause); 
    390391  return 0; 
    391392} 
  • src/modules/test_abort.c

    r1a778bd rf91ddca  
    152152} 
    153153 
    154 static int test_abort_initiate(noit_module_t *self, noit_check_t *check) { 
     154static int test_abort_initiate(noit_module_t *self, noit_check_t *check, 
     155                               noit_check_t *cause) { 
    155156  test_abort_check_info_t *ci = check->closure; 
    156157  struct timeval __now; 
     
    188189 
    189190static int test_abort_initiate_check(noit_module_t *self, noit_check_t *check, 
    190                                    int once, noit_check_t *parent) { 
     191                                   int once, noit_check_t *cause) { 
    191192  if(!check->closure) check->closure = calloc(1, sizeof(test_abort_check_info_t)); 
    192   INITIATE_CHECK(test_abort_initiate, self, check); 
     193  INITIATE_CHECK(test_abort_initiate, self, check, cause); 
    193194  return 0; 
    194195} 
  • src/noit_check.c

    r832c60c rf207009  
    122122  if(start_offset_ms == -1) 
    123123    start_offset_ms = drand48() * noit_check_max_initial_stutter(); 
    124   if(!(check->flags & NP_TRANSIENT)) { 
     124  if(!(check->flags & NP_TRANSIENT) && check->period) { 
    125125    max = noit_check_max_initial_stutter(); 
    126126    offset = start_offset_ms + drand48() * 1000; 
     
    337337    if(check->oncheck) { 
    338338      /* This service is causally triggered by another service */ 
     339      uuid_t id; 
    339340      char fullcheck[1024]; 
    340341      char *name = check->oncheck; 
     
    342343 
    343344      noitL(noit_debug, "Searching for upstream trigger on %s\n", name); 
     345      parent = NULL; 
     346      if(uuid_parse(check->oncheck, id) == 0) { 
     347        target = ""; 
     348        parent = noit_poller_lookup(id); 
     349      } 
    344350      if((target = strchr(check->oncheck, '`')) != NULL) { 
    345         strlcpy(fullcheck, check->oncheck, target - check->oncheck); 
     351        strlcpy(fullcheck, check->oncheck, target + 1 - check->oncheck); 
    346352        name = target + 1; 
    347353        target = fullcheck; 
     354        parent = noit_poller_lookup_by_name(target, name); 
    348355      } 
    349       else 
    350        target = check->target; 
    351  
    352       parent = noit_poller_lookup_by_name(target, name); 
     356      else { 
     357        target = check->target; 
     358        parent = noit_poller_lookup_by_name(target, name); 
     359      } 
     360 
    353361      if(!parent) { 
    354362        check->flags |= NP_DISABLED; 
     
    862870} 
    863871 
     872static int 
     873bad_check_initiate(noit_module_t *self, noit_check_t *check, 
     874                   int once, noit_check_t *cause) { 
     875  /* self is likely null here -- why it is bad, in fact */ 
     876  /* this is only suitable to call in one-offs */ 
     877  stats_t current; 
     878  char buff[256]; 
     879  if(!once) return -1; 
     880  if(!check) return -1; 
     881  assert(!(check->flags & NP_RUNNING)); 
     882  check->flags |= NP_RUNNING; 
     883  noit_check_stats_clear(&current); 
     884  gettimeofday(&current.whence, NULL); 
     885  current.duration = 0; 
     886  current.available = NP_UNKNOWN; 
     887  current.state = NP_UNKNOWN; 
     888  snprintf(buff, sizeof(buff), "check[%s] implementation offline", 
     889           check->module); 
     890  current.status = buff; 
     891  noit_check_set_stats(self, check, &current); 
     892  check->flags &= ~NP_RUNNING; 
     893  return 0; 
     894} 
    864895void 
    865896noit_check_stats_clear(stats_t *s) { 
     
    11441175    noit_module_t *mod; 
    11451176    mod = noit_module_lookup(dep->check->module); 
    1146     assert(mod); 
    1147     noitL(noit_debug, "Firing %s`%s in response to %s`%s\n", 
    1148           dep->check->target, dep->check->name, 
    1149           check->target, check->name); 
    1150     if((dep->check->flags & NP_DISABLED) == 0) 
    1151       if(mod->initiate_check) 
    1152         mod->initiate_check(mod, dep->check, 1, check); 
     1177    if(!mod) { 
     1178      bad_check_initiate(mod, dep->check, 1, check); 
     1179    } 
     1180    else { 
     1181      noitL(noit_debug, "Firing %s`%s in response to %s`%s\n", 
     1182            dep->check->target, dep->check->name, 
     1183            check->target, check->name); 
     1184      if((dep->check->flags & NP_DISABLED) == 0) 
     1185        if(mod->initiate_check) 
     1186          mod->initiate_check(mod, dep->check, 1, check); 
     1187    } 
    11531188  } 
    11541189} 
  • src/noit_check_tools.c

    rda6e546 rf207009  
    4242  noit_module_t *self; 
    4343  noit_check_t *check; 
     44  noit_check_t *cause; 
    4445  dispatch_func_t dispatch; 
    4546} recur_closure_t; 
     
    5253  noit_check_resolve(rcl->check); 
    5354  noit_check_schedule_next(rcl->self, &e->whence, rcl->check, now, 
    54                            rcl->dispatch); 
     55                           rcl->dispatch, NULL); 
    5556  if(NOIT_CHECK_RESOLVED(rcl->check)) { 
    5657    if(NOIT_CHECK_DISPATCH_ENABLED()) { 
     
    6061                          rcl->check->target); 
    6162    } 
    62     rcl->dispatch(rcl->self, rcl->check); 
     63    rcl->dispatch(rcl->self, rcl->check, rcl->cause); 
    6364  } 
    6465  else 
     
    7273noit_check_schedule_next(noit_module_t *self, 
    7374                         struct timeval *last_check, noit_check_t *check, 
    74                          struct timeval *now, dispatch_func_t dispatch) { 
     75                         struct timeval *now, dispatch_func_t dispatch, 
     76                         noit_check_t *cause) { 
    7577  eventer_t newe; 
    7678  struct timeval period, earliest; 
    7779  recur_closure_t *rcl; 
    7880 
     81  assert(cause == NULL); 
    7982  assert(check->fire_event == NULL); 
    8083  if(check->period == 0) return 0; 
     
    112115  rcl->self = self; 
    113116  rcl->check = check; 
     117  rcl->cause = cause; 
    114118  rcl->dispatch = dispatch; 
    115119  newe->closure = rcl; 
  • src/noit_check_tools.h

    r09ecd28 rf91ddca  
    4141#include "noit_check_tools_shared.h" 
    4242 
    43 typedef int (*dispatch_func_t)(noit_module_t *, noit_check_t *); 
     43typedef int (*dispatch_func_t)(noit_module_t *, noit_check_t *, 
     44                               noit_check_t *); 
    4445 
    4546API_EXPORT(void) 
     
    4950  noit_check_schedule_next(noit_module_t *self, 
    5051                           struct timeval *last_check, noit_check_t *check, 
    51                            struct timeval *now, dispatch_func_t recur); 
     52                           struct timeval *now, dispatch_func_t recur, 
     53                           noit_check_t *cause); 
    5254 
    5355API_EXPORT(void) 
     
    5759  noit_check_run_full_asynch(noit_check_t *check, eventer_func_t callback); 
    5860 
    59 #define INITIATE_CHECK(func, self, check) do { \ 
     61#define INITIATE_CHECK(func, self, check, cause) do { \ 
    6062  if(once) { \ 
    61     func(self, check); \ 
     63    func(self, check, cause); \ 
    6264  } \ 
    6365  else if(!check->fire_event) { \ 
    6466    struct timeval epoch = { 0L, 0L }; \ 
    6567    noit_check_fake_last_check(check, &epoch, NULL); \ 
    66     noit_check_schedule_next(self, &epoch, check, NULL, func); \ 
     68    noit_check_schedule_next(self, &epoch, check, NULL, func, cause); \ 
    6769  } \ 
    6870} while(0) 
  • src/noit_conf_checks.c

    rb553f9a r30b3841  
    384384} 
    385385static int 
     386_qsort_string_compare(const void *i1, const void *i2) { 
     387        const char *s1 = ((const char **)i1)[0]; 
     388        const char *s2 = ((const char **)i2)[0]; 
     389        return strcasecmp(s1, s2); 
     390} 
     391static int 
    386392noit_console_show_check(noit_console_closure_t ncct, 
    387393                        int argc, char **argv, 
     
    488494      else { 
    489495        stats_t *c = &check->stats.current; 
     496        int mcount=0; 
     497        const char **sorted_keys; 
     498        char buff[256]; 
    490499        struct timeval now, diff; 
     500        noit_boolean filtered; 
     501 
    491502        gettimeofday(&now, NULL); 
    492503        sub_timeval(now, c->whence, &diff); 
     
    499510        nc_printf(ncct, " metrics:\n"); 
    500511        memset(&iter, 0, sizeof(iter)); 
     512        sorted_keys = alloca(c->metrics.size * sizeof(*sorted_keys)); 
    501513        while(noit_hash_next(&c->metrics, &iter, &k, &klen, &data)) { 
    502           char buff[256]; 
    503           noit_boolean filtered; 
    504           noit_stats_snprint_metric(buff, sizeof(buff), (metric_t *)data); 
    505           filtered = !noit_apply_filterset(check->filterset, check, (metric_t *)data); 
    506           nc_printf(ncct, "  %c%s\n", filtered ? '*' : ' ', buff); 
     514          if(sorted_keys) sorted_keys[mcount++] = k; 
     515          else { 
     516            noit_stats_snprint_metric(buff, sizeof(buff), (metric_t *)data); 
     517            filtered = !noit_apply_filterset(check->filterset, check, (metric_t *)data); 
     518            nc_printf(ncct, "  %c%s\n", filtered ? '*' : ' ', buff); 
     519          } 
     520        } 
     521        if(sorted_keys) { 
     522          int j; 
     523          qsort(sorted_keys, mcount, sizeof(*sorted_keys), 
     524                _qsort_string_compare); 
     525          for(j=0;j<mcount;j++) { 
     526            if(noit_hash_retrieve(&c->metrics, 
     527                                  sorted_keys[j], strlen(sorted_keys[j]), 
     528                                  &data)) { 
     529              noit_stats_snprint_metric(buff, sizeof(buff), (metric_t *)data); 
     530              filtered = !noit_apply_filterset(check->filterset, check, (metric_t *)data); 
     531              nc_printf(ncct, "  %c%s\n", filtered ? '*' : ' ', buff); 
     532            } 
     533          } 
    507534        } 
    508535      } 
  • 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 
  • src/utils/noit_log.c

    rc3852a0 r6c8c525  
    436436  return 0; 
    437437} 
     438static void 
     439noit_log_jlog_err(void *ctx, const char *format, ...) { 
     440  int rv; 
     441  struct timeval now; 
     442  va_list arg; 
     443  va_start(arg, format); 
     444  gettimeofday(&now, NULL); 
     445  rv = noit_vlog(noit_error, &now, "jlog.c", 0, format, arg); 
     446  va_end(arg); 
     447} 
    438448static int 
    439449jlog_logio_open(noit_log_stream_t ls) { 
     
    447457  log = jlog_new(path); 
    448458  if(!log) return -1; 
     459  jlog_set_error_func(log, noit_log_jlog_err, ls); 
    449460  /* Open the writer. */ 
    450461  if(jlog_ctx_open_writer(log)) { 
     
    454465    jlog_ctx_close(log); 
    455466    log = jlog_new(path); 
     467    jlog_set_error_func(log, noit_log_jlog_err, ls); 
    456468    if(jlog_ctx_init(log)) { 
    457469      noitL(noit_error, "Cannot init jlog writer: %s\n", 
     
    463475    jlog_ctx_close(log); 
    464476    log = jlog_new(path); 
     477    jlog_set_error_func(log, noit_log_jlog_err, ls); 
    465478    if(jlog_ctx_open_writer(log)) { 
    466479      noitL(noit_error, "Cannot open jlog writer: %s\n",