Changeset f207009593817c50a5fb4fd4e75cbdc4c79dcfcc
- Timestamp:
- 08/15/11 19:36:52 (2 years ago)
- git-parent:
[93c0f7d278d008139c3282dbbff1ed58c15d8dfa], [633221873749ec0a7b4c5550e3aed3c991ec5126]
- Files:
-
- .gitignore (modified) (1 diff)
- src/jlog/jlog_io.c (modified) (1 diff)
- src/modules-lua/noit/module/jezebel.lua (modified) (1 diff)
- src/modules/collectd.c (modified) (2 diffs)
- src/modules/dns.c (modified) (2 diffs)
- src/modules/external.c (modified) (2 diffs)
- src/modules/httptrap.c (modified) (2 diffs)
- src/modules/lua.c (modified) (9 diffs)
- src/modules/lua_noit.h (modified) (1 diff)
- src/modules/mysql.c (modified) (2 diffs)
- src/modules/ping_icmp.c (modified) (2 diffs)
- src/modules/postgres.c (modified) (2 diffs)
- src/modules/postgres_ingestor.c (modified) (1 diff)
- src/modules/selfcheck.c (modified) (5 diffs)
- src/modules/snmp.c (modified) (2 diffs)
- src/modules/ssh2.c (modified) (2 diffs)
- src/modules/test_abort.c (modified) (2 diffs)
- src/noit_check.c (modified) (5 diffs)
- src/noit_check_tools.c (modified) (5 diffs)
- src/noit_check_tools.h (modified) (3 diffs)
- src/noit_conf_checks.c (modified) (3 diffs)
- src/noit_jlog_listener.c (modified) (6 diffs)
- src/noit_jlog_listener.h (modified) (2 diffs)
- src/utils/noit_log.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
.gitignore
r574a39b r7b99984 12 12 Makefile 13 13 sql/reconnoiter_ddl_dump.sql 14 src/*.dSYM 14 15 src/lua/src/lua 16 src/modules/*.dSYM 15 17 src/noit_version.h 16 18 src/noitd src/jlog/jlog_io.c
re153d26 rb394de2 236 236 { 237 237 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; 240 241 return sb.st_size; 241 242 } src/modules-lua/noit/module/jezebel.lua
rb553f9a r6b499c5 161 161 local doc = noit.parsexml(output) 162 162 if doc == nil then 163 noit.log(" error", "bad xml: %s\n", output)163 noit.log("debug", "bad xml: %s\n", output) 164 164 check.status("bad xml from jezebel") 165 165 return src/modules/collectd.c
rb8cf70c rf91ddca 1300 1300 } 1301 1301 1302 static int collectd_submit(noit_module_t *self, noit_check_t *check) { 1302 static int collectd_submit(noit_module_t *self, noit_check_t *check, 1303 noit_check_t *cause) { 1303 1304 collectd_closure_t *ccl; 1304 1305 struct timeval duration; … … 1471 1472 * Then we can warn people if no stats where written in a period of time 1472 1473 */ 1473 INITIATE_CHECK(collectd_submit, self, check );1474 INITIATE_CHECK(collectd_submit, self, check, cause); 1474 1475 return 0; 1475 1476 } src/modules/dns.c
rb8cf70c rf91ddca 596 596 } 597 597 598 static int dns_check_send(noit_module_t *self, noit_check_t *check) { 598 static int dns_check_send(noit_module_t *self, noit_check_t *check, 599 noit_check_t *cause) { 599 600 void *vnv_pair = NULL; 600 601 struct dns_nameval *nv_pair; … … 758 759 ci->check = check; 759 760 ci->self = self; 760 INITIATE_CHECK(dns_check_send, self, check );761 INITIATE_CHECK(dns_check_send, self, check, cause); 761 762 return 0; 762 763 } src/modules/external.c
r9679460 rf91ddca 443 443 return 0; 444 444 } 445 static int external_invoke(noit_module_t *self, noit_check_t *check) { 445 static int external_invoke(noit_module_t *self, noit_check_t *check, 446 noit_check_t *cause) { 446 447 struct timeval when, p_int; 447 448 external_closure_t *ecl; … … 593 594 int once, noit_check_t *cause) { 594 595 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); 596 597 return 0; 597 598 } src/modules/httptrap.c
r659d7f7 rf91ddca 146 146 } 147 147 148 static int httptrap_submit(noit_module_t *self, noit_check_t *check) { 148 static int httptrap_submit(noit_module_t *self, noit_check_t *check, 149 noit_check_t *cause) { 149 150 httptrap_closure_t *ccl; 150 151 struct timeval duration; … … 382 383 ccl->self = self; 383 384 } 384 INITIATE_CHECK(httptrap_submit, self, check );385 INITIATE_CHECK(httptrap_submit, self, check, cause); 385 386 return 0; 386 387 } src/modules/lua.c
r87e8a7c re437d46 249 249 } 250 250 static int 251 noit_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 } 261 static int 251 262 noit_lua_set_available(lua_State *L) { 252 263 noit_check_t *check; … … 257 268 ci->current.available = lua_tointeger(L, lua_upvalueindex(2)); 258 269 return 0; 270 } 271 static int 272 noit_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; 259 281 } 260 282 static int … … 373 395 lua_pushcclosure(L, noit_lua_set_available, 2); 374 396 } 397 else if(!strcmp(k, "availability")) { 398 lua_pushlightuserdata(L, check); 399 lua_pushcclosure(L, noit_lua_get_available, 1); 400 } 375 401 else break; 376 402 return 1; … … 423 449 return 1; 424 450 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")) { 426 456 lua_pushlightuserdata(L, check); 427 457 lua_pushcclosure(L, noit_lua_set_status, 1); … … 612 642 ci->current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; 613 643 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); 615 648 free(ci->current.status); 616 649 } … … 705 738 } 706 739 static int 707 noit_lua_initiate(noit_module_t *self, noit_check_t *check) { 740 noit_lua_initiate(noit_module_t *self, noit_check_t *check, 741 noit_check_t *cause) { 708 742 LMC_DECL(L, self); 709 743 struct nl_intcl *int_cl; … … 721 755 ci->self = self; 722 756 ci->check = check; 757 ci->cause = cause; 723 758 noit_check_stats_clear(&ci->current); 724 759 … … 753 788 noit_lua_setup_module(ci->coro_state, ci->self); 754 789 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); 756 793 757 794 return 0; … … 768 805 int once, noit_check_t *cause) { 769 806 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); 771 808 return 0; 772 809 } src/modules/lua_noit.h
ra719cb6 rf91ddca 57 57 noit_module_t *self; 58 58 noit_check_t *check; 59 noit_check_t *cause; 59 60 int timed_out; 60 61 eventer_t timeout_event; src/modules/mysql.c
r45f2d70 r8b4fa37 354 354 } 355 355 356 static int mysql_initiate(noit_module_t *self, noit_check_t *check) { 356 static int mysql_initiate(noit_module_t *self, noit_check_t *check, 357 noit_check_t *cause) { 357 358 mysql_check_info_t *ci = check->closure; 358 359 struct timeval __now; … … 377 378 378 379 static 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) { 380 381 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); 382 383 return 0; 383 384 } src/modules/ping_icmp.c
r25cb63a rf91ddca 500 500 } 501 501 } 502 static int ping_icmp_send(noit_module_t *self, noit_check_t *check) { 502 static int ping_icmp_send(noit_module_t *self, noit_check_t *check, 503 noit_check_t *cause) { 503 504 struct timeval when, p_int; 504 505 struct ping_payload *payload; … … 626 627 int once, noit_check_t *cause) { 627 628 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); 629 630 return 0; 630 631 } src/modules/postgres.c
rd8c3f54 rf91ddca 287 287 } 288 288 289 static int postgres_initiate(noit_module_t *self, noit_check_t *check) { 289 static int postgres_initiate(noit_module_t *self, noit_check_t *check, 290 noit_check_t *cause) { 290 291 postgres_check_info_t *ci = check->closure; 291 292 struct timeval __now; … … 310 311 311 312 static 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) { 313 314 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); 315 316 return 0; 316 317 } src/modules/postgres_ingestor.c
r4a653ea rd390b7a 1460 1460 size = pathconf(path, _PC_NAME_MAX); 1461 1461 #endif 1462 size = M IN(size, PATH_MAX + 128);1462 size = MAX(size, PATH_MAX + 128); 1463 1463 de = alloca(size); 1464 1464 root = opendir(path); src/modules/selfcheck.c
rcc25c43 r811c412 43 43 #include "noit_check.h" 44 44 #include "noit_check_tools.h" 45 #include "noit_jlog_listener.h" 45 46 #include "utils/noit_log.h" 46 47 #include "utils/noit_hash.h" … … 72 73 snprintf(buffer, sizeof(buffer), "%s_threads", jobq->queue_name); 73 74 noit_stats_set_metric(current, buffer, METRIC_INT32, &s32); 75 } 76 static 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; 74 97 } 75 98 static void selfcheck_log_results(noit_module_t *self, noit_check_t *check) { … … 113 136 u64 = noit_check_completion_count(); 114 137 noit_stats_set_metric(¤t, "checks_run", METRIC_UINT64, &u64); 138 /* feed pull info */ 139 noit_jlog_foreach_feed_stats(selfcheck_feed_details, ¤t); 115 140 116 141 noit_check_set_stats(self, check, ¤t); … … 161 186 } 162 187 163 static int selfcheck_initiate(noit_module_t *self, noit_check_t *check) { 188 static int selfcheck_initiate(noit_module_t *self, noit_check_t *check, 189 noit_check_t *cause) { 164 190 selfcheck_info_t *ci = check->closure; 165 191 struct timeval __now; … … 183 209 184 210 static 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) { 186 212 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); 188 214 return 0; 189 215 } src/modules/snmp.c
rb553f9a rf91ddca 876 876 return info->noids; 877 877 } 878 static int noit_snmp_send(noit_module_t *self, noit_check_t *check) { 878 static int noit_snmp_send(noit_module_t *self, noit_check_t *check, 879 noit_check_t *cause) { 879 880 struct snmp_pdu *req; 880 881 struct target_session *ts; … … 958 959 int once, noit_check_t *cause) { 959 960 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); 961 962 return 0; 962 963 } src/modules/ssh2.c
rb553f9a rf91ddca 277 277 return 0; 278 278 } 279 static int ssh2_initiate(noit_module_t *self, noit_check_t *check) { 279 static int ssh2_initiate(noit_module_t *self, noit_check_t *check, 280 noit_check_t *cause) { 280 281 ssh2_check_info_t *ci = check->closure; 281 282 struct timeval p_int, __now; … … 385 386 386 387 static 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) { 388 389 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); 390 391 return 0; 391 392 } src/modules/test_abort.c
r1a778bd rf91ddca 152 152 } 153 153 154 static int test_abort_initiate(noit_module_t *self, noit_check_t *check) { 154 static int test_abort_initiate(noit_module_t *self, noit_check_t *check, 155 noit_check_t *cause) { 155 156 test_abort_check_info_t *ci = check->closure; 156 157 struct timeval __now; … … 188 189 189 190 static 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) { 191 192 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); 193 194 return 0; 194 195 } src/noit_check.c
r832c60c rf207009 122 122 if(start_offset_ms == -1) 123 123 start_offset_ms = drand48() * noit_check_max_initial_stutter(); 124 if(!(check->flags & NP_TRANSIENT) ) {124 if(!(check->flags & NP_TRANSIENT) && check->period) { 125 125 max = noit_check_max_initial_stutter(); 126 126 offset = start_offset_ms + drand48() * 1000; … … 337 337 if(check->oncheck) { 338 338 /* This service is causally triggered by another service */ 339 uuid_t id; 339 340 char fullcheck[1024]; 340 341 char *name = check->oncheck; … … 342 343 343 344 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 } 344 350 if((target = strchr(check->oncheck, '`')) != NULL) { 345 strlcpy(fullcheck, check->oncheck, target - check->oncheck);351 strlcpy(fullcheck, check->oncheck, target + 1 - check->oncheck); 346 352 name = target + 1; 347 353 target = fullcheck; 354 parent = noit_poller_lookup_by_name(target, name); 348 355 } 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 353 361 if(!parent) { 354 362 check->flags |= NP_DISABLED; … … 862 870 } 863 871 872 static int 873 bad_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(¤t); 884 gettimeofday(¤t.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, ¤t); 892 check->flags &= ~NP_RUNNING; 893 return 0; 894 } 864 895 void 865 896 noit_check_stats_clear(stats_t *s) { … … 1144 1175 noit_module_t *mod; 1145 1176 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 } 1153 1188 } 1154 1189 } src/noit_check_tools.c
rda6e546 rf207009 42 42 noit_module_t *self; 43 43 noit_check_t *check; 44 noit_check_t *cause; 44 45 dispatch_func_t dispatch; 45 46 } recur_closure_t; … … 52 53 noit_check_resolve(rcl->check); 53 54 noit_check_schedule_next(rcl->self, &e->whence, rcl->check, now, 54 rcl->dispatch );55 rcl->dispatch, NULL); 55 56 if(NOIT_CHECK_RESOLVED(rcl->check)) { 56 57 if(NOIT_CHECK_DISPATCH_ENABLED()) { … … 60 61 rcl->check->target); 61 62 } 62 rcl->dispatch(rcl->self, rcl->check );63 rcl->dispatch(rcl->self, rcl->check, rcl->cause); 63 64 } 64 65 else … … 72 73 noit_check_schedule_next(noit_module_t *self, 73 74 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) { 75 77 eventer_t newe; 76 78 struct timeval period, earliest; 77 79 recur_closure_t *rcl; 78 80 81 assert(cause == NULL); 79 82 assert(check->fire_event == NULL); 80 83 if(check->period == 0) return 0; … … 112 115 rcl->self = self; 113 116 rcl->check = check; 117 rcl->cause = cause; 114 118 rcl->dispatch = dispatch; 115 119 newe->closure = rcl; src/noit_check_tools.h
r09ecd28 rf91ddca 41 41 #include "noit_check_tools_shared.h" 42 42 43 typedef int (*dispatch_func_t)(noit_module_t *, noit_check_t *); 43 typedef int (*dispatch_func_t)(noit_module_t *, noit_check_t *, 44 noit_check_t *); 44 45 45 46 API_EXPORT(void) … … 49 50 noit_check_schedule_next(noit_module_t *self, 50 51 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); 52 54 53 55 API_EXPORT(void) … … 57 59 noit_check_run_full_asynch(noit_check_t *check, eventer_func_t callback); 58 60 59 #define INITIATE_CHECK(func, self, check ) do { \61 #define INITIATE_CHECK(func, self, check, cause) do { \ 60 62 if(once) { \ 61 func(self, check ); \63 func(self, check, cause); \ 62 64 } \ 63 65 else if(!check->fire_event) { \ 64 66 struct timeval epoch = { 0L, 0L }; \ 65 67 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); \ 67 69 } \ 68 70 } while(0) src/noit_conf_checks.c
rb553f9a r30b3841 384 384 } 385 385 static 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 } 391 static int 386 392 noit_console_show_check(noit_console_closure_t ncct, 387 393 int argc, char **argv, … … 488 494 else { 489 495 stats_t *c = &check->stats.current; 496 int mcount=0; 497 const char **sorted_keys; 498 char buff[256]; 490 499 struct timeval now, diff; 500 noit_boolean filtered; 501 491 502 gettimeofday(&now, NULL); 492 503 sub_timeval(now, c->whence, &diff); … … 499 510 nc_printf(ncct, " metrics:\n"); 500 511 memset(&iter, 0, sizeof(iter)); 512 sorted_keys = alloca(c->metrics.size * sizeof(*sorted_keys)); 501 513 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 } 507 534 } 508 535 } src/noit_jlog_listener.c
r8fc8902 r811c412 65 65 jlog_id start; 66 66 jlog_id finish; 67 jlog_feed_stats_t *feed_stats; 67 68 int count; 68 69 int wants_shutdown; … … 89 90 } 90 91 92 static noit_hash_table feed_stats = NOIT_HASH_EMPTY; 93 94 jlog_feed_stats_t * 95 noit_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 } 105 int 106 noit_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 } 91 117 static int 92 118 __safe_Ewrite(eventer_t e, void *b, int l, int *mask) { … … 214 240 goto alldone; 215 241 } 242 gettimeofday(&jcl->feed_stats->last_checkpoint, NULL); 216 243 jlog_ctx_read_checkpoint(jcl->jlog, &jcl->chkpt); 217 244 } … … 242 269 alldone: 243 270 e->opset->close(e->fd, &mask, e); 271 noit_atomic_dec32(&jcl->feed_stats->connections); 244 272 if(jcl) noit_jlog_closure_free(jcl); 245 273 if(ac) acceptor_closure_free(ac); … … 310 338 } 311 339 strlcpy(subscriber, ac->remote_cn, sizeof(subscriber)); 340 jcl->feed_stats = noit_jlog_feed_stats(subscriber); 312 341 } 313 342 else { 343 jcl->feed_stats = noit_jlog_feed_stats("~"); 314 344 snprintf(subscriber, sizeof(subscriber), 315 345 "~%07d", noit_atomic_inc32(&tmpfeedcounter)); … … 354 384 pthread_attr_init(&tattr); 355 385 pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); 386 gettimeofday(&jcl->feed_stats->last_connection, NULL); 387 noit_atomic_inc32(&jcl->feed_stats->connections); 356 388 if(pthread_create(&tid, &tattr, noit_jlog_thread_main, newe) == 0) { 357 389 return 0; src/noit_jlog_listener.h
r88a7178 r811c412 40 40 #define NOIT_JLOG_DATA_TEMP_FEED 0x7e66feed 41 41 42 typedef 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 42 49 API_EXPORT(void) 43 50 noit_jlog_listener_init(void); … … 47 54 struct timeval *now); 48 55 56 /* This API call is only safe from the eventer thread */ 57 API_EXPORT(jlog_feed_stats_t *) 58 noit_jlog_feed_stats(const char *sub); 59 60 API_EXPORT(int) 61 noit_jlog_foreach_feed_stats(int (*f)(jlog_feed_stats_t *, void *), 62 void *); 63 49 64 #endif src/utils/noit_log.c
rc3852a0 r6c8c525 436 436 return 0; 437 437 } 438 static void 439 noit_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 } 438 448 static int 439 449 jlog_logio_open(noit_log_stream_t ls) { … … 447 457 log = jlog_new(path); 448 458 if(!log) return -1; 459 jlog_set_error_func(log, noit_log_jlog_err, ls); 449 460 /* Open the writer. */ 450 461 if(jlog_ctx_open_writer(log)) { … … 454 465 jlog_ctx_close(log); 455 466 log = jlog_new(path); 467 jlog_set_error_func(log, noit_log_jlog_err, ls); 456 468 if(jlog_ctx_init(log)) { 457 469 noitL(noit_error, "Cannot init jlog writer: %s\n", … … 463 475 jlog_ctx_close(log); 464 476 log = jlog_new(path); 477 jlog_set_error_func(log, noit_log_jlog_err, ls); 465 478 if(jlog_ctx_open_writer(log)) { 466 479 noitL(noit_error, "Cannot open jlog writer: %s\n",
