@cryptotaxi247 / netdata-1 / commits / 06300b1e4

timex: this plugin enables timex plugin for non-linux systems (#12489)

* timex: this plugin enables timex plugin for non-linux system * refactoring and fixing PR comments * move OS specific macros to libnetdata * Update README.md Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud> Co-authored-by: Tina Luedtke <kickoke@users.noreply.github.com>

Suraj Neupane committed Mar 24, 2022 at 12:58 UTC 06300b1e42ca623e3b54f6dffeddb2506e3a0213
5 files changed +22 -4
CMakeLists.txt
+1 -1
@@ -1134,6 +1134,7 @@ list(APPEND NETDATA_COMMON_LIBRARIES ${PROTOBUF_LIBRARIES})
1134 list(APPEND NETDATA_COMMON_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS})
1135 list(APPEND NETDATA_COMMON_CFLAGS ${PROTOBUF_CFLAGS_OTHER})
1136 list(APPEND NETDATA_FILES ${ACLK_ALWAYS_BUILD})
1137 +list(APPEND NETDATA_FILES ${TIMEX_PLUGIN_FILES})
1138 list(APPEND NETDATA_FILES ${ACLK_FILES} ${ACLK_PROTO_BUILT_SRCS} ${ACLK_PROTO_BUILT_HDRS})
1139 list(APPEND NETDATA_FILES ${ACLK_COMMON_FILES})
1140 include_directories(BEFORE ${CMAKE_SOURCE_DIR}/aclk/aclk-schemas)
@@ -1151,7 +1152,6 @@ IF(LINUX)
1152 add_executable(netdata config.h ${NETDATA_FILES}
1153 ${CGROUPS_PLUGIN_FILES}
1154 ${DISKSPACE_PLUGIN_FILES}
1154 - ${TIMEX_PLUGIN_FILES}
1155 ${PROC_PLUGIN_FILES}
1156 ${TC_PLUGIN_FILES}
1157 )
Makefile.am
+1 -1
@@ -864,6 +864,7 @@ NETDATA_FILES = \
864 $(ACLK_COMMON_FILES) \
865 $(ACLK_FILES) \
866 $(SPAWN_PLUGIN_FILES) \
867 + $(TIMEX_PLUGIN_FILES) \
868 $(NULL)
869
870 if FREEBSD
@@ -885,7 +886,6 @@ if LINUX
886 daemon/static_threads_linux.c \
887 $(CGROUPS_PLUGIN_FILES) \
888 $(DISKSPACE_PLUGIN_FILES) \
888 - $(TIMEX_PLUGIN_FILES) \
889 $(PROC_PLUGIN_FILES) \
890 $(TC_PLUGIN_FILES) \
891 $(NULL)
collectors/timex.plugin/plugin_timex.c
+3 -2
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "daemon/common.h"
4 -#include "sys/timex.h"
4 +#include "libnetdata/os.h"
5
6 #define PLUGIN_TIMEX_NAME "timex.plugin"
7
@@ -44,7 +44,8 @@ void *timex_main(void *ptr)
44
45 struct timex timex_buf = {};
46 int sync_state = 0;
47 - sync_state = adjtimex(&timex_buf);
47 +
48 + sync_state = ADJUST_TIMEX(&timex_buf);
49
50 collected_number divisor = USEC_PER_MS;
51 if (timex_buf.status & STA_NANO)
daemon/static_threads.c
+10
@@ -11,8 +11,18 @@ extern void *health_main(void *ptr);
11 extern void *pluginsd_main(void *ptr);
12 extern void *service_main(void *ptr);
13 extern void *statsd_main(void *ptr);
14 +extern void *timex_main(void *ptr);
15
16 const struct netdata_static_thread static_threads_common[] = {
17 + {
18 + .name = "PLUGIN[timex]",
19 + .config_section = CONFIG_SECTION_PLUGINS,
20 + .config_name = "timex",
21 + .enabled = 1,
22 + .thread = NULL,
23 + .init_routine = NULL,
24 + .start_routine = timex_main
25 + },
26 {
27 .name = "PLUGIN[check]",
28 .config_section = CONFIG_SECTION_PLUGINS,
libnetdata/os.h
+7
@@ -57,4 +57,11 @@ extern pid_t get_system_pid_max(void);
57 extern unsigned int system_hz;
58 extern void get_system_HZ(void);
59
60 +#include <sys/timex.h>
61 +#if defined(__FreeBSD__) || defined(__APPLE__)
62 +#define ADJUST_TIMEX(x) ntp_adjtime(x)
63 +#else
64 +#define ADJUST_TIMEX(x) adjtimex(x)
65 +#endif
66 +
67 #endif //NETDATA_OS_H