Changeset 8c720f9a4bd5979520e9c7ec00d9bea8d305391b
- Timestamp:
- 12/08/10 05:31:12 (2 years ago)
- git-parent:
- Files:
-
- src/Makefile.in (modified) (1 diff)
- src/java/com/omniti/reconnoiter/event/NoitCheck.java (modified) (1 diff)
- src/java/com/omniti/reconnoiter/event/NoitEvent.java (modified) (1 diff)
- src/java/com/omniti/reconnoiter/event/NoitMetricNumeric.java (modified) (3 diffs)
- src/java/com/omniti/reconnoiter/event/NoitMetricText.java (modified) (3 diffs)
- src/java/com/omniti/reconnoiter/event/NoitStatus.java (modified) (3 diffs)
- src/noit.conf.in (modified) (1 diff)
- src/noit_check.c (modified) (1 diff)
- src/noit_check.h (modified) (2 diffs)
- src/noit_check_log.c (modified) (5 diffs)
- src/noit_check_tools.c (modified) (1 diff)
- src/noit_check_tools.h (modified) (1 diff)
- src/noit_conf.c (modified) (1 diff)
- src/stratcon_datastore.c (modified) (5 diffs)
- src/stratcon_realtime_http.c (modified) (4 diffs)
- src/utils/noit_log.c (modified) (1 diff)
- src/utils/noit_log.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/Makefile.in
r5fbae1c r8c720f9 76 76 noit_console_complete.o noit_xml.o \ 77 77 noit_conf.o noit_http.o noit_rest.o noit_tokenizer.o \ 78 noit_capabilities_listener.o noit_module.o \78 noit_capabilities_listener.o noit_module.o noit_check_tools.o \ 79 79 stratcon_realtime_http.o \ 80 80 stratcon_jlog_streamer.o stratcon_datastore.o \ src/java/com/omniti/reconnoiter/event/NoitCheck.java
r54eb3fe r8c720f9 29 29 public NoitCheck(String[] parts) throws Exception { 30 30 super(parts); 31 String id[] = extended_id_split(parts[3]); 31 32 noit = parts[1]; 32 uuid = parts[3];33 uuid = id[3]; 33 34 target = parts[4]; 34 35 module = parts[5]; src/java/com/omniti/reconnoiter/event/NoitEvent.java
r54eb3fe r8c720f9 17 17 super(parts); 18 18 } 19 public String[] extended_id_split(String id) { 20 String parts[] = { null, null, null, null }; /* target,module,name,uuid */ 21 if(id.length() <= 36) { 22 parts[3] = id; 23 return parts; 24 } 25 parts[3] = id.substring(id.length() - 36); 26 int p1 = id.indexOf('`'); 27 if(p1 < 0) return parts; 28 parts[0] = id.substring(0,p1); 29 int p2 = id.indexOf('`', p1+1); 30 if(p2 < 0) return parts; 31 parts[1] = id.substring(p1+1,p2); 32 parts[2] = id.substring(p2+1,id.length()-37); 33 return parts; 34 } 19 35 public void handle(EventHandler eh) { 20 36 eh.getService().getEPRuntime().sendEvent(this); src/java/com/omniti/reconnoiter/event/NoitMetricNumeric.java
r5cffd17 r8c720f9 13 13 public class NoitMetricNumeric extends NoitEvent { 14 14 private String uuid; 15 private String check_target; 16 private String check_module; 17 private String check_name; 15 18 private String name; 16 19 private long time; … … 27 30 public NoitMetricNumeric(String[] parts) throws Exception { 28 31 super(parts); 32 String id[] = extended_id_split(parts[3]); 29 33 noit = parts[1]; 30 34 time = timeToLong(parts[2]); 31 uuid = parts[3]; 35 check_target = id[0]; 36 check_module = id[1]; 37 check_name = id[2]; 38 uuid = id[3]; 32 39 name = parts[4]; 33 40 value = null; … … 46 53 public Double getValue() { return value; } 47 54 public String getNoit() { return noit; } 55 public String getCheck_target() { return check_target; } 56 public String getCheck_module() { return check_module; } 57 public String getCheck_name() { return check_name; } 48 58 49 59 public int getLength() { src/java/com/omniti/reconnoiter/event/NoitMetricText.java
r54eb3fe r8c720f9 17 17 String message; 18 18 String noit; 19 String check_target; 20 String check_module; 21 String check_name; 19 22 20 23 public String getPrefix() { … … 27 30 public NoitMetricText(String[] parts) throws Exception { 28 31 super(parts); 32 String id[] = extended_id_split(parts[3]); 29 33 noit = parts[1]; 30 uuid = parts[3]; 34 check_target = id[0]; 35 check_module = id[1]; 36 check_name = id[2]; 37 uuid = id[3]; 31 38 name = parts[4]; 32 39 message = parts[6].equals("[[null]]") ? null : parts[6]; … … 38 45 public String getMessage() { return message; } 39 46 public String getNoit() { return noit; } 40 47 public String getCheck_target() { return check_target; } 48 public String getCheck_module() { return check_module; } 49 public String getCheck_name() { return check_name; } 41 50 42 51 public int getLength() { src/java/com/omniti/reconnoiter/event/NoitStatus.java
r54eb3fe r8c720f9 19 19 Double duration; 20 20 String noit; 21 String check_target; 22 String check_module; 23 String check_name; 21 24 22 25 public String getPrefix() { … … 30 33 public NoitStatus(String[] parts) throws Exception { 31 34 super(parts); 35 String id[] = extended_id_split(parts[3]); 32 36 noit = parts[1]; 33 uuid = parts[3]; 37 check_target = id[0]; 38 check_module = id[1]; 39 check_name = id[2]; 40 uuid = id[3]; 34 41 state = parts[4]; 35 42 availability = parts[5]; … … 46 53 public Double getDuration() { return duration; } 47 54 public String getNoit() { return noit; } 55 public String getCheck_target() { return check_target; } 56 public String getCheck_module() { return check_module; } 57 public String getCheck_name() { return check_name; } 48 58 49 59 public int getLength() { src/noit.conf.in
r16e8c85 r8c720f9 47 47 </components> 48 48 <feeds> 49 <config><extended_id>off</extended_id></config> 49 50 <outlet name="feed"/> 50 51 <log name="check"/> src/noit_check.c
r9c846a2 r8c720f9 754 754 } 755 755 756 int 757 noit_check_xpath(char *xpath, int len, 758 const char *base, const char *arg) { 759 uuid_t checkid; 760 int base_trailing_slash; 761 char argcopy[1024], *target, *module, *name; 762 763 base_trailing_slash = (base[strlen(base)-1] == '/'); 764 xpath[0] = '\0'; 765 argcopy[0] = '\0'; 766 if(arg) strlcpy(argcopy, arg, sizeof(argcopy)); 767 768 if(uuid_parse(argcopy, checkid) == 0) { 769 /* If they kill by uuid, we'll seek and destroy -- find it anywhere */ 770 snprintf(xpath, len, "/noit/checks%s%s/check[@uuid=\"%s\"]", 771 base, base_trailing_slash ? "" : "/", argcopy); 772 } 773 else if((module = strchr(argcopy, '`')) != NULL) { 774 noit_check_t *check; 775 char uuid_str[37]; 776 target = argcopy; 777 *module++ = '\0'; 778 if((name = strchr(module+1, '`')) == NULL) 779 name = module; 780 else 781 name++; 782 check = noit_poller_lookup_by_name(target, name); 783 if(!check) { 784 return -1; 785 } 786 uuid_unparse_lower(check->checkid, uuid_str); 787 snprintf(xpath, len, "/noit/checks%s%s/check[@uuid=\"%s\"]", 788 base, base_trailing_slash ? "" : "/", uuid_str); 789 } 790 return strlen(xpath); 791 } 792 756 793 void 757 794 noit_check_stats_clear(stats_t *s) { src/noit_check.h
r95623e8 r8c720f9 200 200 noit_poller_lookup_by_name(char *target, char *name); 201 201 202 API_EXPORT(int) 203 noit_check_xpath(char *xpath, int len, 204 const char *base, const char *arg); 205 202 206 API_EXPORT(void) 203 207 noit_check_stats_clear(stats_t *s); … … 237 241 API_EXPORT(void) noit_check_log_status(noit_check_t *check); 238 242 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check); 243 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len, 244 char *target, int target_len, 245 char *module, int module_len, 246 char *name, int name_len, 247 char *uuid, int uuid_len); 248 239 249 240 250 API_EXPORT(char *) src/noit_check_log.c
r2c35111 r8c720f9 60 60 #define SECPART(a) ((unsigned long)(a)->tv_sec) 61 61 #define MSECPART(a) ((unsigned long)((a)->tv_usec / 1000)) 62 #define MAKE_CHECK_UUID_STR(uuid_str, len, ls, check) do { \ 63 noit_boolean extended_id = noit_false; \ 64 const char *v; \ 65 v = noit_log_stream_get_property(ls, "extended_id"); \ 66 if(v && !strcmp(v, "on")) extended_id = noit_true; \ 67 uuid_str[0] = '\0'; \ 68 if(extended_id) { \ 69 strlcat(uuid_str, check->target, len-37); \ 70 strlcat(uuid_str, "`", len-37); \ 71 strlcat(uuid_str, check->module, len-37); \ 72 strlcat(uuid_str, "`", len-37); \ 73 strlcat(uuid_str, check->name, len-37); \ 74 strlcat(uuid_str, "`", len-37); \ 75 } \ 76 uuid_unparse_lower(check->checkid, uuid_str + strlen(uuid_str)); \ 77 } while(0) 62 78 63 79 static void … … 92 108 noit_check_t *check) { 93 109 struct timeval __now; 94 char uuid_str[37]; 95 96 uuid_unparse_lower(check->checkid, uuid_str); 110 char uuid_str[256*3+37]; 111 SETUP_LOG(check, ); 112 MAKE_CHECK_UUID_STR(uuid_str, sizeof(uuid_str), check_log, check); 113 97 114 gettimeofday(&__now, NULL); 98 115 return noit_log(ls, &__now, __FILE__, __LINE__, … … 115 132 noit_check_t *check) { 116 133 stats_t *c; 117 char uuid_str[37]; 118 119 uuid_unparse_lower(check->checkid, uuid_str); 134 char uuid_str[256*3+37]; 135 SETUP_LOG(status, ); 136 MAKE_CHECK_UUID_STR(uuid_str, sizeof(uuid_str), status_log, check); 137 120 138 c = &check->stats.current; 121 139 return noit_log(ls, &c->whence, __FILE__, __LINE__, … … 136 154 int rv = 0; 137 155 int srv; 138 char uuid_str[ 37];156 char uuid_str[256*3+37]; 139 157 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 140 158 const char *key; … … 142 160 stats_t *c; 143 161 void *vm; 144 145 uuid_unparse_lower(check->checkid, uuid_str); 162 SETUP_LOG(metrics, ); 163 MAKE_CHECK_UUID_STR(uuid_str, sizeof(uuid_str), metrics_log, check); 164 146 165 c = &check->stats.current; 147 166 while(noit_hash_next(&c->metrics, &iter, &key, &klen, &vm)) { src/noit_check_tools.c
r8135eae r8c720f9 219 219 } 220 220 221 int 222 noit_check_xpath(char *xpath, int len, 223 const char *base, const char *arg) { 224 uuid_t checkid; 225 int base_trailing_slash; 226 char argcopy[1024], *target, *module, *name; 227 228 base_trailing_slash = (base[strlen(base)-1] == '/'); 229 xpath[0] = '\0'; 230 argcopy[0] = '\0'; 231 if(arg) strlcpy(argcopy, arg, sizeof(argcopy)); 232 233 if(uuid_parse(argcopy, checkid) == 0) { 234 /* If they kill by uuid, we'll seek and destroy -- find it anywhere */ 235 snprintf(xpath, len, "/noit/checks%s%s/check[@uuid=\"%s\"]", 236 base, base_trailing_slash ? "" : "/", argcopy); 221 void 222 noit_check_extended_id_split(const char *in, int len, 223 char *target, int target_len, 224 char *module, int module_len, 225 char *name, int name_len, 226 char *uuid, int uuid_len) { 227 if(target) *target = '\0'; 228 if(module) *module = '\0'; 229 if(name) *name = '\0'; 230 if(uuid) *uuid = '\0'; 231 if(len >= UUID_STR_LEN) { 232 memcpy(uuid, in + len - UUID_STR_LEN, UUID_STR_LEN); 233 uuid[UUID_STR_LEN] = '\0'; 237 234 } 238 else if((module = strchr(argcopy, '`')) != NULL) { 239 noit_check_t *check; 240 char uuid_str[37]; 241 target = argcopy; 242 *module++ = '\0'; 243 if((name = strchr(module+1, '`')) == NULL) 244 name = module; 245 else 246 name++; 247 check = noit_poller_lookup_by_name(target, name); 248 if(!check) { 249 return -1; 250 } 251 uuid_unparse_lower(check->checkid, uuid_str); 252 snprintf(xpath, len, "/noit/checks%s%s/check[@uuid=\"%s\"]", 253 base, base_trailing_slash ? "" : "/", uuid_str); 235 if(len > UUID_STR_LEN) { 236 const char *tcp = in; 237 const char *mcp, *ncp, *ucp; 238 /* find the end of the target */ 239 mcp = strchr(tcp,'`'); 240 if(!mcp) return; 241 /* copy in the target */ 242 if(target_len > mcp-tcp) { 243 memcpy(target,tcp,mcp-tcp); 244 target[mcp-tcp] = '\0'; 245 } 246 mcp++; 247 ncp = strchr(mcp,'`'); 248 if(!ncp) return; 249 /* copy in the module */ 250 if(module_len > ncp-mcp) { 251 memcpy(module,mcp,ncp-mcp); 252 module[ncp-mcp] = '\0'; 253 } 254 ncp++; 255 /* copy in the name */ 256 ucp = in + len - UUID_STR_LEN - 1; 257 if(ncp < ucp) { 258 if(name_len > ucp-ncp) { 259 memcpy(name, ncp, ucp-ncp); 260 name[ucp-ncp] = '\0'; 261 } 262 } 254 263 } 255 return strlen(xpath);256 264 } 257 265 src/noit_check_tools.h
rd38990d r8c720f9 79 79 API_EXPORT(void) 80 80 noit_check_release_attrs(noit_hash_table *attrs); 81 API_EXPORT(int)82 noit_check_xpath(char *xpath, int len,83 const char *base, const char *arg);84 85 81 86 82 #endif src/noit_conf.c
rdb7317d r8c720f9 1002 1002 } 1003 1003 config = noit_conf_get_hash(log_configs[i], 1004 "ancestor-or-self::node()/config /*");1004 "ancestor-or-self::node()/config"); 1005 1005 ls = noit_log_stream_new(name, type[0] ? type : NULL, 1006 1006 path[0] ? path : NULL, NULL, config); src/stratcon_datastore.c
rcb978e5 r8c720f9 712 712 d->whence = (time_t)strtoul(token, NULL, 10); 713 713 PROCESS_NEXT_FIELD(token, len); 714 /* uuid is last 36 bytes */ 715 if(len > 36) { token += (len-36); len = 36; } 714 716 sid = uuid_to_sid(token, remote_cn); 715 717 if(sid == 0) goto bad_row; … … 728 730 d->whence = (time_t)strtoul(token, NULL, 10); 729 731 PROCESS_NEXT_FIELD(token, len); 732 /* uuid is last 36 bytes */ 733 if(len > 36) { token += (len-36); len = 36; } 730 734 sid = uuid_to_sid(token, remote_cn); 731 735 if(sid == 0) goto bad_row; … … 743 747 d->whence = (time_t)strtoul(token, NULL, 10); 744 748 PROCESS_NEXT_FIELD(token, len); 749 /* uuid is last 36 bytes */ 750 if(len > 36) { token += (len-36); len = 36; } 745 751 sid = uuid_to_sid(token, remote_cn); 746 752 if(sid == 0) goto bad_row; … … 1417 1423 const char *remote_cn, char *line) { 1418 1424 interim_journal_t *ij = NULL; 1419 char uuid_str[UUID_STR_LEN+1], *cp ;1425 char uuid_str[UUID_STR_LEN+1], *cp1, *cp2; 1420 1426 const char *fqdn = NULL, *dsn = NULL; 1421 1427 int storagenode_id = 0; … … 1427 1433 case 'S': 1428 1434 case 'M': 1429 if(line[1] == '\t' && (cp = strchr(line+2, '\t')) != NULL) { 1430 strlcpy(uuid_str, cp + 1, sizeof(uuid_str)); 1435 if(line[1] == '\t' && (cp1 = strchr(line+2, '\t')) != NULL && 1436 (cp2 = strchr(cp1+1, '\t')) != NULL && 1437 (cp2-cp1 >= UUID_STR_LEN)) { 1438 strlcpy(uuid_str, cp2 - UUID_STR_LEN, sizeof(uuid_str)); 1431 1439 if(!uuid_parse(uuid_str, checkid)) { 1432 1440 storage_node_quick_lookup(uuid_str, remote_cn, NULL, src/stratcon_realtime_http.c
rfa84adf r8c720f9 42 42 #include "noit_http.h" 43 43 #include "noit_rest.h" 44 #include "noit_check.h" 44 45 #include "noit_livestream_listener.h" 45 46 #include "stratcon_realtime_http.h" … … 159 160 scp = buff; 160 161 PROCESS_NEXT_FIELD(token,len); /* Skip the leader */ 161 if(buff[0] == 'M') { 162 if(buff[1] == '\t' && (buff[0] == 'M' || buff[0] == 'S')) { 163 char target[256], module[256], name[256], uuid_str[UUID_STR_LEN+1]; 162 164 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 163 165 const char *key; 164 166 int klen, i=0; 165 167 void *vval; 168 char type[2] = { '\0', '\0' }; 169 type[0] = buff[0]; 166 170 167 171 #define ra_write(a,b) if(noit_http_response_append(ctx, a, b) == noit_false) BAIL_HTTP_WRITE … … 176 180 /* Time */ 177 181 noit_hash_store(&json, "script_id", 9, strdup(s_inc_id)); 178 noit_hash_store(&json, "type", 4, strdup( "M"));182 noit_hash_store(&json, "type", 4, strdup(type)); 179 183 PROCESS_NEXT_FIELD(token,len); 180 184 noit_hash_store(&json, "time", 4, noit__strndup(token, len)); 181 185 /* UUID */ 182 186 PROCESS_NEXT_FIELD(token,len); 183 noit_hash_store(&json, "id", 2, noit__strndup(token, len)); 184 /* name */ 185 PROCESS_NEXT_FIELD(token,len); 186 noit_hash_store(&json, "metric_name", 11, noit__strndup(token, len)); 187 /* type */ 188 PROCESS_NEXT_FIELD(token,len); 189 noit_hash_store(&json, "metric_type", 11, noit__strndup(token, len)); 190 /* value */ 191 PROCESS_LAST_FIELD(token,len); /* value */ 192 noit_hash_store(&json, "value", 5, noit__strndup(token, len)); 187 noit_check_extended_id_split(token, len, target, sizeof(target), 188 module, sizeof(module), name, sizeof(name), 189 uuid_str, sizeof(uuid_str)); 190 if(*uuid_str) 191 noit_hash_store(&json, "id", 2, 192 noit__strndup(uuid_str, strlen(uuid_str))); 193 if(*target) 194 noit_hash_store(&json, "check_target", 12, 195 noit__strndup(target, strlen(target))); 196 if(*module) 197 noit_hash_store(&json, "check_module", 12, 198 noit__strndup(module, strlen(module))); 199 if(*name) 200 noit_hash_store(&json, "check_name", 10, 201 noit__strndup(name, strlen(name))); 202 if(buff[0] == 'M') { 203 /* name */ 204 PROCESS_NEXT_FIELD(token,len); 205 noit_hash_store(&json, "metric_name", 11, noit__strndup(token, len)); 206 /* type */ 207 PROCESS_NEXT_FIELD(token,len); 208 noit_hash_store(&json, "metric_type", 11, noit__strndup(token, len)); 209 /* value */ 210 PROCESS_LAST_FIELD(token,len); /* value */ 211 noit_hash_store(&json, "value", 5, noit__strndup(token, len)); 212 } 213 else if(buff[0] == 'S') { 214 /* state */ 215 PROCESS_NEXT_FIELD(token,len); 216 noit_hash_store(&json, "check_state", 11, noit__strndup(token, len)); 217 /* availability */ 218 PROCESS_NEXT_FIELD(token,len); 219 noit_hash_store(&json, "check_availability", 18, noit__strndup(token, len)); 220 /* duration */ 221 PROCESS_NEXT_FIELD(token,len); 222 noit_hash_store(&json, "check_duration_ms", 17, noit__strndup(token, len)); 223 /* status */ 224 PROCESS_LAST_FIELD(token,len); 225 noit_hash_store(&json, "status_message", 14, noit__strndup(token, len)); 226 } 193 227 194 228 memset(&iter, 0, sizeof(iter)); … … 196 230 char *val = (char *)vval; 197 231 if(i++) ra_write(",", 1); 198 ra_write(" '", 1);232 ra_write("\"", 1); 199 233 ra_write(key, klen); 200 ra_write(" ':\"", 3);234 ra_write("\":\"", 3); 201 235 while(*val) { 202 236 if(*val == '\"' || *val == '\\') { src/utils/noit_log.c
r6d9d06e r8c720f9 506 506 } 507 507 508 const char * 509 noit_log_stream_get_property(noit_log_stream_t ls, 510 const char *prop) { 511 const char *v; 512 if(ls && ls->config && 513 noit_hash_retr_str(ls->config, prop, strlen(prop), &v)) 514 return v; 515 return NULL; 516 } 517 518 void 519 noit_log_stream_set_property(noit_log_stream_t ls, 520 const char *prop, const char *v) { 521 if(!ls) return; 522 if(!ls->config) { 523 ls->config = calloc(1, sizeof(*ls->config)); 524 noit_hash_init(ls->config); 525 } 526 noit_hash_replace(ls->config, prop, strlen(prop), (void *)v, free, free); 527 } 528 508 529 noit_log_stream_t 509 530 noit_log_stream_new_on_fd(const char *name, int fd, noit_hash_table *config) { src/utils/noit_log.h
rdb7317d r8c720f9 103 103 API_EXPORT(size_t) noit_log_stream_size(noit_log_stream_t ls); 104 104 API_EXPORT(size_t) noit_log_stream_written(noit_log_stream_t ls); 105 API_EXPORT(const char *) noit_log_stream_get_property(noit_log_stream_t ls, 106 const char *); 107 API_EXPORT(void) noit_log_stream_set_property(noit_log_stream_t ls, 108 const char *, const char *); 105 109 API_EXPORT(void) noit_log_stream_free(noit_log_stream_t ls); 106 110 API_EXPORT(int) noit_vlog(noit_log_stream_t ls, struct timeval *,
