@cryptotaxi247 / netdata-1 / commits / ef397b208

allow statsd metrics to be initialized with value "zinit"

Costa Tsaousis (ktsaou) committed Jan 25, 2018 at 19:54 UTC ef397b2082a5f6784561bb6b80d2646f77da0487
1 file changed +49 -25
src/statsd.c
+49 -25
@@ -434,6 +434,10 @@ static inline void statsd_reset_metric(STATSD_METRIC *m) {
434 m->count = 0;
435 }
436
437 +static inline int value_is_zinit(const char *value) {
438 + return (*value == 'z' && *++value == 'i' && *++value == 'n' && *++value == 'i' && *++value == 't' && *++value == '\0');
439 +}
440 +
441 static inline void statsd_process_gauge(STATSD_METRIC *m, const char *value, const char *sampling) {
442 if(unlikely(!value || !*value)) {
443 error("STATSD: metric '%s' of type gauge, with empty value is ignored.", m->name);
@@ -445,13 +449,18 @@ static inline void statsd_process_gauge(STATSD_METRIC *m, const char *value, con
449 statsd_reset_metric(m);
450 }
451
448 - if(unlikely(*value == '+' || *value == '-'))
449 - m->gauge.value += statsd_parse_float(value, 1.0) / statsd_parse_float(sampling, 1.0);
450 - else
451 - m->gauge.value = statsd_parse_float(value, 1.0) / statsd_parse_float(sampling, 1.0);
452 + if(unlikely(value_is_zinit(value))) {
453 + // magic loading of metric, without affecting anything
454 + }
455 + else {
456 + if (unlikely(*value == '+' || *value == '-'))
457 + m->gauge.value += statsd_parse_float(value, 1.0) / statsd_parse_float(sampling, 1.0);
458 + else
459 + m->gauge.value = statsd_parse_float(value, 1.0) / statsd_parse_float(sampling, 1.0);
460
453 - m->events++;
454 - m->count++;
461 + m->events++;
462 + m->count++;
463 + }
464 }
465
466 static inline void statsd_process_counter(STATSD_METRIC *m, const char *value, const char *sampling) {
@@ -459,10 +468,15 @@ static inline void statsd_process_counter(STATSD_METRIC *m, const char *value, c
468
469 if(unlikely(m->reset)) statsd_reset_metric(m);
470
462 - m->counter.value += llrintl((long double)statsd_parse_int(value, 1) / statsd_parse_float(sampling, 1.0));
471 + if(unlikely(value_is_zinit(value))) {
472 + // magic loading of metric, without affecting anything
473 + }
474 + else {
475 + m->counter.value += llrintl((long double) statsd_parse_int(value, 1) / statsd_parse_float(sampling, 1.0));
476
464 - m->events++;
465 - m->count++;
477 + m->events++;
478 + m->count++;
479 + }
480 }
481
482 static inline void statsd_process_meter(STATSD_METRIC *m, const char *value, const char *sampling) {
@@ -481,17 +495,22 @@ static inline void statsd_process_histogram(STATSD_METRIC *m, const char *value,
495 statsd_reset_metric(m);
496 }
497
484 - if(unlikely(m->histogram.ext->used == m->histogram.ext->size)) {
485 - netdata_mutex_lock(&m->histogram.ext->mutex);
486 - m->histogram.ext->size += statsd.histogram_increase_step;
487 - m->histogram.ext->values = reallocz(m->histogram.ext->values, sizeof(long double) * m->histogram.ext->size);
488 - netdata_mutex_unlock(&m->histogram.ext->mutex);
498 + if(unlikely(value_is_zinit(value))) {
499 + // magic loading of metric, without affecting anything
500 }
501 + else {
502 + if (unlikely(m->histogram.ext->used == m->histogram.ext->size)) {
503 + netdata_mutex_lock(&m->histogram.ext->mutex);
504 + m->histogram.ext->size += statsd.histogram_increase_step;
505 + m->histogram.ext->values = reallocz(m->histogram.ext->values, sizeof(long double) * m->histogram.ext->size);
506 + netdata_mutex_unlock(&m->histogram.ext->mutex);
507 + }
508
491 - m->histogram.ext->values[m->histogram.ext->used++] = statsd_parse_float(value, 1.0) / statsd_parse_float(sampling, 1.0);
509 + m->histogram.ext->values[m->histogram.ext->used++] = statsd_parse_float(value, 1.0) / statsd_parse_float(sampling, 1.0);
510
493 - m->events++;
494 - m->count++;
511 + m->events++;
512 + m->count++;
513 + }
514 }
515
516 static inline void statsd_process_timer(STATSD_METRIC *m, const char *value, const char *sampling) {
@@ -518,19 +537,24 @@ static inline void statsd_process_set(STATSD_METRIC *m, const char *value) {
537 statsd_reset_metric(m);
538 }
539
521 - if(unlikely(!m->set.dict)) {
522 - m->set.dict = dictionary_create(STATSD_DICTIONARY_OPTIONS|DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE);
540 + if (unlikely(!m->set.dict)) {
541 + m->set.dict = dictionary_create(STATSD_DICTIONARY_OPTIONS | DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE);
542 m->set.unique = 0;
543 }
544
526 - void *t = dictionary_get(m->set.dict, value);
527 - if(unlikely(!t)) {
528 - dictionary_set(m->set.dict, value, NULL, 1);
529 - m->set.unique++;
545 + if(unlikely(value_is_zinit(value))) {
546 + // magic loading of metric, without affecting anything
547 }
548 + else {
549 + void *t = dictionary_get(m->set.dict, value);
550 + if (unlikely(!t)) {
551 + dictionary_set(m->set.dict, value, NULL, 1);
552 + m->set.unique++;
553 + }
554
532 - m->events++;
533 - m->count++;
555 + m->events++;
556 + m->count++;
557 + }
558 }
559
560