diff options
Diffstat (limited to '')
-rw-r--r-- | collectors/tc.plugin/Makefile.am | 20 | ||||
l--------- | src/collectors/tc.plugin/README.md (renamed from collectors/tc.plugin/README.md) | 0 | ||||
-rw-r--r-- | src/collectors/tc.plugin/integrations/tc_qos_classes.md (renamed from collectors/tc.plugin/integrations/tc_qos_classes.md) | 10 | ||||
-rw-r--r-- | src/collectors/tc.plugin/metadata.yaml (renamed from collectors/tc.plugin/metadata.yaml) | 0 | ||||
-rw-r--r-- | src/collectors/tc.plugin/plugin_tc.c (renamed from collectors/tc.plugin/plugin_tc.c) | 117 | ||||
-rwxr-xr-x | src/collectors/tc.plugin/tc-qos-helper.sh.in (renamed from collectors/tc.plugin/tc-qos-helper.sh.in) | 2 |
6 files changed, 54 insertions, 95 deletions
diff --git a/collectors/tc.plugin/Makefile.am b/collectors/tc.plugin/Makefile.am deleted file mode 100644 index 9bc6cf2de..000000000 --- a/collectors/tc.plugin/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later - -AUTOMAKE_OPTIONS = subdir-objects -MAINTAINERCLEANFILES = $(srcdir)/Makefile.in - -CLEANFILES = \ - tc-qos-helper.sh \ - $(NULL) - -include $(top_srcdir)/build/subst.inc -SUFFIXES = .in - -dist_plugins_SCRIPTS = \ - tc-qos-helper.sh \ - $(NULL) - -dist_noinst_DATA = \ - tc-qos-helper.sh.in \ - README.md \ - $(NULL) diff --git a/collectors/tc.plugin/README.md b/src/collectors/tc.plugin/README.md index 2a20ff262..2a20ff262 120000 --- a/collectors/tc.plugin/README.md +++ b/src/collectors/tc.plugin/README.md diff --git a/collectors/tc.plugin/integrations/tc_qos_classes.md b/src/collectors/tc.plugin/integrations/tc_qos_classes.md index 7a6650660..2928110b3 100644 --- a/collectors/tc.plugin/integrations/tc_qos_classes.md +++ b/src/collectors/tc.plugin/integrations/tc_qos_classes.md @@ -1,9 +1,9 @@ <!--startmeta -custom_edit_url: "https://github.com/netdata/netdata/edit/master/collectors/tc.plugin/README.md" -meta_yaml: "https://github.com/netdata/netdata/edit/master/collectors/tc.plugin/metadata.yaml" +custom_edit_url: "https://github.com/netdata/netdata/edit/master/src/collectors/tc.plugin/README.md" +meta_yaml: "https://github.com/netdata/netdata/edit/master/src/collectors/tc.plugin/metadata.yaml" sidebar_label: "tc QoS classes" learn_status: "Published" -learn_rel_path: "Data Collection/Linux Systems/Network" +learn_rel_path: "Collecting Metrics/Linux Systems/Network" most_popular: False message: "DO NOT EDIT THIS FILE DIRECTLY, IT IS GENERATED BY THE COLLECTOR'S metadata.yaml FILE" endmeta--> @@ -117,7 +117,7 @@ The file format is a modified INI syntax. The general structure is: option3 = some third value ``` You can edit the configuration file using the `edit-config` script from the -Netdata [config directory](https://github.com/netdata/netdata/blob/master/docs/configure/nodes.md#the-netdata-config-directory). +Netdata [config directory](/docs/netdata-agent/configuration/README.md#the-netdata-config-directory). ```bash cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata @@ -127,7 +127,7 @@ sudo ./edit-config netdata.conf -<details><summary>Config option</summary> +<details open><summary>Config option</summary> | Name | Description | Default | Required | |:----|:-----------|:-------|:--------:| diff --git a/collectors/tc.plugin/metadata.yaml b/src/collectors/tc.plugin/metadata.yaml index f4039a8c5..f4039a8c5 100644 --- a/collectors/tc.plugin/metadata.yaml +++ b/src/collectors/tc.plugin/metadata.yaml diff --git a/collectors/tc.plugin/plugin_tc.c b/src/collectors/tc.plugin/plugin_tc.c index eae70453f..da2a39194 100644 --- a/collectors/tc.plugin/plugin_tc.c +++ b/src/collectors/tc.plugin/plugin_tc.c @@ -206,41 +206,54 @@ static inline void tc_device_classes_cleanup(struct tc_device *d) { } static inline void tc_device_commit(struct tc_device *d) { - static int enable_new_interfaces = -1, enable_bytes = -1, enable_packets = -1, enable_dropped = -1, enable_tokens = -1, enable_ctokens = -1, enabled_all_classes_qdiscs = -1; + static int enable_tokens = -1, enable_ctokens = -1, enabled_all_classes_qdiscs = -1; - if(unlikely(enable_new_interfaces == -1)) { - enable_new_interfaces = config_get_boolean_ondemand("plugin:tc", "enable new interfaces detected at runtime", CONFIG_BOOLEAN_YES); - enable_bytes = config_get_boolean_ondemand("plugin:tc", "enable traffic charts for all interfaces", CONFIG_BOOLEAN_AUTO); - enable_packets = config_get_boolean_ondemand("plugin:tc", "enable packets charts for all interfaces", CONFIG_BOOLEAN_AUTO); - enable_dropped = config_get_boolean_ondemand("plugin:tc", "enable dropped charts for all interfaces", CONFIG_BOOLEAN_AUTO); + if(unlikely(enabled_all_classes_qdiscs == -1)) { enable_tokens = config_get_boolean_ondemand("plugin:tc", "enable tokens charts for all interfaces", CONFIG_BOOLEAN_NO); enable_ctokens = config_get_boolean_ondemand("plugin:tc", "enable ctokens charts for all interfaces", CONFIG_BOOLEAN_NO); enabled_all_classes_qdiscs = config_get_boolean_ondemand("plugin:tc", "enable show all classes and qdiscs for all interfaces", CONFIG_BOOLEAN_NO); } if(unlikely(d->enabled == (char)-1)) { + d->enabled = CONFIG_BOOLEAN_YES; + d->enabled_bytes = CONFIG_BOOLEAN_YES; + d->enabled_packets = CONFIG_BOOLEAN_YES; + d->enabled_dropped = CONFIG_BOOLEAN_YES; + d->enabled_tokens = enable_tokens; + d->enabled_ctokens = enable_ctokens; + d->enabled_all_classes_qdiscs = enabled_all_classes_qdiscs; + + char var_name[CONFIG_MAX_NAME + 1]; - snprintfz(var_name, CONFIG_MAX_NAME, "qos for %s", string2str(d->id)); - d->enabled = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_new_interfaces); + snprintfz(var_name, CONFIG_MAX_NAME, "qos for %s", string2str(d->id)); + if (config_exists("plugin:tc", var_name)) + d->enabled = (char)config_get_boolean_ondemand("plugin:tc", var_name, d->enabled); snprintfz(var_name, CONFIG_MAX_NAME, "traffic chart for %s", string2str(d->id)); - d->enabled_bytes = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_bytes); + if (config_exists("plugin:tc", var_name)) + d->enabled_bytes = (char)config_get_boolean_ondemand("plugin:tc", var_name, d->enabled_bytes); snprintfz(var_name, CONFIG_MAX_NAME, "packets chart for %s", string2str(d->id)); - d->enabled_packets = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_packets); + if (config_exists("plugin:tc", var_name)) + d->enabled_packets = (char)config_get_boolean_ondemand("plugin:tc", var_name, d->enabled_packets); snprintfz(var_name, CONFIG_MAX_NAME, "dropped packets chart for %s", string2str(d->id)); - d->enabled_dropped = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_dropped); + if (config_exists("plugin:tc", var_name)) + d->enabled_dropped = (char)config_get_boolean_ondemand("plugin:tc", var_name, d->enabled_dropped); snprintfz(var_name, CONFIG_MAX_NAME, "tokens chart for %s", string2str(d->id)); - d->enabled_tokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_tokens); + if (config_exists("plugin:tc", var_name)) + d->enabled_tokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, d->enabled_tokens); snprintfz(var_name, CONFIG_MAX_NAME, "ctokens chart for %s", string2str(d->id)); - d->enabled_ctokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_ctokens); + if (config_exists("plugin:tc", var_name)) + d->enabled_ctokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, d->enabled_ctokens); snprintfz(var_name, CONFIG_MAX_NAME, "show all classes for %s", string2str(d->id)); - d->enabled_all_classes_qdiscs = (char)config_get_boolean_ondemand("plugin:tc", var_name, enabled_all_classes_qdiscs); + if (config_exists("plugin:tc", var_name)) + d->enabled_all_classes_qdiscs = + (char)config_get_boolean_ondemand("plugin:tc", var_name, d->enabled_all_classes_qdiscs); } // we only need to add leaf classes @@ -379,27 +392,10 @@ static inline void tc_device_commit(struct tc_device *d) { return; } - netdata_log_debug(D_TC_LOOP, "TC: evaluating TC device '%s'. enabled = %d/%d (bytes: %d/%d, packets: %d/%d, dropped: %d/%d, tokens: %d/%d, ctokens: %d/%d, all_classes_qdiscs: %d/%d), classes: (bytes = %llu, packets = %llu, dropped = %llu, tokens = %llu, ctokens = %llu).", - string2str(d->name?d->name:d->id), - d->enabled, enable_new_interfaces, - d->enabled_bytes, enable_bytes, - d->enabled_packets, enable_packets, - d->enabled_dropped, enable_dropped, - d->enabled_tokens, enable_tokens, - d->enabled_ctokens, enable_ctokens, - d->enabled_all_classes_qdiscs, enabled_all_classes_qdiscs, - bytes_sum, - packets_sum, - dropped_sum, - tokens_sum, - ctokens_sum - ); - // -------------------------------------------------------------------- // bytes - if(d->enabled_bytes == CONFIG_BOOLEAN_YES || (d->enabled_bytes == CONFIG_BOOLEAN_AUTO && - (bytes_sum || netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) { + if (d->enabled_bytes == CONFIG_BOOLEAN_YES || d->enabled_bytes == CONFIG_BOOLEAN_AUTO) { d->enabled_bytes = CONFIG_BOOLEAN_YES; if(unlikely(!d->st_bytes)) { @@ -453,9 +449,7 @@ static inline void tc_device_commit(struct tc_device *d) { // -------------------------------------------------------------------- // packets - if(d->enabled_packets == CONFIG_BOOLEAN_YES || (d->enabled_packets == CONFIG_BOOLEAN_AUTO && - (packets_sum || - netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) { + if (d->enabled_packets == CONFIG_BOOLEAN_YES || d->enabled_packets == CONFIG_BOOLEAN_AUTO) { d->enabled_packets = CONFIG_BOOLEAN_YES; if(unlikely(!d->st_packets)) { @@ -517,9 +511,7 @@ static inline void tc_device_commit(struct tc_device *d) { // -------------------------------------------------------------------- // dropped - if(d->enabled_dropped == CONFIG_BOOLEAN_YES || (d->enabled_dropped == CONFIG_BOOLEAN_AUTO && - (dropped_sum || - netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) { + if (d->enabled_dropped == CONFIG_BOOLEAN_YES || d->enabled_dropped == CONFIG_BOOLEAN_AUTO) { d->enabled_dropped = CONFIG_BOOLEAN_YES; if(unlikely(!d->st_dropped)) { @@ -581,9 +573,7 @@ static inline void tc_device_commit(struct tc_device *d) { // -------------------------------------------------------------------- // tokens - if(d->enabled_tokens == CONFIG_BOOLEAN_YES || (d->enabled_tokens == CONFIG_BOOLEAN_AUTO && - (tokens_sum || - netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) { + if (d->enabled_tokens == CONFIG_BOOLEAN_YES || d->enabled_tokens == CONFIG_BOOLEAN_AUTO) { d->enabled_tokens = CONFIG_BOOLEAN_YES; if(unlikely(!d->st_tokens)) { @@ -646,9 +636,7 @@ static inline void tc_device_commit(struct tc_device *d) { // -------------------------------------------------------------------- // ctokens - if(d->enabled_ctokens == CONFIG_BOOLEAN_YES || (d->enabled_ctokens == CONFIG_BOOLEAN_AUTO && - (ctokens_sum || - netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) { + if (d->enabled_ctokens == CONFIG_BOOLEAN_YES || d->enabled_ctokens == CONFIG_BOOLEAN_AUTO) { d->enabled_ctokens = CONFIG_BOOLEAN_YES; if(unlikely(!d->st_ctokens)) { @@ -846,28 +834,23 @@ static inline void tc_split_words(char *str, char **words, int max_words) { while(i < max_words) words[i++] = NULL; } -static pid_t tc_child_pid = 0; +static POPEN_INSTANCE *tc_child_instance = NULL; -static void tc_main_cleanup(void *ptr) { - worker_unregister(); +static void tc_main_cleanup(void *pptr) { + struct netdata_static_thread *static_thread = CLEANUP_FUNCTION_GET_PTR(pptr); + if(!static_thread) return; + worker_unregister(); tc_device_index_destroy(); - struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr; static_thread->enabled = NETDATA_MAIN_THREAD_EXITING; collector_info("cleaning up..."); - if(tc_child_pid) { - collector_info("TC: killing with SIGTERM tc-qos-helper process %d", tc_child_pid); - if(killpid(tc_child_pid) != -1) { - siginfo_t info; - - collector_info("TC: waiting for tc plugin child process pid %d to exit...", tc_child_pid); - netdata_waitid(P_PID, (id_t) tc_child_pid, &info, WEXITED); - } - - tc_child_pid = 0; + if(tc_child_instance) { + collector_info("TC: stopping the running tc-qos-helper script"); + int code = spawn_popen_wait(tc_child_instance); (void)code; + tc_child_instance = NULL; } static_thread->enabled = NETDATA_MAIN_THREAD_EXITED; @@ -892,6 +875,8 @@ static void tc_main_cleanup(void *ptr) { #endif void *tc_main(void *ptr) { + CLEANUP_FUNCTION_REGISTER(tc_main_cleanup) cleanup_ptr = ptr; + worker_register("TC"); worker_register_job_name(WORKER_TC_CLASS, "class"); worker_register_job_name(WORKER_TC_BEGIN, "begin"); @@ -909,7 +894,6 @@ void *tc_main(void *ptr) { worker_register_job_custom_metric(WORKER_TC_CLASSES, "number of classes", "classes", WORKER_METRIC_ABSOLUTE); tc_device_index_init(); - netdata_thread_cleanup_push(tc_main_cleanup, ptr); char command[FILENAME_MAX + 1]; char *words[PLUGINSD_MAX_WORDS] = { NULL }; @@ -931,21 +915,20 @@ void *tc_main(void *ptr) { char *tc_script = config_get("plugin:tc", "script to run to get tc values", command); while(service_running(SERVICE_COLLECTORS)) { - FILE *fp_child_input, *fp_child_output; struct tc_device *device = NULL; struct tc_class *class = NULL; snprintfz(command, TC_LINE_MAX, "exec %s %d", tc_script, localhost->rrd_update_every); netdata_log_debug(D_TC_LOOP, "executing '%s'", command); - fp_child_output = netdata_popen(command, (pid_t *)&tc_child_pid, &fp_child_input); - if(unlikely(!fp_child_output)) { + tc_child_instance = spawn_popen_run(command); + if(!tc_child_instance) { collector_error("TC: Cannot popen(\"%s\", \"r\").", command); goto cleanup; } char buffer[TC_LINE_MAX+1] = ""; - while(fgets(buffer, TC_LINE_MAX, fp_child_output) != NULL) { + while(fgets(buffer, TC_LINE_MAX, tc_child_instance->child_stdout_fp) != NULL) { if(unlikely(!service_running(SERVICE_COLLECTORS))) break; buffer[TC_LINE_MAX] = '\0'; @@ -1036,10 +1019,8 @@ void *tc_main(void *ptr) { // netdata_log_debug(D_TC_LOOP, "END line"); if(likely(device)) { - netdata_thread_disable_cancelability(); tc_device_commit(device); // tc_device_free(device); - netdata_thread_enable_cancelability(); } device = NULL; @@ -1154,8 +1135,8 @@ void *tc_main(void *ptr) { } // fgets() failed or loop broke - int code = netdata_pclose(fp_child_input, fp_child_output, (pid_t)tc_child_pid); - tc_child_pid = 0; + int code = spawn_popen_kill(tc_child_instance); + tc_child_instance = NULL; if(unlikely(device)) { // tc_device_free(device); @@ -1177,7 +1158,5 @@ void *tc_main(void *ptr) { } cleanup: ; // added semi-colon to prevent older gcc error: label at end of compound statement - worker_unregister(); - netdata_thread_cleanup_pop(1); return NULL; } diff --git a/collectors/tc.plugin/tc-qos-helper.sh.in b/src/collectors/tc.plugin/tc-qos-helper.sh.in index 3298c39a3..d7aad40f4 100755 --- a/collectors/tc.plugin/tc-qos-helper.sh.in +++ b/src/collectors/tc.plugin/tc-qos-helper.sh.in @@ -154,7 +154,7 @@ if [ ! -d "${fireqos_run_dir}" ]; then warning "Although FireQOS is installed on this system as '${fireqos}', I cannot find/read its installation configuration at '${fireqos_exec_dir}/install.config'." fi else - warning "FireQOS is not installed on this system. Use FireQOS to apply traffic QoS and expose the class names to netdata. Check https://github.com/netdata/netdata/tree/master/collectors/tc.plugin#tcplugin" + warning "FireQOS is not installed on this system. Use FireQOS to apply traffic QoS and expose the class names to netdata. Check https://github.com/netdata/netdata/tree/master/src/collectors/tc.plugin#tcplugin" fi fi |