diff options
Diffstat (limited to 'src/collectors/timex.plugin')
-rw-r--r-- | src/collectors/timex.plugin/integrations/timex.md | 6 | ||||
-rw-r--r-- | src/collectors/timex.plugin/plugin_timex.c | 26 |
2 files changed, 20 insertions, 12 deletions
diff --git a/src/collectors/timex.plugin/integrations/timex.md b/src/collectors/timex.plugin/integrations/timex.md index ce0e0ed2c..98bcbe10b 100644 --- a/src/collectors/timex.plugin/integrations/timex.md +++ b/src/collectors/timex.plugin/integrations/timex.md @@ -103,7 +103,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/netdata-agent/configuration.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 @@ -113,7 +113,7 @@ sudo ./edit-config netdata.conf At least one option ('clock synchronization state', 'time offset') needs to be enabled for this collector to run. -<details><summary>Config options</summary> +<details open><summary>Config options</summary> | Name | Description | Default | Required | |:----|:-----------|:-------|:--------:| @@ -129,7 +129,7 @@ At least one option ('clock synchronization state', 'time offset') needs to be e A basic configuration example. -<details><summary>Config</summary> +<details open><summary>Config</summary> ```yaml [plugin:timex] diff --git a/src/collectors/timex.plugin/plugin_timex.c b/src/collectors/timex.plugin/plugin_timex.c index 025b699a1..6e200c425 100644 --- a/src/collectors/timex.plugin/plugin_timex.c +++ b/src/collectors/timex.plugin/plugin_timex.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "daemon/common.h" -#include "libnetdata/os.h" +#include "libnetdata/os/os.h" #define PLUGIN_TIMEX_NAME "timex.plugin" @@ -30,25 +30,26 @@ struct status_codes { {NULL, 0, NULL}, }; -static void timex_main_cleanup(void *ptr) +static void timex_main_cleanup(void *pptr) { - worker_unregister(); + struct netdata_static_thread *static_thread = CLEANUP_FUNCTION_GET_PTR(pptr); + if(!static_thread) return; - struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr; static_thread->enabled = NETDATA_MAIN_THREAD_EXITING; netdata_log_info("cleaning up..."); + worker_unregister(); static_thread->enabled = NETDATA_MAIN_THREAD_EXITED; } void *timex_main(void *ptr) { + CLEANUP_FUNCTION_REGISTER(timex_main_cleanup) cleanup_ptr = ptr; + worker_register("TIMEX"); worker_register_job_name(0, "clock check"); - netdata_thread_cleanup_push(timex_main_cleanup, ptr); - int update_every = (int)config_get_number(CONFIG_SECTION_TIMEX, "update every", 10); if (update_every < localhost->rrd_update_every) update_every = localhost->rrd_update_every; @@ -62,18 +63,26 @@ void *timex_main(void *ptr) } usec_t step = update_every * USEC_PER_SEC; + usec_t real_step = USEC_PER_SEC; heartbeat_t hb; heartbeat_init(&hb); while (service_running(SERVICE_COLLECTORS)) { worker_is_idle(); - heartbeat_next(&hb, step); + heartbeat_next(&hb, USEC_PER_SEC); + + if (real_step < step) { + real_step += USEC_PER_SEC; + continue; + } + real_step = USEC_PER_SEC; + worker_is_busy(0); struct timex timex_buf = {}; int sync_state = 0; static int prev_sync_state = 0; - sync_state = ADJUST_TIMEX(&timex_buf); + sync_state = os_adjtimex(&timex_buf); int non_seq_failure = (sync_state == -1 && prev_sync_state != -1); prev_sync_state = sync_state; @@ -171,6 +180,5 @@ void *timex_main(void *ptr) } exit: - netdata_thread_cleanup_pop(1); return NULL; } |