diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-07-20 04:49:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-07-20 04:49:55 +0000 |
commit | ab1bb5b7f1c3c3a7b240ab7fc8661459ecd7decb (patch) | |
tree | 7a900833aad3ccc685712c6c2a7d87576d54f427 /collectors/statsd.plugin/statsd.c | |
parent | Adding upstream version 1.40.1. (diff) | |
download | netdata-878715cc218c4a71a71c4cb4b4634082aa9627ba.tar.xz netdata-878715cc218c4a71a71c4cb4b4634082aa9627ba.zip |
Adding upstream version 1.41.0.upstream/1.41.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/statsd.plugin/statsd.c')
-rw-r--r-- | collectors/statsd.plugin/statsd.c | 248 |
1 files changed, 114 insertions, 134 deletions
diff --git a/collectors/statsd.plugin/statsd.c b/collectors/statsd.plugin/statsd.c index 1425d0a97..5422d2905 100644 --- a/collectors/statsd.plugin/statsd.c +++ b/collectors/statsd.plugin/statsd.c @@ -34,7 +34,7 @@ typedef struct statsd_metric_gauge { } STATSD_METRIC_GAUGE; typedef struct statsd_metric_counter { // counter and meter - long long value; + collected_number value; } STATSD_METRIC_COUNTER; typedef struct statsd_histogram_extensions { @@ -57,8 +57,8 @@ typedef struct statsd_histogram_extensions { RRDDIM *rd_stddev; //RRDDIM *rd_sum; - size_t size; - size_t used; + uint32_t size; + uint32_t used; NETDATA_DOUBLE *values; // dynamic array of values collected } STATSD_METRIC_HISTOGRAM_EXTENSIONS; @@ -68,24 +68,22 @@ typedef struct statsd_metric_histogram { // histogram and timer typedef struct statsd_metric_set { DICTIONARY *dict; - size_t unique; } STATSD_METRIC_SET; typedef struct statsd_metric_dictionary_item { - size_t count; + uint32_t count; RRDDIM *rd; } STATSD_METRIC_DICTIONARY_ITEM; typedef struct statsd_metric_dictionary { DICTIONARY *dict; - size_t unique; } STATSD_METRIC_DICTIONARY; // -------------------------------------------------------------------------------------------------------------------- // this is a metric - for all types of metrics -typedef enum statsd_metric_options { +typedef enum __attribute__((packed)) statsd_metric_options { STATSD_METRIC_OPTION_NONE = 0x00000000, // no options set STATSD_METRIC_OPTION_SHOW_GAPS_WHEN_NOT_COLLECTED = 0x00000001, // do not update the chart dimension, when this metric is not collected STATSD_METRIC_OPTION_PRIVATE_CHART_ENABLED = 0x00000002, // render a private chart for this metric @@ -99,7 +97,7 @@ typedef enum statsd_metric_options { STATSD_METRIC_OPTION_UPDATED_CHART_METADATA = 0x00000200, // set when the private chart metadata have been updated via tags } STATS_METRIC_OPTIONS; -typedef enum statsd_metric_type { +typedef enum __attribute__((packed)) statsd_metric_type { STATSD_METRIC_TYPE_GAUGE, STATSD_METRIC_TYPE_COUNTER, STATSD_METRIC_TYPE_METER, @@ -118,7 +116,7 @@ typedef struct statsd_metric { // metadata about data collection collected_number events; // the number of times this metric has been collected (never resets) - size_t count; // the number of times this metric has been collected since the last flush + uint32_t count; // the number of times this metric has been collected since the last flush // the actual collected data union { @@ -151,22 +149,21 @@ typedef struct statsd_metric { typedef struct statsd_index { char *name; // the name of the index of metrics - size_t events; // the number of events processed for this index - size_t metrics; // the number of metrics in this index - size_t useful; // the number of useful metrics in this index + uint32_t events; // the number of events processed for this index + uint32_t metrics; // the number of metrics in this index + uint32_t useful; // the number of useful metrics in this index + STATS_METRIC_OPTIONS default_options; // default options for all metrics in this index STATSD_METRIC_TYPE type; // the type of index DICTIONARY *dict; STATSD_METRIC *first_useful; // the linked list of useful metrics (new metrics are added in front) - - STATS_METRIC_OPTIONS default_options; // default options for all metrics in this index } STATSD_INDEX; // -------------------------------------------------------------------------------------------------------------------- // synthetic charts -typedef enum statsd_app_chart_dimension_value_type { +typedef enum __attribute__((packed)) statsd_app_chart_dimension_value_type { STATSD_APP_CHART_DIM_VALUE_TYPE_EVENTS, STATSD_APP_CHART_DIM_VALUE_TYPE_LAST, STATSD_APP_CHART_DIM_VALUE_TYPE_AVERAGE, @@ -183,18 +180,18 @@ typedef struct statsd_app_chart_dimension { const char *metric; // the source metric name of this dimension uint32_t metric_hash; // hash for fast string comparisons - SIMPLE_PATTERN *metric_pattern; // set when the 'metric' is a simple pattern - - collected_number multiplier; // the multiplier of the dimension - collected_number divisor; // the divisor of the dimension + int32_t multiplier; // the multiplier of the dimension + int32_t divisor; // the divisor of the dimension RRDDIM_FLAGS flags; // the RRDDIM flags for this dimension RRDDIM_OPTIONS options; // the RRDDIM options for this dimension + RRD_ALGORITHM algorithm; // the algorithm of this dimension STATSD_APP_CHART_DIM_VALUE_TYPE value_type; // which value to use of the source metric + SIMPLE_PATTERN *metric_pattern; // set when the 'metric' is a simple pattern + RRDDIM *rd; // a pointer to the RRDDIM that has been created for this dimension collected_number *value_ptr; // a pointer to the source metric value - RRD_ALGORITHM algorithm; // the algorithm of this dimension struct statsd_app_chart_dimension *next; // the next dimension for this chart } STATSD_APP_CHART_DIM; @@ -207,11 +204,11 @@ typedef struct statsd_app_chart { const char *context; const char *units; const char *module; - long priority; + int32_t priority; RRDSET_TYPE chart_type; STATSD_APP_CHART_DIM *dimensions; - size_t dimensions_count; - size_t dimensions_linked_count; + uint32_t dimensions_count; + uint32_t dimensions_linked_count; RRDSET *st; struct statsd_app_chart *next; @@ -222,8 +219,8 @@ typedef struct statsd_app { SIMPLE_PATTERN *metrics; STATS_METRIC_OPTIONS default_options; RRD_MEMORY_MODE rrd_memory_mode; + int32_t rrd_history_entries; DICTIONARY *dict; - long rrd_history_entries; const char *source; STATSD_APP_CHART *charts; @@ -236,7 +233,7 @@ typedef struct statsd_app { struct collection_thread_status { SPINLOCK spinlock; bool running; - size_t max_sockets; + uint32_t max_sockets; netdata_thread_t thread; }; @@ -262,23 +259,22 @@ static struct statsd { size_t udp_packets_received; size_t udp_bytes_read; - int enabled; - int update_every; + int32_t update_every; + bool enabled; + bool private_charts_hidden; SIMPLE_PATTERN *charts_for; - size_t tcp_idle_timeout; + uint32_t tcp_idle_timeout; collected_number decimal_detail; - size_t private_charts; - size_t max_private_charts_hard; - long private_charts_rrd_history_entries; - unsigned int private_charts_hidden:1; + uint32_t private_charts; + uint32_t max_private_charts_hard; STATSD_APP *apps; - size_t recvmmsg_size; - size_t histogram_increase_step; + uint32_t recvmmsg_size; + uint32_t histogram_increase_step; + uint32_t dictionary_max_unique; double histogram_percentile; char *histogram_percentile_str; - size_t dictionary_max_unique; int threads; struct collection_thread_status *collection_threads_status; @@ -287,7 +283,7 @@ static struct statsd { } statsd = { .enabled = 1, .max_private_charts_hard = 1000, - .private_charts_hidden = 0, + .private_charts_hidden = false, .recvmmsg_size = 10, .decimal_detail = STATSD_DECIMAL_DETAIL, @@ -374,7 +370,7 @@ static void dictionary_metric_insert_callback(const DICTIONARY_ITEM *item, void STATSD_METRIC *m = (STATSD_METRIC *)value; const char *name = dictionary_acquired_item_name(item); - debug(D_STATSD, "Creating new %s metric '%s'", index->name, name); + netdata_log_debug(D_STATSD, "Creating new %s metric '%s'", index->name, name); m->name = name; m->hash = simple_hash(name); @@ -405,7 +401,7 @@ static void dictionary_metric_delete_callback(const DICTIONARY_ITEM *item, void } static inline STATSD_METRIC *statsd_find_or_add_metric(STATSD_INDEX *index, const char *name) { - debug(D_STATSD, "searching for metric '%s' under '%s'", name, index->name); + netdata_log_debug(D_STATSD, "searching for metric '%s' under '%s'", name, index->name); #ifdef STATSD_MULTITHREADED // avoid the write lock of dictionary_set() for existing metrics @@ -571,18 +567,11 @@ static inline void statsd_process_histogram_or_timer(STATSD_METRIC *m, const cha #define statsd_process_timer(m, value, sampling) statsd_process_histogram_or_timer(m, value, sampling, "timer") #define statsd_process_histogram(m, value, sampling) statsd_process_histogram_or_timer(m, value, sampling, "histogram") -static void dictionary_metric_set_value_insert_callback(const DICTIONARY_ITEM *item, void *value, void *data) { - (void)item; - (void)value; - STATSD_METRIC *m = (STATSD_METRIC *)data; - m->set.unique++; -} - static inline void statsd_process_set(STATSD_METRIC *m, const char *value) { if(!is_metric_useful_for_collection(m)) return; if(unlikely(!value || !*value)) { - error("STATSD: metric of type set, with empty value is ignored."); + netdata_log_error("STATSD: metric of type set, with empty value is ignored."); return; } @@ -594,11 +583,8 @@ static inline void statsd_process_set(STATSD_METRIC *m, const char *value) { statsd_reset_metric(m); } - if (unlikely(!m->set.dict)) { - m->set.dict = dictionary_create_advanced(STATSD_DICTIONARY_OPTIONS, &dictionary_stats_category_collectors, 0); - dictionary_register_insert_callback(m->set.dict, dictionary_metric_set_value_insert_callback, m); - m->set.unique = 0; - } + if (unlikely(!m->set.dict)) + m->set.dict = dictionary_create_advanced(STATSD_DICTIONARY_OPTIONS, &dictionary_stats_category_collectors, 0); if(unlikely(value_is_zinit(value))) { // magic loading of metric, without affecting anything @@ -616,29 +602,19 @@ static inline void statsd_process_set(STATSD_METRIC *m, const char *value) { } } -static void dictionary_metric_dict_value_insert_callback(const DICTIONARY_ITEM *item, void *value, void *data) { - (void)item; - (void)value; - STATSD_METRIC *m = (STATSD_METRIC *)data; - m->dictionary.unique++; -} - static inline void statsd_process_dictionary(STATSD_METRIC *m, const char *value) { if(!is_metric_useful_for_collection(m)) return; if(unlikely(!value || !*value)) { - error("STATSD: metric of type set, with empty value is ignored."); + netdata_log_error("STATSD: metric of type set, with empty value is ignored."); return; } if(unlikely(m->reset)) statsd_reset_metric(m); - if (unlikely(!m->dictionary.dict)) { - m->dictionary.dict = dictionary_create_advanced(STATSD_DICTIONARY_OPTIONS, &dictionary_stats_category_collectors, 0); - dictionary_register_insert_callback(m->dictionary.dict, dictionary_metric_dict_value_insert_callback, m); - m->dictionary.unique = 0; - } + if (unlikely(!m->dictionary.dict)) + m->dictionary.dict = dictionary_create_advanced(STATSD_DICTIONARY_OPTIONS, &dictionary_stats_category_collectors, 0); if(unlikely(value_is_zinit(value))) { // magic loading of metric, without affecting anything @@ -647,7 +623,7 @@ static inline void statsd_process_dictionary(STATSD_METRIC *m, const char *value STATSD_METRIC_DICTIONARY_ITEM *t = (STATSD_METRIC_DICTIONARY_ITEM *)dictionary_get(m->dictionary.dict, value); if (unlikely(!t)) { - if(!t && m->dictionary.unique >= statsd.dictionary_max_unique) + if(!t && dictionary_entries(m->dictionary.dict) >= statsd.dictionary_max_unique) value = "other"; t = (STATSD_METRIC_DICTIONARY_ITEM *)dictionary_set(m->dictionary.dict, value, NULL, sizeof(STATSD_METRIC_DICTIONARY_ITEM)); @@ -697,7 +673,7 @@ static inline const char *statsd_parse_field_trim(const char *start, char *end) } static void statsd_process_metric(const char *name, const char *value, const char *type, const char *sampling, const char *tags) { - debug(D_STATSD, "STATSD: raw metric '%s', value '%s', type '%s', sampling '%s', tags '%s'", name?name:"(null)", value?value:"(null)", type?type:"(null)", sampling?sampling:"(null)", tags?tags:"(null)"); + netdata_log_debug(D_STATSD, "STATSD: raw metric '%s', value '%s', type '%s', sampling '%s', tags '%s'", name?name:"(null)", value?value:"(null)", type?type:"(null)", sampling?sampling:"(null)", tags?tags:"(null)"); if(unlikely(!name || !*name)) return; if(unlikely(!type || !*type)) type = "m"; @@ -744,7 +720,7 @@ static void statsd_process_metric(const char *name, const char *value, const cha } else { statsd.unknown_types++; - error("STATSD: metric '%s' with value '%s' is sent with unknown metric type '%s'", name, value?value:"", type); + netdata_log_error("STATSD: metric '%s' with value '%s' is sent with unknown metric type '%s'", name, value?value:"", type); } if(m && tags && *tags) { @@ -792,7 +768,7 @@ static void statsd_process_metric(const char *name, const char *value, const cha static inline size_t statsd_process(char *buffer, size_t size, int require_newlines) { buffer[size] = '\0'; - debug(D_STATSD, "RECEIVED: %zu bytes: '%s'", size, buffer); + netdata_log_debug(D_STATSD, "RECEIVED: %zu bytes: '%s'", size, buffer); const char *s = buffer; while(*s) { @@ -916,14 +892,14 @@ static void statsd_del_callback(POLLINFO *pi) { if(t->type == STATSD_SOCKET_DATA_TYPE_TCP) { if(t->len != 0) { statsd.socket_errors++; - error("STATSD: client is probably sending unterminated metrics. Closed socket left with '%s'. Trying to process it.", t->buffer); + netdata_log_error("STATSD: client is probably sending unterminated metrics. Closed socket left with '%s'. Trying to process it.", t->buffer); statsd_process(t->buffer, t->len, 0); } statsd.tcp_socket_disconnects++; statsd.tcp_socket_connected--; } else - error("STATSD: internal error: received socket data type is %d, but expected %d", (int)t->type, (int)STATSD_SOCKET_DATA_TYPE_TCP); + netdata_log_error("STATSD: internal error: received socket data type is %d, but expected %d", (int)t->type, (int)STATSD_SOCKET_DATA_TYPE_TCP); freez(t); } @@ -944,7 +920,7 @@ static int statsd_rcv_callback(POLLINFO *pi, short int *events) { case SOCK_STREAM: { struct statsd_tcp *d = (struct statsd_tcp *)pi->data; if(unlikely(!d)) { - error("STATSD: internal error: expected TCP data pointer is NULL"); + netdata_log_error("STATSD: internal error: expected TCP data pointer is NULL"); statsd.socket_errors++; retval = -1; goto cleanup; @@ -952,7 +928,7 @@ static int statsd_rcv_callback(POLLINFO *pi, short int *events) { #ifdef NETDATA_INTERNAL_CHECKS if(unlikely(d->type != STATSD_SOCKET_DATA_TYPE_TCP)) { - error("STATSD: internal error: socket data type should be %d, but it is %d", (int)STATSD_SOCKET_DATA_TYPE_TCP, (int)d->type); + netdata_log_error("STATSD: internal error: socket data type should be %d, but it is %d", (int)STATSD_SOCKET_DATA_TYPE_TCP, (int)d->type); statsd.socket_errors++; retval = -1; goto cleanup; @@ -966,14 +942,14 @@ static int statsd_rcv_callback(POLLINFO *pi, short int *events) { if (rc < 0) { // read failed if (errno != EWOULDBLOCK && errno != EAGAIN && errno != EINTR) { - error("STATSD: recv() on TCP socket %d failed.", fd); + netdata_log_error("STATSD: recv() on TCP socket %d failed.", fd); statsd.socket_errors++; ret = -1; } } else if (!rc) { // connection closed - debug(D_STATSD, "STATSD: client disconnected."); + netdata_log_debug(D_STATSD, "STATSD: client disconnected."); ret = -1; } else { @@ -1000,7 +976,7 @@ static int statsd_rcv_callback(POLLINFO *pi, short int *events) { case SOCK_DGRAM: { struct statsd_udp *d = (struct statsd_udp *)pi->data; if(unlikely(!d)) { - error("STATSD: internal error: expected UDP data pointer is NULL"); + netdata_log_error("STATSD: internal error: expected UDP data pointer is NULL"); statsd.socket_errors++; retval = -1; goto cleanup; @@ -1008,7 +984,7 @@ static int statsd_rcv_callback(POLLINFO *pi, short int *events) { #ifdef NETDATA_INTERNAL_CHECKS if(unlikely(d->type != STATSD_SOCKET_DATA_TYPE_UDP)) { - error("STATSD: internal error: socket data should be %d, but it is %d", (int)d->type, (int)STATSD_SOCKET_DATA_TYPE_UDP); + netdata_log_error("STATSD: internal error: socket data should be %d, but it is %d", (int)d->type, (int)STATSD_SOCKET_DATA_TYPE_UDP); statsd.socket_errors++; retval = -1; goto cleanup; @@ -1022,7 +998,7 @@ static int statsd_rcv_callback(POLLINFO *pi, short int *events) { if (rc < 0) { // read failed if (errno != EWOULDBLOCK && errno != EAGAIN && errno != EINTR) { - error("STATSD: recvmmsg() on UDP socket %d failed.", fd); + netdata_log_error("STATSD: recvmmsg() on UDP socket %d failed.", fd); statsd.socket_errors++; retval = -1; goto cleanup; @@ -1048,7 +1024,7 @@ static int statsd_rcv_callback(POLLINFO *pi, short int *events) { if (rc < 0) { // read failed if (errno != EWOULDBLOCK && errno != EAGAIN && errno != EINTR) { - error("STATSD: recv() on UDP socket %d failed.", fd); + netdata_log_error("STATSD: recv() on UDP socket %d failed.", fd); statsd.socket_errors++; retval = -1; goto cleanup; @@ -1067,7 +1043,7 @@ static int statsd_rcv_callback(POLLINFO *pi, short int *events) { } default: { - error("STATSD: internal error: unknown socktype %d on socket %d", pi->socktype, fd); + netdata_log_error("STATSD: internal error: unknown socktype %d on socket %d", pi->socktype, fd); statsd.socket_errors++; retval = -1; goto cleanup; @@ -1085,7 +1061,7 @@ static int statsd_snd_callback(POLLINFO *pi, short int *events) { (void)events; worker_is_busy(WORKER_JOB_TYPE_SND_DATA); - error("STATSD: snd_callback() called, but we never requested to send data to statsd clients."); + netdata_log_error("STATSD: snd_callback() called, but we never requested to send data to statsd clients."); worker_is_idle(); return -1; @@ -1096,9 +1072,9 @@ static int statsd_snd_callback(POLLINFO *pi, short int *events) { void statsd_collector_thread_cleanup(void *data) { struct statsd_udp *d = data; - netdata_spinlock_lock(&d->status->spinlock); + spinlock_lock(&d->status->spinlock); d->status->running = false; - netdata_spinlock_unlock(&d->status->spinlock); + spinlock_unlock(&d->status->spinlock); collector_info("cleaning up..."); @@ -1121,9 +1097,9 @@ static bool statsd_should_stop(void) { void *statsd_collector_thread(void *ptr) { struct collection_thread_status *status = ptr; - netdata_spinlock_lock(&status->spinlock); + spinlock_lock(&status->spinlock); status->running = true; - netdata_spinlock_unlock(&status->spinlock); + spinlock_unlock(&status->spinlock); worker_register("STATSD"); worker_register_job_name(WORKER_JOB_TYPE_TCP_CONNECTED, "tcp connect"); @@ -1193,7 +1169,7 @@ static STATSD_APP_CHART_DIM_VALUE_TYPE string2valuetype(const char *type, size_t else if(!strcmp(type, "stddev")) return STATSD_APP_CHART_DIM_VALUE_TYPE_STDDEV; else if(!strcmp(type, "percentile")) return STATSD_APP_CHART_DIM_VALUE_TYPE_PERCENTILE; - error("STATSD: invalid type '%s' at line %zu of file '%s'. Using 'last'.", type, line, filename); + netdata_log_error("STATSD: invalid type '%s' at line %zu of file '%s'. Using 'last'.", type, line, filename); return STATSD_APP_CHART_DIM_VALUE_TYPE_LAST; } @@ -1255,20 +1231,20 @@ static STATSD_APP_CHART_DIM *add_dimension_to_app_chart( } chart->dimensions_count++; - debug(D_STATSD, "Added dimension '%s' to chart '%s' of app '%s', for metric '%s', with type %u, multiplier " COLLECTED_NUMBER_FORMAT ", divisor " COLLECTED_NUMBER_FORMAT, + netdata_log_debug(D_STATSD, "Added dimension '%s' to chart '%s' of app '%s', for metric '%s', with type %u, multiplier %d, divisor %d", dim->name, chart->id, app->name, dim->metric, dim->value_type, dim->multiplier, dim->divisor); return dim; } static int statsd_readfile(const char *filename, STATSD_APP *app, STATSD_APP_CHART *chart, DICTIONARY *dict) { - debug(D_STATSD, "STATSD configuration reading file '%s'", filename); + netdata_log_debug(D_STATSD, "STATSD configuration reading file '%s'", filename); char *buffer = mallocz(STATSD_CONF_LINE_MAX + 1); FILE *fp = fopen(filename, "r"); if(!fp) { - error("STATSD: cannot open file '%s'.", filename); + netdata_log_error("STATSD: cannot open file '%s'.", filename); freez(buffer); return -1; } @@ -1281,11 +1257,11 @@ static int statsd_readfile(const char *filename, STATSD_APP *app, STATSD_APP_CHA s = trim(buffer); if (!s || *s == '#') { - debug(D_STATSD, "STATSD: ignoring line %zu of file '%s', it is empty.", line, filename); + netdata_log_debug(D_STATSD, "STATSD: ignoring line %zu of file '%s', it is empty.", line, filename); continue; } - debug(D_STATSD, "STATSD: processing line %zu of file '%s': %s", line, filename, buffer); + netdata_log_debug(D_STATSD, "STATSD: processing line %zu of file '%s': %s", line, filename, buffer); if(*s == 'i' && strncmp(s, "include", 7) == 0) { s = trim(&s[7]); @@ -1305,7 +1281,7 @@ static int statsd_readfile(const char *filename, STATSD_APP *app, STATSD_APP_CHA freez(tmp); } else - error("STATSD: ignoring line %zu of file '%s', include filename is empty", line, filename); + netdata_log_error("STATSD: ignoring line %zu of file '%s', include filename is empty", line, filename); continue; } @@ -1372,20 +1348,20 @@ static int statsd_readfile(const char *filename, STATSD_APP *app, STATSD_APP_CHA } } else - error("STATSD: ignoring line %zu ('%s') of file '%s', [app] is not defined.", line, s, filename); + netdata_log_error("STATSD: ignoring line %zu ('%s') of file '%s', [app] is not defined.", line, s, filename); continue; } if(!app) { - error("STATSD: ignoring line %zu ('%s') of file '%s', it is outside all sections.", line, s, filename); + netdata_log_error("STATSD: ignoring line %zu ('%s') of file '%s', it is outside all sections.", line, s, filename); continue; } char *name = s; char *value = strchr(s, '='); if(!value) { - error("STATSD: ignoring line %zu ('%s') of file '%s', there is no = in it.", line, s, filename); + netdata_log_error("STATSD: ignoring line %zu ('%s') of file '%s', there is no = in it.", line, s, filename); continue; } *value = '\0'; @@ -1395,11 +1371,11 @@ static int statsd_readfile(const char *filename, STATSD_APP *app, STATSD_APP_CHA value = trim(value); if(!name || *name == '#') { - error("STATSD: ignoring line %zu of file '%s', name is empty.", line, filename); + netdata_log_error("STATSD: ignoring line %zu of file '%s', name is empty.", line, filename); continue; } if(!value) { - debug(D_CONFIG, "STATSD: ignoring line %zu of file '%s', value is empty.", line, filename); + netdata_log_debug(D_CONFIG, "STATSD: ignoring line %zu of file '%s', value is empty.", line, filename); continue; } @@ -1442,7 +1418,7 @@ static int statsd_readfile(const char *filename, STATSD_APP *app, STATSD_APP_CHA app->rrd_history_entries = 5; } else { - error("STATSD: ignoring line %zu ('%s') of file '%s'. Unknown keyword for the [app] section.", line, name, filename); + netdata_log_error("STATSD: ignoring line %zu ('%s') of file '%s'. Unknown keyword for the [app] section.", line, name, filename); continue; } } @@ -1480,7 +1456,7 @@ static int statsd_readfile(const char *filename, STATSD_APP *app, STATSD_APP_CHA else if (!strcmp(name, "dimension")) { // metric [name [type [multiplier [divisor]]]] char *words[10] = { NULL }; - size_t num_words = pluginsd_split_words(value, words, 10); + size_t num_words = quoted_strings_splitter_pluginsd(value, words, 10); int pattern = 0; size_t i = 0; @@ -1536,7 +1512,7 @@ static int statsd_readfile(const char *filename, STATSD_APP *app, STATSD_APP_CHA dim->metric_pattern = simple_pattern_create(dim->metric, NULL, SIMPLE_PATTERN_EXACT, true); } else { - error("STATSD: ignoring line %zu ('%s') of file '%s'. Unknown keyword for the [%s] section.", line, name, filename, chart->id); + netdata_log_error("STATSD: ignoring line %zu ('%s') of file '%s'. Unknown keyword for the [%s] section.", line, name, filename, chart->id); continue; } } @@ -1649,7 +1625,7 @@ static inline RRDSET *statsd_private_rrdset_create( } static inline void statsd_private_chart_gauge(STATSD_METRIC *m) { - debug(D_STATSD, "updating private chart for gauge metric '%s'", m->name); + netdata_log_debug(D_STATSD, "updating private chart for gauge metric '%s'", m->name); if(unlikely(!m->st || m->options & STATSD_METRIC_OPTION_UPDATED_CHART_METADATA)) { m->options &= ~STATSD_METRIC_OPTION_UPDATED_CHART_METADATA; @@ -1689,7 +1665,7 @@ static inline void statsd_private_chart_gauge(STATSD_METRIC *m) { } static inline void statsd_private_chart_counter_or_meter(STATSD_METRIC *m, const char *dim, const char *family) { - debug(D_STATSD, "updating private chart for %s metric '%s'", dim, m->name); + netdata_log_debug(D_STATSD, "updating private chart for %s metric '%s'", dim, m->name); if(unlikely(!m->st || m->options & STATSD_METRIC_OPTION_UPDATED_CHART_METADATA)) { m->options &= ~STATSD_METRIC_OPTION_UPDATED_CHART_METADATA; @@ -1729,7 +1705,7 @@ static inline void statsd_private_chart_counter_or_meter(STATSD_METRIC *m, const } static inline void statsd_private_chart_set(STATSD_METRIC *m) { - debug(D_STATSD, "updating private chart for set metric '%s'", m->name); + netdata_log_debug(D_STATSD, "updating private chart for set metric '%s'", m->name); if(unlikely(!m->st || m->options & STATSD_METRIC_OPTION_UPDATED_CHART_METADATA)) { m->options &= ~STATSD_METRIC_OPTION_UPDATED_CHART_METADATA; @@ -1769,7 +1745,7 @@ static inline void statsd_private_chart_set(STATSD_METRIC *m) { } static inline void statsd_private_chart_dictionary(STATSD_METRIC *m) { - debug(D_STATSD, "updating private chart for dictionary metric '%s'", m->name); + netdata_log_debug(D_STATSD, "updating private chart for dictionary metric '%s'", m->name); if(unlikely(!m->st || m->options & STATSD_METRIC_OPTION_UPDATED_CHART_METADATA)) { m->options &= ~STATSD_METRIC_OPTION_UPDATED_CHART_METADATA; @@ -1812,7 +1788,7 @@ static inline void statsd_private_chart_dictionary(STATSD_METRIC *m) { } static inline void statsd_private_chart_timer_or_histogram(STATSD_METRIC *m, const char *dim, const char *family, const char *units) { - debug(D_STATSD, "updating private chart for %s metric '%s'", dim, m->name); + netdata_log_debug(D_STATSD, "updating private chart for %s metric '%s'", dim, m->name); if(unlikely(!m->st || m->options & STATSD_METRIC_OPTION_UPDATED_CHART_METADATA)) { m->options &= ~STATSD_METRIC_OPTION_UPDATED_CHART_METADATA; @@ -1867,7 +1843,7 @@ static inline void statsd_private_chart_timer_or_histogram(STATSD_METRIC *m, con // statsd flush metrics static inline void statsd_flush_gauge(STATSD_METRIC *m) { - debug(D_STATSD, "flushing gauge metric '%s'", m->name); + netdata_log_debug(D_STATSD, "flushing gauge metric '%s'", m->name); int updated = 0; if(unlikely(!m->reset && m->count)) { @@ -1882,7 +1858,7 @@ static inline void statsd_flush_gauge(STATSD_METRIC *m) { } static inline void statsd_flush_counter_or_meter(STATSD_METRIC *m, const char *dim, const char *family) { - debug(D_STATSD, "flushing %s metric '%s'", dim, m->name); + netdata_log_debug(D_STATSD, "flushing %s metric '%s'", dim, m->name); int updated = 0; if(unlikely(!m->reset && m->count)) { @@ -1905,11 +1881,11 @@ static inline void statsd_flush_meter(STATSD_METRIC *m) { } static inline void statsd_flush_set(STATSD_METRIC *m) { - debug(D_STATSD, "flushing set metric '%s'", m->name); + netdata_log_debug(D_STATSD, "flushing set metric '%s'", m->name); int updated = 0; if(unlikely(!m->reset && m->count)) { - m->last = (collected_number)m->set.unique; + m->last = (collected_number)dictionary_entries(m->set.dict); m->reset = 1; updated = 1; @@ -1923,11 +1899,11 @@ static inline void statsd_flush_set(STATSD_METRIC *m) { } static inline void statsd_flush_dictionary(STATSD_METRIC *m) { - debug(D_STATSD, "flushing dictionary metric '%s'", m->name); + netdata_log_debug(D_STATSD, "flushing dictionary metric '%s'", m->name); int updated = 0; if(unlikely(!m->reset && m->count)) { - m->last = (collected_number)m->dictionary.unique; + m->last = (collected_number)dictionary_entries(m->dictionary.dict); m->reset = 1; updated = 1; @@ -1939,19 +1915,19 @@ static inline void statsd_flush_dictionary(STATSD_METRIC *m) { if(unlikely(m->options & STATSD_METRIC_OPTION_PRIVATE_CHART_ENABLED && (updated || !(m->options & STATSD_METRIC_OPTION_SHOW_GAPS_WHEN_NOT_COLLECTED)))) statsd_private_chart_dictionary(m); - if(m->dictionary.unique >= statsd.dictionary_max_unique) { + if(dictionary_entries(m->dictionary.dict) >= statsd.dictionary_max_unique) { if(!(m->options & STATSD_METRIC_OPTION_COLLECTION_FULL_LOGGED)) { m->options |= STATSD_METRIC_OPTION_COLLECTION_FULL_LOGGED; collector_info( "STATSD dictionary '%s' reach max of %zu items - try increasing 'dictionaries max unique dimensions' in netdata.conf", m->name, - m->dictionary.unique); + dictionary_entries(m->dictionary.dict)); } } } static inline void statsd_flush_timer_or_histogram(STATSD_METRIC *m, const char *dim, const char *family, const char *units) { - debug(D_STATSD, "flushing %s metric '%s'", dim, m->name); + netdata_log_debug(D_STATSD, "flushing %s metric '%s'", dim, m->name); int updated = 0; if(unlikely(!m->reset && m->count && m->histogram.ext->used > 0)) { @@ -1976,7 +1952,7 @@ static inline void statsd_flush_timer_or_histogram(STATSD_METRIC *m, const char netdata_mutex_unlock(&m->histogram.ext->mutex); - debug(D_STATSD, "STATSD %s metric %s: min " COLLECTED_NUMBER_FORMAT ", max " COLLECTED_NUMBER_FORMAT ", last " COLLECTED_NUMBER_FORMAT ", pcent " COLLECTED_NUMBER_FORMAT ", median " COLLECTED_NUMBER_FORMAT ", stddev " COLLECTED_NUMBER_FORMAT ", sum " COLLECTED_NUMBER_FORMAT, + netdata_log_debug(D_STATSD, "STATSD %s metric %s: min " COLLECTED_NUMBER_FORMAT ", max " COLLECTED_NUMBER_FORMAT ", last " COLLECTED_NUMBER_FORMAT ", pcent " COLLECTED_NUMBER_FORMAT ", median " COLLECTED_NUMBER_FORMAT ", stddev " COLLECTED_NUMBER_FORMAT ", sum " COLLECTED_NUMBER_FORMAT, dim, m->name, m->histogram.ext->last_min, m->histogram.ext->last_max, m->last, m->histogram.ext->last_percentile, m->histogram.ext->last_median, m->histogram.ext->last_stddev, m->histogram.ext->last_sum); m->histogram.ext->zeroed = 0; @@ -2073,7 +2049,7 @@ static inline void link_metric_to_app_dimension(STATSD_APP *app, STATSD_METRIC * } else { if (dim->value_type != STATSD_APP_CHART_DIM_VALUE_TYPE_LAST) - error("STATSD: unsupported value type for dimension '%s' of chart '%s' of app '%s' on metric '%s'", dim->name, chart->id, app->name, m->name); + netdata_log_error("STATSD: unsupported value type for dimension '%s' of chart '%s' of app '%s' on metric '%s'", dim->name, chart->id, app->name, m->name); dim->value_ptr = &m->last; dim->algorithm = statsd_algorithm_for_metric(m); @@ -2090,7 +2066,7 @@ static inline void link_metric_to_app_dimension(STATSD_APP *app, STATSD_METRIC * chart->dimensions_linked_count++; m->options |= STATSD_METRIC_OPTION_USED_IN_APPS; - debug(D_STATSD, "metric '%s' of type %u linked with app '%s', chart '%s', dimension '%s', algorithm '%s'", m->name, m->type, app->name, chart->id, dim->name, rrd_algorithm_name(dim->algorithm)); + netdata_log_debug(D_STATSD, "metric '%s' of type %u linked with app '%s', chart '%s', dimension '%s', algorithm '%s'", m->name, m->type, app->name, chart->id, dim->name, rrd_algorithm_name(dim->algorithm)); } static inline void check_if_metric_is_for_app(STATSD_INDEX *index, STATSD_METRIC *m) { @@ -2099,7 +2075,7 @@ static inline void check_if_metric_is_for_app(STATSD_INDEX *index, STATSD_METRIC STATSD_APP *app; for(app = statsd.apps; app ;app = app->next) { if(unlikely(simple_pattern_matches(app->metrics, m->name))) { - debug(D_STATSD, "metric '%s' matches app '%s'", m->name, app->name); + netdata_log_debug(D_STATSD, "metric '%s' matches app '%s'", m->name, app->name); // the metric should get the options from the app @@ -2213,18 +2189,18 @@ static inline RRDDIM *statsd_add_dim_to_app_chart(STATSD_APP *app, STATSD_APP_CH dim->rd = rrddim_add(chart->st, metric, dim->name, dim->multiplier, dim->divisor, dim->algorithm); if(dim->flags != RRDDIM_FLAG_NONE) dim->rd->flags |= dim->flags; - if(dim->options != RRDDIM_OPTION_NONE) dim->rd->options |= dim->options; + if(dim->options != RRDDIM_OPTION_NONE) dim->rd->collector.options |= dim->options; return dim->rd; } dim->rd = rrddim_add(chart->st, dim->metric, dim->name, dim->multiplier, dim->divisor, dim->algorithm); if(dim->flags != RRDDIM_FLAG_NONE) dim->rd->flags |= dim->flags; - if(dim->options != RRDDIM_OPTION_NONE) dim->rd->options |= dim->options; + if(dim->options != RRDDIM_OPTION_NONE) dim->rd->collector.options |= dim->options; return dim->rd; } static inline void statsd_update_app_chart(STATSD_APP *app, STATSD_APP_CHART *chart) { - debug(D_STATSD, "updating chart '%s' for app '%s'", chart->id, app->name); + netdata_log_debug(D_STATSD, "updating chart '%s' for app '%s'", chart->id, app->name); if(!chart->st) { chart->st = rrdset_create_custom( @@ -2256,22 +2232,22 @@ static inline void statsd_update_app_chart(STATSD_APP *app, STATSD_APP_CHART *ch statsd_add_dim_to_app_chart(app, chart, dim); if (unlikely(dim->value_ptr)) { - debug(D_STATSD, "updating dimension '%s' (%s) of chart '%s' (%s) for app '%s' with value " COLLECTED_NUMBER_FORMAT, dim->name, rrddim_id(dim->rd), chart->id, rrdset_id(chart->st), app->name, *dim->value_ptr); + netdata_log_debug(D_STATSD, "updating dimension '%s' (%s) of chart '%s' (%s) for app '%s' with value " COLLECTED_NUMBER_FORMAT, dim->name, rrddim_id(dim->rd), chart->id, rrdset_id(chart->st), app->name, *dim->value_ptr); rrddim_set_by_pointer(chart->st, dim->rd, *dim->value_ptr); } } } rrdset_done(chart->st); - debug(D_STATSD, "completed update of chart '%s' for app '%s'", chart->id, app->name); + netdata_log_debug(D_STATSD, "completed update of chart '%s' for app '%s'", chart->id, app->name); } static inline void statsd_update_all_app_charts(void) { - // debug(D_STATSD, "updating app charts"); + // netdata_log_debug(D_STATSD, "updating app charts"); STATSD_APP *app; for(app = statsd.apps; app ;app = app->next) { - // debug(D_STATSD, "updating charts for app '%s'", app->name); + // netdata_log_debug(D_STATSD, "updating charts for app '%s'", app->name); STATSD_APP_CHART *chart; for(chart = app->charts; chart ;chart = chart->next) { @@ -2281,7 +2257,7 @@ static inline void statsd_update_all_app_charts(void) { } } - // debug(D_STATSD, "completed update of app charts"); + // netdata_log_debug(D_STATSD, "completed update of app charts"); } const char *statsd_metric_type_string(STATSD_METRIC_TYPE type) { @@ -2307,23 +2283,28 @@ static inline void statsd_flush_index_metrics(STATSD_INDEX *index, void (*flush_ if(unlikely(is_metric_checked(m))) break; if(unlikely(!(m->options & STATSD_METRIC_OPTION_CHECKED_IN_APPS))) { - log_access("NEW STATSD METRIC '%s': '%s'", statsd_metric_type_string(m->type), m->name); + netdata_log_access("NEW STATSD METRIC '%s': '%s'", statsd_metric_type_string(m->type), m->name); check_if_metric_is_for_app(index, m); m->options |= STATSD_METRIC_OPTION_CHECKED_IN_APPS; } if(unlikely(!(m->options & STATSD_METRIC_OPTION_PRIVATE_CHART_CHECKED))) { if(unlikely(statsd.private_charts >= statsd.max_private_charts_hard)) { - debug(D_STATSD, "STATSD: metric '%s' will not be charted, because the hard limit of the maximum number of charts has been reached.", m->name); - collector_info("STATSD: metric '%s' will not be charted, because the hard limit of the maximum number of charts (%zu) has been reached. Increase the number of charts by editing netdata.conf, [statsd] section.", m->name, statsd.max_private_charts_hard); + netdata_log_debug(D_STATSD, "STATSD: metric '%s' will not be charted, because the hard limit of the maximum number " + "of charts has been reached.", m->name); + + collector_info("STATSD: metric '%s' will not be charted, because the hard limit of the maximum number " + "of charts (%u) has been reached. Increase the number of charts by editing netdata.conf, " + "[statsd] section.", m->name, statsd.max_private_charts_hard); + m->options &= ~STATSD_METRIC_OPTION_PRIVATE_CHART_ENABLED; } else { if (simple_pattern_matches(statsd.charts_for, m->name)) { - debug(D_STATSD, "STATSD: metric '%s' will be charted.", m->name); + netdata_log_debug(D_STATSD, "STATSD: metric '%s' will be charted.", m->name); m->options |= STATSD_METRIC_OPTION_PRIVATE_CHART_ENABLED; } else { - debug(D_STATSD, "STATSD: metric '%s' will not be charted.", m->name); + netdata_log_debug(D_STATSD, "STATSD: metric '%s' will not be charted.", m->name); m->options &= ~STATSD_METRIC_OPTION_PRIVATE_CHART_ENABLED; } } @@ -2366,7 +2347,7 @@ static void statsd_main_cleanup(void *data) { if (statsd.collection_threads_status) { int i; for (i = 0; i < statsd.threads; i++) { - netdata_spinlock_lock(&statsd.collection_threads_status[i].spinlock); + spinlock_lock(&statsd.collection_threads_status[i].spinlock); if(statsd.collection_threads_status[i].running) { collector_info("STATSD: stopping data collection thread %d...", i + 1); netdata_thread_cancel(statsd.collection_threads_status[i].thread); @@ -2374,7 +2355,7 @@ static void statsd_main_cleanup(void *data) { else { collector_info("STATSD: data collection thread %d found stopped.", i + 1); } - netdata_spinlock_unlock(&statsd.collection_threads_status[i].spinlock); + spinlock_unlock(&statsd.collection_threads_status[i].spinlock); } } @@ -2466,7 +2447,6 @@ void *statsd_main(void *ptr) { config_get(CONFIG_SECTION_STATSD, "create private charts for metrics matching", "*"), NULL, SIMPLE_PATTERN_EXACT, true); statsd.max_private_charts_hard = (size_t)config_get_number(CONFIG_SECTION_STATSD, "max private charts hard limit", (long long)statsd.max_private_charts_hard); - statsd.private_charts_rrd_history_entries = (int)config_get_number(CONFIG_SECTION_STATSD, "private charts history", default_rrd_history_entries); statsd.decimal_detail = (collected_number)config_get_number(CONFIG_SECTION_STATSD, "decimal detail", (long long int)statsd.decimal_detail); statsd.tcp_idle_timeout = (size_t) config_get_number(CONFIG_SECTION_STATSD, "disconnect idle tcp clients after seconds", (long long int)statsd.tcp_idle_timeout); statsd.private_charts_hidden = (unsigned int)config_get_boolean(CONFIG_SECTION_STATSD, "private charts hidden", statsd.private_charts_hidden); @@ -2549,7 +2529,7 @@ void *statsd_main(void *ptr) { statsd.collection_threads_status[i].max_sockets = max_sockets / statsd.threads; char tag[NETDATA_THREAD_TAG_MAX + 1]; snprintfz(tag, NETDATA_THREAD_TAG_MAX, "STATSD_IN[%d]", i + 1); - netdata_spinlock_init(&statsd.collection_threads_status[i].spinlock); + spinlock_init(&statsd.collection_threads_status[i].spinlock); netdata_thread_create(&statsd.collection_threads_status[i].thread, tag, NETDATA_THREAD_OPTION_DEFAULT, statsd_collector_thread, &statsd.collection_threads_status[i]); } |