Changeset c385b68fdd537ec15c1467e6c8541b32d3838bf6
- Timestamp:
- 05/22/12 14:48:01
(1 year ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1337698081 -0400
- git-parent:
[c0606177e96ca2dd9ca395a81715892807816f5c]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1337698081 -0400
- Message:
Add lookup by ip/module.
Make the counters into a rate like statsd does.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rc060617 |
rc385b68 |
|
| 46 | 46 | #include "utils/noit_hash.h" |
|---|
| 47 | 47 | |
|---|
| 48 | | #define MAX_DEPTH 32 |
|---|
| | 48 | #define MAX_CHECKS 3 |
|---|
| 49 | 49 | |
|---|
| 50 | 50 | static noit_log_stream_t nlerr = NULL; |
|---|
| … | … | |
| 153 | 153 | /* Next the actual data */ |
|---|
| 154 | 154 | snprintf(buff, sizeof(buff), "%s`%s", key, |
|---|
| 155 | | (type == 'c') ? "counter" : (type == 'g') ? "gauge" : "timing"); |
|---|
| | 155 | (type == 'c') ? "rate" : (type == 'g') ? "gauge" : "timing"); |
|---|
| 156 | 156 | m = noit_stats_get_metric(check, &ccl->current, buff); |
|---|
| 157 | 157 | if(type == 'c') { |
|---|
| 158 | | double v = diff * (1.0 / sample); |
|---|
| | 158 | double v = diff * (1.0 / sample) / (check->period / 1000.0); |
|---|
| 159 | 159 | if(m && m->metric_type == METRIC_DOUBLE && m->metric_value.n != NULL) { |
|---|
| 160 | 160 | (*m->metric_value.n) += v; |
|---|
| … | … | |
| 176 | 176 | |
|---|
| 177 | 177 | static void |
|---|
| 178 | | statsd_handle_payload(noit_check_t *parent, noit_check_t *single, |
|---|
| | 178 | statsd_handle_payload(noit_check_t **checks, int nchecks, |
|---|
| 179 | 179 | char *payload, int len) { |
|---|
| 180 | 180 | char *cp, *ecp, *endptr; |
|---|
| … | … | |
| 182 | 182 | endptr = payload + len - 1; |
|---|
| 183 | 183 | while(ecp != NULL && ecp < endptr) { |
|---|
| 184 | | int idx = 0, last_space = 0; |
|---|
| | 184 | int i, idx = 0, last_space = 0; |
|---|
| 185 | 185 | char key[256], *value; |
|---|
| 186 | 186 | const char *type = NULL; |
|---|
| … | … | |
| 240 | 240 | case 'c': |
|---|
| 241 | 241 | case 'm': |
|---|
| 242 | | if(parent) update_check(parent, key, *type, diff, sampleRate); |
|---|
| 243 | | if(single) update_check(single, key, *type, diff, sampleRate); |
|---|
| | 242 | for(i=0;i<nchecks;i++) |
|---|
| | 243 | update_check(checks[i], key, *type, diff, sampleRate); |
|---|
| 244 | 244 | break; |
|---|
| 245 | 245 | default: |
|---|
| … | … | |
| 259 | 259 | int packets_per_cycle; |
|---|
| 260 | 260 | statsd_mod_config_t *conf; |
|---|
| 261 | | noit_check_t *check = NULL, *parent = NULL; |
|---|
| | 261 | noit_check_t *parent = NULL; |
|---|
| 262 | 262 | |
|---|
| 263 | 263 | conf = noit_module_get_userdata(self); |
|---|
| … | … | |
| 266 | 266 | packets_per_cycle = MAX(conf->packets_per_cycle, 1); |
|---|
| 267 | 267 | for( ; packets_per_cycle > 0; packets_per_cycle--) { |
|---|
| | 268 | noit_check_t *checks[MAX_CHECKS]; |
|---|
| | 269 | int nchecks = 0; |
|---|
| 268 | 270 | char ip[INET6_ADDRSTRLEN]; |
|---|
| 269 | 271 | union { |
|---|
| … | … | |
| 277 | 279 | (struct sockaddr *)&addr, &addrlen); |
|---|
| 278 | 280 | if(len < 0) { |
|---|
| 279 | | if(errno == EAGAIN) |
|---|
| | 281 | if(errno != EAGAIN) |
|---|
| 280 | 282 | noitL(nlerr, "statsd: recvfrom() -> %s\n", strerror(errno)); |
|---|
| 281 | 283 | break; |
|---|
| … | … | |
| 294 | 296 | } |
|---|
| 295 | 297 | conf->payload[len] = '\0'; |
|---|
| 296 | | check = *ip ? noit_poller_lookup_by_name(ip, "statsd") : NULL; |
|---|
| 297 | | if(parent || check) |
|---|
| 298 | | statsd_handle_payload(parent, check, conf->payload, len); |
|---|
| | 298 | nchecks = 0; |
|---|
| | 299 | if(*ip) |
|---|
| | 300 | nchecks = noit_poller_lookup_by_ip_module(ip, self->hdr.name, |
|---|
| | 301 | checks, MAX_CHECKS-1); |
|---|
| | 302 | if(parent) checks[nchecks++] = parent; |
|---|
| | 303 | if(nchecks) |
|---|
| | 304 | statsd_handle_payload(checks, nchecks, conf->payload, len); |
|---|
| 299 | 305 | } |
|---|
| 300 | 306 | return EVENTER_READ | EVENTER_EXCEPTION; |
|---|
| rac0eb62 |
rc385b68 |
|
| 999 | 999 | } |
|---|
| 1000 | 1000 | int |
|---|
| 1001 | | noit_poller_target_do(char *target, int (*f)(noit_check_t *, void *), |
|---|
| | 1001 | noit_poller_target_do(const char *target, int (*f)(noit_check_t *, void *), |
|---|
| 1002 | 1002 | void *closure) { |
|---|
| 1003 | 1003 | int count = 0; |
|---|
| … | … | |
| 1006 | 1006 | |
|---|
| 1007 | 1007 | memset(&pivot, 0, sizeof(pivot)); |
|---|
| 1008 | | pivot.target = target; |
|---|
| | 1008 | pivot.target = (char *)target; |
|---|
| 1009 | 1009 | pivot.name = ""; |
|---|
| 1010 | 1010 | noit_skiplist_find_neighbors(&polls_by_name, &pivot, NULL, NULL, &next); |
|---|
| … | … | |
| 1016 | 1016 | } |
|---|
| 1017 | 1017 | return count; |
|---|
| | 1018 | } |
|---|
| | 1019 | struct ip_module_collector_crutch { |
|---|
| | 1020 | noit_check_t **array; |
|---|
| | 1021 | const char *module; |
|---|
| | 1022 | int idx; |
|---|
| | 1023 | int allocd; |
|---|
| | 1024 | }; |
|---|
| | 1025 | static int ip_module_collector(noit_check_t *check, void *cl) { |
|---|
| | 1026 | struct ip_module_collector_crutch *c = cl; |
|---|
| | 1027 | if(c->idx >= c->allocd) return 0; |
|---|
| | 1028 | if(strcmp(check->module, c->module)) return 0; |
|---|
| | 1029 | c->array[c->idx++] = check; |
|---|
| | 1030 | return 1; |
|---|
| | 1031 | } |
|---|
| | 1032 | int |
|---|
| | 1033 | noit_poller_lookup_by_ip_module(const char *ip, const char *mod, |
|---|
| | 1034 | noit_check_t **checks, int nchecks) { |
|---|
| | 1035 | struct ip_module_collector_crutch crutch; |
|---|
| | 1036 | crutch.array = checks; |
|---|
| | 1037 | crutch.allocd = nchecks; |
|---|
| | 1038 | crutch.idx = 0; |
|---|
| | 1039 | crutch.module = mod; |
|---|
| | 1040 | return noit_poller_target_do(ip, ip_module_collector, &crutch); |
|---|
| 1018 | 1041 | } |
|---|
| 1019 | 1042 | |
|---|
| rac0eb62 |
rc385b68 |
|
| 228 | 228 | |
|---|
| 229 | 229 | API_EXPORT(int) |
|---|
| 230 | | noit_poller_target_do(char *target, int (*f)(noit_check_t *, void *), |
|---|
| | 230 | noit_poller_lookup_by_ip_module(const char *ip, const char *mod, |
|---|
| | 231 | noit_check_t **checks, int nchecks); |
|---|
| | 232 | |
|---|
| | 233 | API_EXPORT(int) |
|---|
| | 234 | noit_poller_target_do(const char *target, int (*f)(noit_check_t *, void *), |
|---|
| 231 | 235 | void *closure); |
|---|
| 232 | 236 | |
|---|