From: Pavel Rochnyak Date: Thu, 5 Jul 2018 03:41:18 +0000 (+0700) Subject: Merge pull request #2631 from DanCech/tagged-carbon X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=e9c6bf25649bb8ead1bf383e51426b6552f08251;hp=e53ab7ffa52682fa59882ebaeb4489315d3c3832 Merge pull request #2631 from DanCech/tagged-carbon Graphite 1.1+ tag support --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 35c80209..9cae9c2c 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1908,6 +1908,11 @@ plugin below on how matches are defined. If the B or B options are set to B, B blocks are optional. +=item B I + +Sets the interval (in seconds) in which the values will be collected from this +URL. By default the global B setting will be used. + =item B I The B option sets the overall timeout for HTTP requests to B, in @@ -2104,6 +2109,11 @@ Use I as the plugin instance when submitting values. May be overridden by B option inside B blocks. Defaults to an empty string (no plugin instance). +=item B I + +Sets the interval (in seconds) in which the values will be collected from this +URL. By default the global B setting will be used. + =item B I I If an XPath expression references namespaces, they must be specified diff --git a/src/curl.c b/src/curl.c index 4bfd1e4d..4925ad09 100644 --- a/src/curl.c +++ b/src/curl.c @@ -78,18 +78,13 @@ struct web_page_s /* {{{ */ size_t buffer_fill; web_match_t *matches; - - web_page_t *next; }; /* }}} */ /* - * Global variables; - */ -static web_page_t *pages_g; - -/* * Private functions */ +static int cc_read_page(user_data_t *ud); + static size_t cc_curl_callback(void *buf, /* {{{ */ size_t size, size_t nmemb, void *user_data) { web_page_t *wp; @@ -137,8 +132,9 @@ static void cc_web_match_free(web_match_t *wm) /* {{{ */ sfree(wm); } /* }}} void cc_web_match_free */ -static void cc_web_page_free(web_page_t *wp) /* {{{ */ +static void cc_web_page_free(void *arg) /* {{{ */ { + web_page_t *wp = (web_page_t *)arg; if (wp == NULL) return; @@ -161,7 +157,6 @@ static void cc_web_page_free(web_page_t *wp) /* {{{ */ sfree(wp->buffer); cc_web_match_free(wp->matches); - cc_web_page_free(wp->next); sfree(wp); } /* }}} void cc_web_page_free */ @@ -400,6 +395,7 @@ static int cc_page_init_curl(web_page_t *wp) /* {{{ */ static int cc_config_add_page(oconfig_item_t *ci) /* {{{ */ { + cdtime_t interval = 0; web_page_t *page; int status; @@ -464,6 +460,8 @@ static int cc_config_add_page(oconfig_item_t *ci) /* {{{ */ status = cc_config_append_string("Header", &page->headers, child); else if (strcasecmp("Post", child->key) == 0) status = cf_util_get_string(child, &page->post_body); + else if (strcasecmp("Interval", child->key) == 0) + status = cf_util_get_cdtime(child, &interval); else if (strcasecmp("Timeout", child->key) == 0) status = cf_util_get_int(child, &page->timeout); else if (strcasecmp("Statistics", child->key) == 0) { @@ -507,17 +505,15 @@ static int cc_config_add_page(oconfig_item_t *ci) /* {{{ */ return status; } - /* Add the new page to the linked list */ - if (pages_g == NULL) - pages_g = page; - else { - web_page_t *prev; + /* If all went well, register this page for reading */ + char *cb_name = ssnprintf_alloc("curl-%s-%s", page->instance, page->url); - prev = pages_g; - while (prev->next != NULL) - prev = prev->next; - prev->next = page; - } + plugin_register_complex_read(/* group = */ NULL, cb_name, cc_read_page, + interval, + &(user_data_t){ + .data = page, .free_func = cc_web_page_free, + }); + sfree(cb_name); return 0; } /* }}} int cc_config_add_page */ @@ -556,10 +552,6 @@ static int cc_config(oconfig_item_t *ci) /* {{{ */ static int cc_init(void) /* {{{ */ { - if (pages_g == NULL) { - INFO("curl plugin: No pages have been defined."); - return -1; - } curl_global_init(CURL_GLOBAL_SSL); return 0; } /* }}} int cc_init */ @@ -608,8 +600,16 @@ static void cc_submit_response_time(const web_page_t *wp, /* {{{ */ plugin_dispatch_values(&vl); } /* }}} void cc_submit_response_time */ -static int cc_read_page(web_page_t *wp) /* {{{ */ +static int cc_read_page(user_data_t *ud) /* {{{ */ { + + if ((ud == NULL) || (ud->data == NULL)) { + ERROR("curl plugin: cc_read_page: Invalid user data."); + return -1; + } + + web_page_t *wp = (web_page_t *)ud->data; + int status; cdtime_t start = 0; @@ -666,25 +666,7 @@ static int cc_read_page(web_page_t *wp) /* {{{ */ return 0; } /* }}} int cc_read_page */ -static int cc_read(void) /* {{{ */ -{ - for (web_page_t *wp = pages_g; wp != NULL; wp = wp->next) - cc_read_page(wp); - - return 0; -} /* }}} int cc_read */ - -static int cc_shutdown(void) /* {{{ */ -{ - cc_web_page_free(pages_g); - pages_g = NULL; - - return 0; -} /* }}} int cc_shutdown */ - void module_register(void) { plugin_register_complex_config("curl", cc_config); plugin_register_init("curl", cc_init); - plugin_register_read("curl", cc_read); - plugin_register_shutdown("curl", cc_shutdown); } /* void module_register */ diff --git a/src/curl_json.c b/src/curl_json.c index 5d96cbd5..dedfed05 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -97,7 +97,6 @@ struct cj_s /* {{{ */ char *cacert; struct curl_slist *headers; char *post_body; - cdtime_t interval; int timeout; curl_stats_t *stats; @@ -623,9 +622,6 @@ static int cj_init_curl(cj_t *db) /* {{{ */ #ifdef HAVE_CURLOPT_TIMEOUT_MS if (db->timeout >= 0) curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS, (long)db->timeout); - else if (db->interval > 0) - curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS, - (long)CDTIME_T_TO_MS(db->interval)); else curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS, (long)CDTIME_T_TO_MS(plugin_get_interval())); @@ -638,6 +634,7 @@ static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */ { cj_t *db; int status = 0; + cdtime_t interval = 0; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("curl_json plugin: The `URL' block " @@ -698,7 +695,7 @@ static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */ else if (strcasecmp("Key", child->key) == 0) status = cj_config_add_key(db, child); else if (strcasecmp("Interval", child->key) == 0) - status = cf_util_get_cdtime(child, &db->interval); + status = cf_util_get_cdtime(child, &interval); else if (strcasecmp("Timeout", child->key) == 0) status = cf_util_get_int(child, &db->timeout); else if (strcasecmp("Statistics", child->key) == 0) { @@ -736,8 +733,7 @@ static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */ cb_name = ssnprintf_alloc("curl_json-%s-%s", db->instance, db->url ? db->url : db->sock); - plugin_register_complex_read(/* group = */ NULL, cb_name, cj_read, - /* interval = */ db->interval, + plugin_register_complex_read(/* group = */ NULL, cb_name, cj_read, interval, &(user_data_t){ .data = db, .free_func = cj_free, }); @@ -815,9 +811,6 @@ static void cj_submit_impl(cj_t *db, cj_key_t *key, value_t *value) /* {{{ */ sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, key->type, sizeof(vl.type)); - if (db->interval > 0) - vl.interval = db->interval; - plugin_dispatch_values(&vl); } /* }}} int cj_submit_impl */ diff --git a/src/curl_xml.c b/src/curl_xml.c index 654bb671..0bed05a5 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -823,6 +823,8 @@ static int cx_config_add_url(oconfig_item_t *ci) /* {{{ */ return status; } + cdtime_t interval = 0; + /* Fill the `cx_t' structure.. */ for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -853,6 +855,8 @@ static int cx_config_add_url(oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string(child, &db->post_body); else if (strcasecmp("Namespace", child->key) == 0) status = cx_config_add_namespace(db, child); + else if (strcasecmp("Interval", child->key) == 0) + status = cf_util_get_cdtime(child, &interval); else if (strcasecmp("Timeout", child->key) == 0) status = cf_util_get_int(child, &db->timeout); else if (strcasecmp("Statistics", child->key) == 0) { @@ -891,7 +895,7 @@ static int cx_config_add_url(oconfig_item_t *ci) /* {{{ */ char *cb_name = ssnprintf_alloc("curl_xml-%s-%s", db->instance, db->url); plugin_register_complex_read(/* group = */ "curl_xml", cb_name, cx_read, - /* interval = */ 0, + /* interval = */ interval, &(user_data_t){ .data = db, .free_func = cx_free, }); diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index d9038002..8750bef8 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -381,6 +381,7 @@ static int dispatch_block_plugin(oconfig_item_t *ci) { /* default to the global interval set before loading this plugin */ ctx.interval = cf_get_default_interval(); + ctx.name = strdup(name); old_ctx = plugin_set_ctx(ctx); status = plugin_load(name, /* flags = */ false); diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 92e1ab26..73d7c841 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -292,10 +292,10 @@ static int register_callback(llist_t **list, /* {{{ */ old_cf = le->value; le->value = cf; - WARNING("plugin: register_callback: " - "a callback named `%s' already exists - " - "overwriting the old entry!", - name); + P_WARNING("register_callback: " + "a callback named `%s' already exists - " + "overwriting the old entry!", + name); destroy_callback(old_cf); sfree(key); @@ -315,7 +315,7 @@ static void log_list_callbacks(llist_t **list, /* {{{ */ n = llist_size(*list); if (n == 0) { - INFO("%s [none]", comment); + INFO("%s: [none]", comment); return; } @@ -713,25 +713,8 @@ plugin_value_list_clone(value_list_t const *vl_orig) /* {{{ */ vl->time = cdtime(); /* Fill in the interval from the thread context, if it is zero. */ - if (vl->interval == 0) { - plugin_ctx_t ctx = plugin_get_ctx(); - - if (ctx.interval != 0) - vl->interval = ctx.interval; - else { - char name[6 * DATA_MAX_NAME_LEN]; - FORMAT_VL(name, sizeof(name), vl); - ERROR("plugin_value_list_clone: Unable to determine " - "interval from context for " - "value list \"%s\". " - "This indicates a broken plugin. " - "Please report this problem to the " - "collectd mailing list or at " - ".", - name); - vl->interval = cf_get_default_interval(); - } - } + if (vl->interval == 0) + vl->interval = plugin_get_interval(); return vl; } /* }}} value_list_t *plugin_value_list_clone */ @@ -1114,9 +1097,9 @@ static int plugin_insert_read(read_func_t *rf) { le = llist_search(read_list, rf->rf_name); if (le != NULL) { pthread_mutex_unlock(&read_lock); - WARNING("The read function \"%s\" is already registered. " - "Check for duplicates in your configuration!", - rf->rf_name); + P_WARNING("The read function \"%s\" is already registered. " + "Check for duplicates in your configuration!", + rf->rf_name); return EINVAL; } @@ -1162,6 +1145,7 @@ int plugin_register_read(const char *name, int (*callback)(void)) { rf->rf_name = strdup(name); rf->rf_type = RF_SIMPLE; rf->rf_interval = plugin_get_interval(); + rf->rf_ctx.interval = rf->rf_interval; status = plugin_insert_read(rf); if (status != 0) { @@ -1203,6 +1187,7 @@ int plugin_register_complex_read(const char *group, const char *name, } rf->rf_ctx = plugin_get_ctx(); + rf->rf_ctx.interval = rf->rf_interval; status = plugin_insert_read(rf); if (status != 0) { @@ -2298,7 +2283,7 @@ const data_set_t *plugin_get_ds(const char *name) { data_set_t *ds; if (data_sets == NULL) { - ERROR("plugin_get_ds: No data sets are defined yet."); + P_ERROR("plugin_get_ds: No data sets are defined yet."); return NULL; } @@ -2529,6 +2514,8 @@ cdtime_t plugin_get_interval(void) { if (interval > 0) return interval; + P_ERROR("plugin_get_interval: Unable to determine Interval from context."); + return cf_get_default_interval(); } /* cdtime_t plugin_get_interval */ diff --git a/src/dbi.c b/src/dbi.c index 1909d8ca..fe9bc516 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -64,8 +64,6 @@ struct cdbi_database_s /* {{{ */ char *select_db; char *plugin_name; - cdtime_t interval; - char *driver; char *host; cdbi_driver_option_t *driver_options; @@ -267,6 +265,7 @@ static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ { + cdtime_t interval = 0; cdbi_database_t *db; int status; @@ -304,7 +303,7 @@ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ else if (strcasecmp("Host", child->key) == 0) status = cf_util_get_string(child, &db->host); else if (strcasecmp("Interval", child->key) == 0) - status = cf_util_get_cdtime(child, &db->interval); + status = cf_util_get_cdtime(child, &interval); else if (strcasecmp("Plugin", child->key) == 0) status = cf_util_get_string(child, &db->plugin_name); else { @@ -370,7 +369,7 @@ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ /* group = */ NULL, /* name = */ name ? name : db->name, /* callback = */ cdbi_read_database, - /* interval = */ (db->interval > 0) ? db->interval : 0, + /* interval = */ interval, &(user_data_t){ .data = db, }); @@ -550,8 +549,7 @@ static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */ status = udb_query_prepare_result( q, prep_area, (db->host ? db->host : hostname_g), /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "dbi", - db->name, column_names, column_num, - /* interval = */ (db->interval > 0) ? db->interval : 0); + db->name, column_names, column_num); if (status != 0) { ERROR("dbi plugin: udb_query_prepare_result failed with status %i.", diff --git a/src/dpdkevents.c b/src/dpdkevents.c index 9970be0c..2a44b2c1 100644 --- a/src/dpdkevents.c +++ b/src/dpdkevents.c @@ -419,8 +419,12 @@ static int dpdk_events_config(oconfig_item_t *ci) { static int dpdk_helper_link_status_get(dpdk_helper_ctx_t *phc) { dpdk_events_ctx_t *ec = DPDK_EVENTS_CTX_GET(phc); - /* get Link Status values from DPDK */ +/* get Link Status values from DPDK */ +#if RTE_VERSION < RTE_VERSION_NUM(18, 05, 0, 0) uint8_t nb_ports = rte_eth_dev_count(); +#else + uint8_t nb_ports = rte_eth_dev_count_avail(); +#endif if (nb_ports == 0) { DPDK_CHILD_LOG("dpdkevent-helper: No DPDK ports available. " "Check bound devices to DPDK driver.\n"); diff --git a/src/modbus.c b/src/modbus.c index bb9eaa0f..0a4f40ca 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -129,7 +129,6 @@ struct mb_host_s /* {{{ */ int port; /* for Modbus/TCP */ int baudrate; /* for Modbus/RTU */ mb_conntype_t conntype; - cdtime_t interval; mb_slave_t *slaves; size_t slaves_num; @@ -252,15 +251,11 @@ static int mb_submit(mb_host_t *host, mb_slave_t *slave, /* {{{ */ if ((host == NULL) || (slave == NULL) || (data == NULL)) return EINVAL; - if (host->interval == 0) - host->interval = plugin_get_interval(); - if (slave->instance[0] == 0) snprintf(slave->instance, sizeof(slave->instance), "slave_%i", slave->id); vl.values = &value; vl.values_len = 1; - vl.interval = host->interval; sstrncpy(vl.host, host->host, sizeof(vl.host)); sstrncpy(vl.plugin, "modbus", sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, slave->instance, sizeof(vl.plugin_instance)); @@ -952,6 +947,7 @@ static int mb_config_add_slave(mb_host_t *host, oconfig_item_t *ci) /* {{{ */ static int mb_config_add_host(oconfig_item_t *ci) /* {{{ */ { + cdtime_t interval = 0; mb_host_t *host; int status; @@ -992,7 +988,7 @@ static int mb_config_add_host(oconfig_item_t *ci) /* {{{ */ } else if (strcasecmp("Baudrate", child->key) == 0) status = cf_util_get_int(child, &host->baudrate); else if (strcasecmp("Interval", child->key) == 0) - status = cf_util_get_cdtime(child, &host->interval); + status = cf_util_get_cdtime(child, &interval); else if (strcasecmp("Slave", child->key) == 0) /* Don't set status: Gracefully continue if a slave fails. */ mb_config_add_slave(host, child); @@ -1033,7 +1029,7 @@ static int mb_config_add_host(oconfig_item_t *ci) /* {{{ */ plugin_register_complex_read(/* group = */ NULL, name, /* callback = */ mb_read, - /* interval = */ host->interval, + /* interval = */ interval, &(user_data_t){ .data = host, .free_func = host_free, }); diff --git a/src/oracle.c b/src/oracle.c index 4bca8387..1b17d9c3 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -550,8 +550,7 @@ static int o_read_database_query(o_database_t *db, /* {{{ */ status = udb_query_prepare_result( q, prep_area, (db->host != NULL) ? db->host : hostname_g, /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "oracle", - db->name, column_names, column_num, - /* interval = */ 0); + db->name, column_names, column_num); if (status != 0) { ERROR("oracle plugin: o_read_database_query (%s, %s): " "udb_query_prepare_result failed.", diff --git a/src/postgresql.c b/src/postgresql.c index 7c140e0a..ae887a17 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -125,8 +125,6 @@ typedef struct { /* make sure we don't access the database object in parallel */ pthread_mutex_t db_lock; - cdtime_t interval; - /* writer "caching" settings */ cdtime_t commit_interval; cdtime_t next_commit; @@ -237,8 +235,6 @@ static c_psql_database_t *c_psql_database_new(const char *name) { pthread_mutex_init(&db->db_lock, /* attrs = */ NULL); - db->interval = 0; - db->commit_interval = 0; db->next_commit = 0; db->expire_delay = 0; @@ -431,8 +427,7 @@ static PGresult *c_psql_exec_query_params(c_psql_database_t *db, udb_query_t *q, break; case C_PSQL_PARAM_INTERVAL: snprintf(interval, sizeof(interval), "%.3f", - (db->interval > 0) ? CDTIME_T_TO_DOUBLE(db->interval) - : plugin_get_interval()); + CDTIME_T_TO_DOUBLE(plugin_get_interval())); params[i] = interval; break; case C_PSQL_PARAM_INSTANCE: @@ -548,7 +543,7 @@ static int c_psql_exec_query(c_psql_database_t *db, udb_query_t *q, status = udb_query_prepare_result( q, prep_area, host, (db->plugin_name != NULL) ? db->plugin_name : "postgresql", db->instance, - column_names, (size_t)column_num, db->interval); + column_names, (size_t)column_num); if (0 != status) { log_err("udb_query_prepare_result failed with status %i.", status); @@ -1123,6 +1118,7 @@ static int c_psql_config_writer(oconfig_item_t *ci) { static int c_psql_config_database(oconfig_item_t *ci) { c_psql_database_t *db; + cdtime_t interval = 0; char cb_name[DATA_MAX_NAME_LEN]; static bool have_flush; @@ -1163,7 +1159,7 @@ static int c_psql_config_database(oconfig_item_t *ci) { config_add_writer(c, writers, writers_num, &db->writers, &db->writers_num); else if (0 == strcasecmp(c->key, "Interval")) - cf_util_get_cdtime(c, &db->interval); + cf_util_get_cdtime(c, &interval); else if (strcasecmp("CommitInterval", c->key) == 0) cf_util_get_cdtime(c, &db->commit_interval); else if (strcasecmp("ExpireDelay", c->key) == 0) @@ -1211,8 +1207,8 @@ static int c_psql_config_database(oconfig_item_t *ci) { if (db->queries_num > 0) { ++db->ref_cnt; - plugin_register_complex_read("postgresql", cb_name, c_psql_read, - /* interval = */ db->interval, &ud); + plugin_register_complex_read("postgresql", cb_name, c_psql_read, interval, + &ud); } if (db->writers_num > 0) { ++db->ref_cnt; diff --git a/src/redis.c b/src/redis.c index 7edd329c..41442b66 100644 --- a/src/redis.c +++ b/src/redis.c @@ -654,8 +654,6 @@ static void redis_read_server_info(redis_node_t *rn) { "total_connections_received", DS_TYPE_DERIVE); redis_handle_info(rn->name, rr->str, "total_operations", NULL, "total_commands_processed", DS_TYPE_DERIVE); - redis_handle_info(rn->name, rr->str, "operations_per_second", NULL, - "instantaneous_ops_per_sec", DS_TYPE_GAUGE); redis_handle_info(rn->name, rr->str, "expired_keys", NULL, "expired_keys", DS_TYPE_DERIVE); redis_handle_info(rn->name, rr->str, "evicted_keys", NULL, "evicted_keys", diff --git a/src/snmp.c b/src/snmp.c index 6c018da7..a86d0853 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -97,7 +97,6 @@ struct host_definition_s { void *sess_handle; c_complain_t complaint; - cdtime_t interval; data_definition_t **data_list; int data_list_len; }; @@ -743,6 +742,7 @@ static int csnmp_config_add_host(oconfig_item_t *ci) { int status = 0; /* Registration stuff. */ + cdtime_t interval = 0; char cb_name[DATA_MAX_NAME_LEN]; hd = calloc(1, sizeof(*hd)); @@ -758,7 +758,6 @@ static int csnmp_config_add_host(oconfig_item_t *ci) { } hd->sess_handle = NULL; - hd->interval = 0; /* These mean that we have not set a timeout or retry value */ hd->timeout = 0; @@ -780,7 +779,7 @@ static int csnmp_config_add_host(oconfig_item_t *ci) { else if (strcasecmp("Collect", option->key) == 0) status = csnmp_config_add_host_collect(hd, option); else if (strcasecmp("Interval", option->key) == 0) - status = cf_util_get_cdtime(option, &hd->interval); + status = cf_util_get_cdtime(option, &interval); else if (strcasecmp("Username", option->key) == 0) status = cf_util_get_string(option, &hd->username); else if (strcasecmp("AuthProtocol", option->key) == 0) @@ -875,7 +874,7 @@ static int csnmp_config_add_host(oconfig_item_t *ci) { snprintf(cb_name, sizeof(cb_name), "snmp-%s", hd->name); status = plugin_register_complex_read( - /* group = */ NULL, cb_name, csnmp_read_host, hd->interval, + /* group = */ NULL, cb_name, csnmp_read_host, interval, &(user_data_t){ .data = hd, .free_func = csnmp_host_definition_destroy, }); @@ -1314,8 +1313,6 @@ static int csnmp_dispatch_table(host_definition_t *host, sstrncpy(vl.plugin, data->plugin_name, sizeof(vl.plugin)); sstrncpy(vl.type, data->type, sizeof(vl.type)); - vl.interval = host->interval; - have_more = 1; while (have_more) { bool suffix_skipped = 0; @@ -2048,8 +2045,6 @@ static int csnmp_read_value(host_definition_t *host, data_definition_t *data) { sstrncpy(vl.plugin_instance, data->plugin_instance.value, sizeof(vl.plugin_instance)); - vl.interval = host->interval; - req = snmp_pdu_create(SNMP_MSG_GET); if (req == NULL) { ERROR("snmp plugin: snmp_pdu_create failed."); @@ -2111,9 +2106,6 @@ static int csnmp_read_host(user_data_t *ud) { host = ud->data; - if (host->interval == 0) - host->interval = plugin_get_interval(); - if (host->sess_handle == NULL) csnmp_host_open_session(host); diff --git a/src/tail.c b/src/tail.c index a6471d83..841b3312 100644 --- a/src/tail.c +++ b/src/tail.c @@ -54,14 +54,17 @@ struct ctail_config_match_s { int flags; char *type; char *type_instance; - cdtime_t interval; latency_config_t latency; }; typedef struct ctail_config_match_s ctail_config_match_t; -static cu_tail_match_t **tail_match_list; -static size_t tail_match_list_num; -static cdtime_t tail_match_list_intervals[255]; +static size_t tail_file_num; + +static int ctail_read(user_data_t *ud); + +static void ctail_match_free(void *arg) { + tail_match_destroy((cu_tail_match_t *)arg); +} /* void ctail_match_free */ static int ctail_config_add_match_dstype(ctail_config_match_t *cm, oconfig_item_t *ci) { @@ -136,7 +139,7 @@ static int ctail_config_add_match_dstype(ctail_config_match_t *cm, static int ctail_config_add_match(cu_tail_match_t *tm, const char *plugin_name, const char *plugin_instance, - oconfig_item_t *ci, cdtime_t interval) { + oconfig_item_t *ci) { ctail_config_match_t cm = {0}; int status; @@ -194,7 +197,7 @@ static int ctail_config_add_match(cu_tail_match_t *tm, const char *plugin_name, status = tail_match_add_match_simple( tm, cm.regex, cm.excluderegex, cm.flags, (plugin_name != NULL) ? plugin_name : "tail", plugin_instance, cm.type, - cm.type_instance, cm.latency, interval); + cm.type_instance, cm.latency); if (status != 0) ERROR("tail plugin: tail_match_add_match_simple failed."); @@ -239,8 +242,7 @@ static int ctail_config_add_file(oconfig_item_t *ci) { else if (strcasecmp("Interval", option->key) == 0) cf_util_get_cdtime(option, &interval); else if (strcasecmp("Match", option->key) == 0) { - status = ctail_config_add_match(tm, plugin_name, plugin_instance, option, - interval); + status = ctail_config_add_match(tm, plugin_name, plugin_instance, option); if (status == 0) num_matches++; /* Be mild with failed matches.. */ @@ -261,23 +263,15 @@ static int ctail_config_add_file(oconfig_item_t *ci) { ci->values[0].value.string); tail_match_destroy(tm); return -1; - } else { - cu_tail_match_t **temp; - - temp = realloc(tail_match_list, - sizeof(cu_tail_match_t *) * (tail_match_list_num + 1)); - if (temp == NULL) { - ERROR("tail plugin: realloc failed."); - tail_match_destroy(tm); - return -1; - } - - tail_match_list = temp; - tail_match_list[tail_match_list_num] = tm; - tail_match_list_intervals[tail_match_list_num] = interval; - tail_match_list_num++; } + char str[255]; + snprintf(str, sizeof(str), "tail-%zu", tail_file_num++); + + plugin_register_complex_read( + NULL, str, ctail_read, interval, + &(user_data_t){.data = tm, .free_func = ctail_match_free}); + return 0; } /* int ctail_config_add_file */ @@ -307,40 +301,6 @@ static int ctail_read(user_data_t *ud) { return 0; } /* int ctail_read */ -static int ctail_init(void) { - char str[255]; - - if (tail_match_list_num == 0) { - WARNING("tail plugin: File list is empty. Returning an error."); - return -1; - } - - for (size_t i = 0; i < tail_match_list_num; i++) { - snprintf(str, sizeof(str), "tail-%zu", i); - - plugin_register_complex_read(NULL, str, ctail_read, - tail_match_list_intervals[i], - &(user_data_t){ - .data = tail_match_list[i], - }); - } - - return 0; -} /* int ctail_init */ - -static int ctail_shutdown(void) { - for (size_t i = 0; i < tail_match_list_num; i++) { - tail_match_destroy(tail_match_list[i]); - tail_match_list[i] = NULL; - } - sfree(tail_match_list); - tail_match_list_num = 0; - - return 0; -} /* int ctail_shutdown */ - void module_register(void) { plugin_register_complex_config("tail", ctail_config); - plugin_register_init("tail", ctail_init); - plugin_register_shutdown("tail", ctail_shutdown); } /* void module_register */ diff --git a/src/tail_csv.c b/src/tail_csv.c index be7cd40f..48f3d743 100644 --- a/src/tail_csv.c +++ b/src/tail_csv.c @@ -50,7 +50,6 @@ struct instance_definition_s { cu_tail_t *tail; metric_definition_t **metric_list; size_t metric_list_len; - cdtime_t interval; ssize_t time_from; struct instance_definition_s *next; }; @@ -77,7 +76,6 @@ static int tcsv_submit(instance_definition_t *id, metric_definition_t *md, sstrncpy(vl.type_instance, md->instance, sizeof(vl.type_instance)); vl.time = t; - vl.interval = id->interval; return plugin_dispatch_values(&vl); } @@ -418,6 +416,7 @@ static int tcsv_config_add_file(oconfig_item_t *ci) { int status = 0; /* Registration variables */ + cdtime_t interval = 0; char cb_name[DATA_MAX_NAME_LEN]; id = calloc(1, sizeof(*id)); @@ -436,9 +435,6 @@ static int tcsv_config_add_file(oconfig_item_t *ci) { return status; } - /* Use default interval. */ - id->interval = plugin_get_interval(); - for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *option = ci->children + i; status = 0; @@ -448,7 +444,7 @@ static int tcsv_config_add_file(oconfig_item_t *ci) { else if (strcasecmp("Collect", option->key) == 0) status = tcsv_config_add_instance_collect(id, option); else if (strcasecmp("Interval", option->key) == 0) - cf_util_get_cdtime(option, &id->interval); + cf_util_get_cdtime(option, &interval); else if (strcasecmp("TimeFrom", option->key) == 0) status = tcsv_config_get_index(option, &id->time_from); else if (strcasecmp("Plugin", option->key) == 0) @@ -484,7 +480,7 @@ static int tcsv_config_add_file(oconfig_item_t *ci) { snprintf(cb_name, sizeof(cb_name), "tail_csv/%s", id->path); status = plugin_register_complex_read( - NULL, cb_name, tcsv_read, id->interval, + NULL, cb_name, tcsv_read, interval, &(user_data_t){ .data = id, .free_func = tcsv_instance_definition_destroy, }); diff --git a/src/utils_db_query.c b/src/utils_db_query.c index 54ddb046..0279a471 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -84,8 +84,6 @@ struct udb_query_preparation_area_s /* {{{ */ char *plugin; char *db_name; - cdtime_t interval; - udb_result_preparation_area_t *result_prep_areas; }; /* }}} */ @@ -188,9 +186,6 @@ static int udb_result_submit(udb_result_t *r, /* {{{ */ } } - if (q_area->interval > 0) - vl.interval = q_area->interval; - sstrncpy(vl.host, q_area->host, sizeof(vl.host)); sstrncpy(vl.plugin, q_area->plugin, sizeof(vl.plugin)); sstrncpy(vl.type, r->type, sizeof(vl.type)); @@ -835,8 +830,6 @@ void udb_query_finish_result(udb_query_t const *q, /* {{{ */ sfree(prep_area->plugin); sfree(prep_area->db_name); - prep_area->interval = 0; - for (r = q->results, r_area = prep_area->result_prep_areas; r != NULL; r = r->next, r_area = r_area->next) { /* this may happen during error conditions of the caller */ @@ -897,7 +890,7 @@ int udb_query_prepare_result(udb_query_t const *q, /* {{{ */ udb_query_preparation_area_t *prep_area, const char *host, const char *plugin, const char *db_name, char **column_names, - size_t column_num, cdtime_t interval) { + size_t column_num) { udb_result_preparation_area_t *r_area; udb_result_t *r; int status; @@ -910,7 +903,6 @@ int udb_query_prepare_result(udb_query_t const *q, /* {{{ */ assert(prep_area->host == NULL); assert(prep_area->plugin == NULL); assert(prep_area->db_name == NULL); - assert(prep_area->interval == 0); #endif prep_area->column_num = column_num; @@ -918,8 +910,6 @@ int udb_query_prepare_result(udb_query_t const *q, /* {{{ */ prep_area->plugin = strdup(plugin); prep_area->db_name = strdup(db_name); - prep_area->interval = interval; - if ((prep_area->host == NULL) || (prep_area->plugin == NULL) || (prep_area->db_name == NULL)) { P_ERROR("Query `%s': Prepare failed: Out of memory.", q->name); diff --git a/src/utils_db_query.h b/src/utils_db_query.h index 4d6129a1..f173204c 100644 --- a/src/utils_db_query.h +++ b/src/utils_db_query.h @@ -71,7 +71,7 @@ int udb_query_prepare_result(udb_query_t const *q, udb_query_preparation_area_t *prep_area, const char *host, const char *plugin, const char *db_name, char **column_names, - size_t column_num, cdtime_t interval); + size_t column_num); int udb_query_handle_result(udb_query_t const *q, udb_query_preparation_area_t *prep_area, char **column_values); diff --git a/src/utils_dpdk.c b/src/utils_dpdk.c index 1d4668f3..aee97917 100644 --- a/src/utils_dpdk.c +++ b/src/utils_dpdk.c @@ -853,7 +853,11 @@ uint128_t str_to_uint128(const char *str, int len) { } uint8_t dpdk_helper_eth_dev_count(void) { +#if RTE_VERSION < RTE_VERSION_NUM(18, 05, 0, 0) uint8_t ports = rte_eth_dev_count(); +#else + uint8_t ports = rte_eth_dev_count_avail(); +#endif if (ports == 0) { ERROR( "%s:%d: No DPDK ports available. Check bound devices to DPDK driver.\n", diff --git a/src/utils_tail_match.c b/src/utils_tail_match.c index 5134a6e1..ccab5ace 100644 --- a/src/utils_tail_match.c +++ b/src/utils_tail_match.c @@ -43,7 +43,6 @@ struct cu_tail_match_simple_s { char plugin_instance[DATA_MAX_NAME_LEN]; char type[DATA_MAX_NAME_LEN]; char type_instance[DATA_MAX_NAME_LEN]; - cdtime_t interval; latency_config_t latency_config; }; typedef struct cu_tail_match_simple_s cu_tail_match_simple_t; @@ -57,10 +56,7 @@ struct cu_tail_match_match_s { typedef struct cu_tail_match_match_s cu_tail_match_match_t; struct cu_tail_match_s { - int flags; cu_tail_t *tail; - - cdtime_t interval; cu_tail_match_match_t *matches; size_t matches_num; }; @@ -92,7 +88,6 @@ static int simple_submit_match(cu_match_t *match, void *user_data) { sstrncpy(vl.type, data->type, sizeof(vl.type)); sstrncpy(vl.type_instance, data->type_instance, sizeof(vl.type_instance)); - vl.interval = data->interval; plugin_dispatch_values(&vl); match_value_reset(match_value); @@ -111,7 +106,6 @@ static int latency_submit_match(cu_match_t *match, void *user_data) { sstrncpy(vl.plugin, data->plugin, sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, data->plugin_instance, sizeof(vl.plugin_instance)); - vl.interval = data->interval; vl.time = cdtime(); /* Submit percentiles */ @@ -248,8 +242,6 @@ int tail_match_add_match(cu_tail_match_t *obj, cu_match_t *match, obj->matches = temp; obj->matches_num++; - DEBUG("tail_match_add_match interval %lf", - CDTIME_T_TO_DOUBLE(((cu_tail_match_simple_t *)user_data)->interval)); temp = obj->matches + (obj->matches_num - 1); temp->match = match; @@ -264,8 +256,7 @@ int tail_match_add_match_simple(cu_tail_match_t *obj, const char *regex, const char *excluderegex, int ds_type, const char *plugin, const char *plugin_instance, const char *type, const char *type_instance, - const latency_config_t latency_cfg, - const cdtime_t interval) { + const latency_config_t latency_cfg) { cu_match_t *match; cu_tail_match_simple_t *user_data; int status; @@ -290,8 +281,6 @@ int tail_match_add_match_simple(cu_tail_match_t *obj, const char *regex, sstrncpy(user_data->type_instance, type_instance, sizeof(user_data->type_instance)); - user_data->interval = interval; - if ((ds_type & UTILS_MATCH_DS_TYPE_GAUGE) && (ds_type & UTILS_MATCH_CF_GAUGE_DIST)) { status = latency_config_copy(&user_data->latency_config, latency_cfg); diff --git a/src/utils_tail_match.h b/src/utils_tail_match.h index 03b70e93..2d4c2531 100644 --- a/src/utils_tail_match.h +++ b/src/utils_tail_match.h @@ -80,9 +80,8 @@ void tail_match_destroy(cu_tail_match_t *obj); * When `tail_match_destroy' is called the `user_data' pointer is freed using * the `free_user_data' callback - if it is not NULL. * When using this interface the `tail_match' module doesn't dispatch any - * values - * itself - all that has to happen in either the match-callbacks or the - * submit_match callback. + * values itself - all that has to happen in either the match-callbacks or + * the submit_match callback. * * RETURN VALUE * Zero upon success, non-zero otherwise. @@ -98,14 +97,13 @@ int tail_match_add_match(cu_tail_match_t *obj, cu_match_t *match, * tail_match_add_match_simple * * DESCRIPTION - * A simplified version of `tail_match_add_match'. The regular expressen - * `regex' - * must match a number, which is then dispatched according to `ds_type'. See - * the `match_create_simple' function in utils_match.h for a description how - * this flag effects calculation of a new value. + * A simplified version of `tail_match_add_match'. The regular expression + * `regex' must match a number, which is then dispatched according to + * `ds_type'. + * See the `match_create_simple' function in utils_match.h for a description + * how this flag effects calculation of a new value. * The values gathered are dispatched by the tail_match module in this case. - * The - * passed `plugin', `plugin_instance', `type', and `type_instance' are + * The passed `plugin', `plugin_instance', `type', and `type_instance' are * directly used when submitting these values. * With excluderegex it is possible to exlude lines from the match. * The `latency_cfg' specifies configuration for submitting latency. @@ -117,8 +115,7 @@ int tail_match_add_match_simple(cu_tail_match_t *obj, const char *regex, const char *excluderegex, int ds_type, const char *plugin, const char *plugin_instance, const char *type, const char *type_instance, - const latency_config_t latency_cfg, - const cdtime_t interval); + const latency_config_t latency_cfg); /* * NAME @@ -130,8 +127,7 @@ int tail_match_add_match_simple(cu_tail_match_t *obj, const char *regex, * added `utils_match' objects. * After all lines have been read and processed, the submit_match callback is * called or, in case of tail_match_add_match_simple, the data is dispatched - * to - * the daemon directly. + * to the daemon directly. * * RETURN VALUE * Zero on success, nonzero on failure.