diff --git a/CMakeLists.txt b/CMakeLists.txt
index e72554a31b..f26b744632 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,22 +57,15 @@ SET(MACOS   False)
 
 # Detect the operating system
 IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
-    SET(TARGET_OS_NAME "macos")
-    SET(TARGET_OS 3)
     SET(MACOS True)
 ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
-    SET(TARGET_OS_NAME "freebsd")
-    SET(TARGET_OS 2)
     SET(FREEBSD True)
 ELSE()
-    SET(TARGET_OS_NAME "linux")
-    SET(TARGET_OS 1)
     SET(LINUX True)
 ENDIF()
 
 # show the operating system on the console
-message(STATUS "operating system: ${TARGET_OS_NAME} (TARGET_OS=${TARGET_OS})")
-
+message(STATUS "system name: ${CMAKE_SYSTEM_NAME}")
 
 # -----------------------------------------------------------------------------
 # Detect libuuid
@@ -430,7 +423,6 @@ set(APPS_PLUGIN_FILES
 
 set(CHECKS_PLUGIN_FILES
         collectors/checks.plugin/plugin_checks.c
-        collectors/checks.plugin/plugin_checks.h
         )
 
 set(FREEBSD_PLUGIN_FILES
@@ -455,7 +447,6 @@ set(HEALTH_PLUGIN_FILES
 
 set(IDLEJITTER_PLUGIN_FILES
         collectors/idlejitter.plugin/plugin_idlejitter.c
-        collectors/idlejitter.plugin/plugin_idlejitter.h
         )
 
 set(CGROUPS_PLUGIN_FILES
@@ -468,12 +459,10 @@ set(CGROUP_NETWORK_FILES
         )
 
 set(DISKSPACE_PLUGIN_FILES
-        collectors/diskspace.plugin/plugin_diskspace.h
         collectors/diskspace.plugin/plugin_diskspace.c
         )
 
 set(TIMEX_PLUGIN_FILES
-        collectors/timex.plugin/plugin_timex.h
         collectors/timex.plugin/plugin_timex.c
         )
 
@@ -585,7 +574,6 @@ set(PROC_PLUGIN_FILES
 
 set(TC_PLUGIN_FILES
         collectors/tc.plugin/plugin_tc.c
-        collectors/tc.plugin/plugin_tc.h
         )
 
 set(MACOS_PLUGIN_FILES
@@ -626,7 +614,6 @@ set(REGISTRY_PLUGIN_FILES
 
 set(STATSD_PLUGIN_FILES
         collectors/statsd.plugin/statsd.c
-        collectors/statsd.plugin/statsd.h
         )
 
 set(RRD_PLUGIN_FILES
@@ -928,7 +915,8 @@ set(DAEMON_FILES
         daemon/signals.c
         daemon/signals.h
         daemon/service.c
-        daemon/service.h
+        daemon/static_threads.c
+        daemon/static_threads.h
         daemon/commands.c
         daemon/commands.h
         daemon/unit_test.c
@@ -997,7 +985,6 @@ include_directories(AFTER .)
 
 add_definitions(
         -DHAVE_CONFIG_H
-        -DTARGET_OS=${TARGET_OS}
         -DCACHE_DIR="/var/cache/netdata"
         -DCONFIG_DIR="/etc/netdata"
         -DLIBCONFIG_DIR="/usr/lib/netdata/conf.d"
@@ -1186,7 +1173,9 @@ include_directories(BEFORE ${CMAKE_SOURCE_DIR}/mqtt_websockets/c-rbuf/include)
 # netdata
 
 IF(LINUX)
+    list(APPEND NETDATA_FILES daemon/static_threads_linux.c)
     list(APPEND NETDATA_COMMON_LIBRARIES rt)
+
     add_executable(netdata config.h ${NETDATA_FILES}
             ${CGROUPS_PLUGIN_FILES}
             ${DISKSPACE_PLUGIN_FILES}
@@ -1204,6 +1193,8 @@ IF(LINUX)
     SET(ENABLE_PLUGIN_SLABINFO True)
 
 ELSEIF(FREEBSD)
+    list(APPEND NETDATA_FILES daemon/static_threads_freebsd.c)
+
     add_executable(netdata config.h ${NETDATA_FILES} ${FREEBSD_PLUGIN_FILES})
     target_link_libraries (netdata libnetdata ${NETDATA_COMMON_LIBRARIES})
     target_include_directories(netdata PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS})
@@ -1215,6 +1206,8 @@ ELSEIF(FREEBSD)
     SET(ENABLE_PLUGIN_EBPF False)
 
 ELSEIF(MACOS)
+    list(APPEND NETDATA_FILES daemon/static_threads_macos.c)
+
     add_executable(netdata config.h ${NETDATA_FILES} ${MACOS_PLUGIN_FILES})
     target_link_libraries (netdata libnetdata ${NETDATA_COMMON_LIBRARIES} ${IOKIT} ${FOUNDATION})
     target_include_directories(netdata PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS})
diff --git a/Makefile.am b/Makefile.am
index 7c699ce7c1..d64361711a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -201,7 +201,6 @@ APPS_PLUGIN_FILES = \
 
 CHECKS_PLUGIN_FILES = \
     collectors/checks.plugin/plugin_checks.c \
-    collectors/checks.plugin/plugin_checks.h \
     $(NULL)
 
 FREEBSD_PLUGIN_FILES = \
@@ -271,7 +270,6 @@ endif
 
 IDLEJITTER_PLUGIN_FILES = \
     collectors/idlejitter.plugin/plugin_idlejitter.c \
-    collectors/idlejitter.plugin/plugin_idlejitter.h \
     $(NULL)
 
 CGROUPS_PLUGIN_FILES = \
@@ -285,12 +283,10 @@ CGROUP_NETWORK_FILES = \
     $(NULL)
 
 DISKSPACE_PLUGIN_FILES = \
-    collectors/diskspace.plugin/plugin_diskspace.h \
     collectors/diskspace.plugin/plugin_diskspace.c \
     $(NULL)
 
 TIMEX_PLUGIN_FILES = \
-    collectors/timex.plugin/plugin_timex.h \
     collectors/timex.plugin/plugin_timex.c \
     $(NULL)
 
@@ -413,7 +409,6 @@ PROC_PLUGIN_FILES = \
 
 TC_PLUGIN_FILES = \
     collectors/tc.plugin/plugin_tc.c \
-    collectors/tc.plugin/plugin_tc.h \
     $(NULL)
 
 MACOS_PLUGIN_FILES = \
@@ -571,7 +566,6 @@ REGISTRY_PLUGIN_FILES = \
 
 STATSD_PLUGIN_FILES = \
     collectors/statsd.plugin/statsd.c \
-    collectors/statsd.plugin/statsd.h \
     $(NULL)
 
 WEB_PLUGIN_FILES = \
@@ -869,7 +863,8 @@ DAEMON_FILES = \
     daemon/signals.c \
     daemon/signals.h \
     daemon/service.c \
-    daemon/service.h \
+    daemon/static_threads.h \
+    daemon/static_threads.c \
     daemon/commands.c \
     daemon/commands.h \
     daemon/unit_test.c \
@@ -904,25 +899,27 @@ NETDATA_FILES = \
 
 if FREEBSD
     NETDATA_FILES += \
+        daemon/static_threads_freebsd.c \
         $(FREEBSD_PLUGIN_FILES) \
         $(NULL)
 endif
 
 if MACOS
     NETDATA_FILES += \
+        daemon/static_threads_macos.c \
         $(MACOS_PLUGIN_FILES) \
         $(NULL)
 endif
 
 if LINUX
     NETDATA_FILES += \
+        daemon/static_threads_linux.c \
         $(CGROUPS_PLUGIN_FILES) \
         $(DISKSPACE_PLUGIN_FILES) \
         $(TIMEX_PLUGIN_FILES) \
         $(PROC_PLUGIN_FILES) \
         $(TC_PLUGIN_FILES) \
         $(NULL)
-
 endif
 
 NETDATA_COMMON_LIBS = \
diff --git a/collectors/all.h b/collectors/all.h
index 647ee97746..100a6b0904 100644
--- a/collectors/all.h
+++ b/collectors/all.h
@@ -7,20 +7,8 @@
 
 // netdata internal data collection plugins
 
-#include "checks.plugin/plugin_checks.h"
-#include "freebsd.plugin/plugin_freebsd.h"
-#include "idlejitter.plugin/plugin_idlejitter.h"
-#include "cgroups.plugin/sys_fs_cgroup.h"
-#include "diskspace.plugin/plugin_diskspace.h"
-#include "timex.plugin/plugin_timex.h"
-#include "proc.plugin/plugin_proc.h"
-#include "tc.plugin/plugin_tc.h"
-#include "macos.plugin/plugin_macos.h"
-#include "statsd.plugin/statsd.h"
-
 #include "plugins.d/plugins_d.h"
 
-
 // ----------------------------------------------------------------------------
 // netdata chart priorities
 
diff --git a/collectors/cgroups.plugin/sys_fs_cgroup.h b/collectors/cgroups.plugin/sys_fs_cgroup.h
index 017aa8fb5c..85968a4da7 100644
--- a/collectors/cgroups.plugin/sys_fs_cgroup.h
+++ b/collectors/cgroups.plugin/sys_fs_cgroup.h
@@ -5,21 +5,6 @@
 
 #include "daemon/common.h"
 
-#if (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_CGROUPS \
-    { \
-        .name = "PLUGIN[cgroups]", \
-        .config_section = CONFIG_SECTION_PLUGINS, \
-        .config_name = "cgroups", \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = cgroups_main \
-    },
-
-extern void *cgroups_main(void *ptr);
-
 #define CGROUP_OPTIONS_DISABLED_DUPLICATE   0x00000001
 #define CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE 0x00000002
 #define CGROUP_OPTIONS_IS_UNIFIED           0x00000004
@@ -54,12 +39,6 @@ typedef struct netdata_ebpf_cgroup_shm {
 
 #include "../proc.plugin/plugin_proc.h"
 
-#else // (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_CGROUPS
-
-#endif // (TARGET_OS == OS_LINUX)
-
 extern char *parse_k8s_data(struct label **labels, char *data);
 
 #endif //NETDATA_SYS_FS_CGROUP_H
diff --git a/collectors/checks.plugin/plugin_checks.c b/collectors/checks.plugin/plugin_checks.c
index 1bd053b8c9..312515115f 100644
--- a/collectors/checks.plugin/plugin_checks.c
+++ b/collectors/checks.plugin/plugin_checks.c
@@ -1,8 +1,6 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
-#include "plugin_checks.h"
-
-#ifdef NETDATA_INTERNAL_CHECKS
+#include "daemon/common.h"
 
 static void checks_main_cleanup(void *ptr) {
     struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
@@ -125,5 +123,3 @@ void *checks_main(void *ptr) {
     netdata_thread_cleanup_pop(1);
     return NULL;
 }
-
-#endif // NETDATA_INTERNAL_CHECKS
diff --git a/collectors/checks.plugin/plugin_checks.h b/collectors/checks.plugin/plugin_checks.h
deleted file mode 100644
index c8057253cb..0000000000
--- a/collectors/checks.plugin/plugin_checks.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef NETDATA_PLUGIN_CHECKS_H
-#define NETDATA_PLUGIN_CHECKS_H 1
-
-#include "daemon/common.h"
-
-#ifdef NETDATA_INTERNAL_CHECKS
-
-#define NETDATA_PLUGIN_HOOK_CHECKS \
-    { \
-        .name = "PLUGIN[check]", \
-        .config_section = CONFIG_SECTION_PLUGINS, \
-        .config_name = "checks", \
-        .enabled = 0, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = checks_main \
-    },
-
-extern void *checks_main(void *ptr);
-
-#else // !NETDATA_INTERNAL_CHECKS
-
-#define NETDATA_PLUGIN_HOOK_CHECKS
-
-#endif // NETDATA_INTERNAL_CHECKS
-
-#endif // NETDATA_PLUGIN_CHECKS_H
diff --git a/collectors/diskspace.plugin/plugin_diskspace.c b/collectors/diskspace.plugin/plugin_diskspace.c
index 2e7d18909e..c148e415a6 100644
--- a/collectors/diskspace.plugin/plugin_diskspace.c
+++ b/collectors/diskspace.plugin/plugin_diskspace.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
-#include "plugin_diskspace.h"
+#include "../proc.plugin/plugin_proc.h"
 
 #define PLUGIN_DISKSPACE_NAME "diskspace.plugin"
 
diff --git a/collectors/diskspace.plugin/plugin_diskspace.h b/collectors/diskspace.plugin/plugin_diskspace.h
deleted file mode 100644
index 1f96708796..0000000000
--- a/collectors/diskspace.plugin/plugin_diskspace.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef NETDATA_PLUGIN_PROC_DISKSPACE_H
-#define NETDATA_PLUGIN_PROC_DISKSPACE_H
-
-#include "daemon/common.h"
-
-
-#if (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_DISKSPACE \
-    { \
-        .name = "PLUGIN[diskspace]", \
-        .config_section = CONFIG_SECTION_PLUGINS, \
-        .config_name = "diskspace", \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = diskspace_main \
-    },
-
-extern void *diskspace_main(void *ptr);
-
-#include "../proc.plugin/plugin_proc.h"
-
-#else // (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_DISKSPACE
-
-#endif // (TARGET_OS == OS_LINUX)
-
-
-
-#endif //NETDATA_PLUGIN_PROC_DISKSPACE_H
diff --git a/collectors/ebpf.plugin/ebpf.h b/collectors/ebpf.plugin/ebpf.h
index a59bad031d..d865b06b73 100644
--- a/collectors/ebpf.plugin/ebpf.h
+++ b/collectors/ebpf.plugin/ebpf.h
@@ -27,6 +27,7 @@
 #include "libnetdata/config/appconfig.h"
 #include "libnetdata/ebpf/ebpf.h"
 #include "libnetdata/procfile/procfile.h"
+#include "collectors/cgroups.plugin/sys_fs_cgroup.h"
 #include "daemon/main.h"
 
 #include "ebpf_apps.h"
diff --git a/collectors/freebsd.plugin/plugin_freebsd.h b/collectors/freebsd.plugin/plugin_freebsd.h
index ab46080bed..26f76b6bf8 100644
--- a/collectors/freebsd.plugin/plugin_freebsd.h
+++ b/collectors/freebsd.plugin/plugin_freebsd.h
@@ -5,20 +5,6 @@
 
 #include "daemon/common.h"
 
-#if (TARGET_OS == OS_FREEBSD)
-
-#define NETDATA_PLUGIN_HOOK_FREEBSD \
-    { \
-        .name = "PLUGIN[freebsd]", \
-        .config_section = CONFIG_SECTION_PLUGINS, \
-        .config_name = "freebsd", \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = freebsd_main \
-    },
-
-
 #include <sys/sysctl.h>
 
 #define KILO_FACTOR 1024
@@ -27,8 +13,6 @@
 
 #define MAX_INT_DIGITS 10 // maximum number of digits for int
 
-void *freebsd_main(void *ptr);
-
 extern int freebsd_plugin_init();
 
 extern int do_vm_loadavg(int update_every, usec_t dt);
@@ -65,10 +49,4 @@ extern int do_kstat_zfs_misc_arcstats(int update_every, usec_t dt);
 extern int do_kstat_zfs_misc_zio_trim(int update_every, usec_t dt);
 extern int do_ipfw(int update_every, usec_t dt);
 
-#else // (TARGET_OS == OS_FREEBSD)
-
-#define NETDATA_PLUGIN_HOOK_FREEBSD
-
-#endif // (TARGET_OS == OS_FREEBSD)
-
 #endif /* NETDATA_PLUGIN_FREEBSD_H */
diff --git a/collectors/idlejitter.plugin/plugin_idlejitter.c b/collectors/idlejitter.plugin/plugin_idlejitter.c
index c59541ecba..12ab8601a7 100644
--- a/collectors/idlejitter.plugin/plugin_idlejitter.c
+++ b/collectors/idlejitter.plugin/plugin_idlejitter.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
-#include "plugin_idlejitter.h"
+#include "daemon/common.h"
 
 #define CPU_IDLEJITTER_SLEEP_TIME_MS 20
 
diff --git a/collectors/idlejitter.plugin/plugin_idlejitter.h b/collectors/idlejitter.plugin/plugin_idlejitter.h
deleted file mode 100644
index 6da78a085f..0000000000
--- a/collectors/idlejitter.plugin/plugin_idlejitter.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef NETDATA_PLUGIN_IDLEJITTER_H
-#define NETDATA_PLUGIN_IDLEJITTER_H 1
-
-#include "daemon/common.h"
-
-#define NETDATA_PLUGIN_HOOK_IDLEJITTER \
-    { \
-        .name = "PLUGIN[idlejitter]", \
-        .config_section = CONFIG_SECTION_PLUGINS, \
-        .config_name = "idlejitter", \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = cpuidlejitter_main \
-    },
-
-extern void *cpuidlejitter_main(void *ptr);
-
-#endif /* NETDATA_PLUGIN_IDLEJITTER_H */
diff --git a/collectors/macos.plugin/plugin_macos.h b/collectors/macos.plugin/plugin_macos.h
index a66ec08523..b4c2cf542d 100644
--- a/collectors/macos.plugin/plugin_macos.h
+++ b/collectors/macos.plugin/plugin_macos.h
@@ -1,43 +1,12 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
-
 #ifndef NETDATA_PLUGIN_MACOS_H
 #define NETDATA_PLUGIN_MACOS_H 1
 
 #include "daemon/common.h"
 
-#if (TARGET_OS == OS_MACOS)
-
-#define NETDATA_PLUGIN_HOOK_MACOS \
-    { \
-        .name = "PLUGIN[macos]", \
-        .config_section = CONFIG_SECTION_PLUGINS, \
-        .config_name = "macos", \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = macos_main \
-    },
-
-void *macos_main(void *ptr);
-
-#define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
-
-extern int getsysctl_by_name(const char *name, void *ptr, size_t len);
-
 extern int do_macos_sysctl(int update_every, usec_t dt);
 extern int do_macos_mach_smi(int update_every, usec_t dt);
 extern int do_macos_iokit(int update_every, usec_t dt);
 
-
-#else // (TARGET_OS == OS_MACOS)
-
-#define NETDATA_PLUGIN_HOOK_MACOS
-
-#endif // (TARGET_OS == OS_MACOS)
-
-
-
-
-
 #endif /* NETDATA_PLUGIN_MACOS_H */
diff --git a/collectors/plugins.d/plugins_d.h b/collectors/plugins.d/plugins_d.h
index b9e30e12b1..8f0b028578 100644
--- a/collectors/plugins.d/plugins_d.h
+++ b/collectors/plugins.d/plugins_d.h
@@ -5,18 +5,6 @@
 
 #include "daemon/common.h"
 
-#define NETDATA_PLUGIN_HOOK_PLUGINSD \
-    { \
-        .name = "PLUGINSD", \
-        .config_section = NULL, \
-        .config_name = NULL, \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = pluginsd_main \
-    },
-
-
 #define PLUGINSD_FILE_SUFFIX ".plugin"
 #define PLUGINSD_FILE_SUFFIX_LEN strlen(PLUGINSD_FILE_SUFFIX)
 #define PLUGINSD_CMD_MAX (FILENAME_MAX*2)
@@ -71,8 +59,6 @@ struct plugind {
 
 extern struct plugind *pluginsd_root;
 
-extern void *pluginsd_main(void *ptr);
-
 extern size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int trust_durations);
 extern int pluginsd_split_words(char *str, char **words, int max_words, char *recover_string, char **recover_location, int max_recover);
 
diff --git a/collectors/proc.plugin/plugin_proc.h b/collectors/proc.plugin/plugin_proc.h
index 18714b548e..60a5a78a2e 100644
--- a/collectors/proc.plugin/plugin_proc.h
+++ b/collectors/proc.plugin/plugin_proc.h
@@ -5,25 +5,9 @@
 
 #include "daemon/common.h"
 
-#if (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_PROC \
-    { \
-        .name = "PLUGIN[proc]", \
-        .config_section = CONFIG_SECTION_PLUGINS, \
-        .config_name = "proc", \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = proc_main \
-    },
-
-
 #define PLUGIN_PROC_CONFIG_NAME "proc"
 #define PLUGIN_PROC_NAME PLUGIN_PROC_CONFIG_NAME ".plugin"
 
-extern void *proc_main(void *ptr);
-
 extern int do_proc_net_dev(int update_every, usec_t dt);
 extern int do_proc_net_wireless(int update_every, usec_t dt);
 extern int do_proc_diskstats(int update_every, usec_t dt);
@@ -74,11 +58,4 @@ extern void netdev_rename_device_del(const char *host_device);
 #include "proc_pressure.h"
 #include "zfs_common.h"
 
-#else // (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_PROC
-
-#endif // (TARGET_OS == OS_LINUX)
-
-
 #endif /* NETDATA_PLUGIN_PROC_H */
diff --git a/collectors/statsd.plugin/statsd.c b/collectors/statsd.plugin/statsd.c
index 9e152b09e7..a630d00d0c 100644
--- a/collectors/statsd.plugin/statsd.c
+++ b/collectors/statsd.plugin/statsd.c
@@ -1,11 +1,14 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
-#include "statsd.h"
+#include "daemon/common.h"
 
 #define STATSD_CHART_PREFIX "statsd"
 
 #define PLUGIN_STATSD_NAME "statsd.plugin"
 
+#define STATSD_LISTEN_PORT 8125
+#define STATSD_LISTEN_BACKLOG 4096
+
 // --------------------------------------------------------------------------------------
 
 // #define STATSD_MULTITHREADED 1
diff --git a/collectors/statsd.plugin/statsd.h b/collectors/statsd.plugin/statsd.h
deleted file mode 100644
index 37d6a08b3e..0000000000
--- a/collectors/statsd.plugin/statsd.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef NETDATA_STATSD_H
-#define NETDATA_STATSD_H 1
-
-#include "daemon/common.h"
-
-#define STATSD_LISTEN_PORT 8125
-#define STATSD_LISTEN_BACKLOG 4096
-
-#define NETDATA_PLUGIN_HOOK_STATSD \
-    { \
-        .name = "STATSD", \
-        .config_section = NULL, \
-        .config_name = NULL, \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = statsd_main \
-    },
-
-
-extern void *statsd_main(void *ptr);
-
-#endif //NETDATA_STATSD_H
diff --git a/collectors/tc.plugin/plugin_tc.c b/collectors/tc.plugin/plugin_tc.c
index 0197db0732..ce3fe668b4 100644
--- a/collectors/tc.plugin/plugin_tc.c
+++ b/collectors/tc.plugin/plugin_tc.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
-#include "plugin_tc.h"
+#include "daemon/common.h"
 
 #define RRD_TYPE_TC "tc"
 #define PLUGIN_TC_NAME "tc.plugin"
diff --git a/collectors/tc.plugin/plugin_tc.h b/collectors/tc.plugin/plugin_tc.h
deleted file mode 100644
index d51fcf6744..0000000000
--- a/collectors/tc.plugin/plugin_tc.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef NETDATA_PLUGIN_TC_H
-#define NETDATA_PLUGIN_TC_H 1
-
-#include "daemon/common.h"
-
-#if (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_TC \
-    { \
-        .name = "PLUGIN[tc]", \
-        .config_section = CONFIG_SECTION_PLUGINS, \
-        .config_name = "tc", \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = tc_main \
-    },
-
-extern void *tc_main(void *ptr);
-
-#else // (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_TC
-
-#endif // (TARGET_OS == OS_LINUX)
-
-
-#endif /* NETDATA_PLUGIN_TC_H */
-
diff --git a/collectors/timex.plugin/plugin_timex.c b/collectors/timex.plugin/plugin_timex.c
index b3e722a4cb..b69f342923 100644
--- a/collectors/timex.plugin/plugin_timex.c
+++ b/collectors/timex.plugin/plugin_timex.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
-#include "plugin_timex.h"
+#include "daemon/common.h"
 #include "sys/timex.h"
 
 #define PLUGIN_TIMEX_NAME "timex.plugin"
diff --git a/collectors/timex.plugin/plugin_timex.h b/collectors/timex.plugin/plugin_timex.h
deleted file mode 100644
index f837861633..0000000000
--- a/collectors/timex.plugin/plugin_timex.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef NETDATA_PLUGIN_TIMEX_H
-#define NETDATA_PLUGIN_TIMEX_H
-
-#include "daemon/common.h"
-
-#if (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_TIMEX \
-    { \
-        .name = "PLUGIN[timex]", \
-        .config_section = CONFIG_SECTION_PLUGINS, \
-        .config_name = "timex", \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = timex_main \
-    },
-
-extern void *timex_main(void *ptr);
-
-#else // (TARGET_OS == OS_LINUX)
-
-#define NETDATA_PLUGIN_HOOK_LINUX_TIMEX
-
-#endif // (TARGET_OS == OS_LINUX)
-
-#endif //NETDATA_PLUGIN_TIMEX_H
diff --git a/configure.ac b/configure.ac
index 5608d2bf49..eae219fd69 100644
--- a/configure.ac
+++ b/configure.ac
@@ -279,24 +279,21 @@ AC_MSG_CHECKING([operating system])
 case "$host_os" in
 freebsd*)
     build_target=freebsd
-    build_target_id=2
     CFLAGS="${CFLAGS} -I/usr/local/include -L/usr/local/lib"
     ;;
 darwin*)
     build_target=macos
-    build_target_id=3
     LDFLAGS="${LDFLAGS} -framework CoreFoundation -framework IOKit"
     ;;
 *)
     build_target=linux
-    build_target_id=1
     ;;
 esac
 
 AM_CONDITIONAL([FREEBSD], [test "${build_target}" = "freebsd"])
 AM_CONDITIONAL([MACOS], [test "${build_target}" = "macos"])
 AM_CONDITIONAL([LINUX], [test "${build_target}" = "linux"])
-AC_MSG_RESULT([${build_target} with id ${build_target_id}])
+AC_MSG_RESULT([Host OS: ${build_target}])
 
 
 # -----------------------------------------------------------------------------
@@ -1538,7 +1535,6 @@ libconfigdir="${libdir}/netdata/conf.d"
 logdir="${localstatedir}/log/netdata"
 pluginsdir="${libexecdir}/netdata/plugins.d"
 
-AC_SUBST([build_target])
 AC_SUBST([varlibdir])
 AC_SUBST([registrydir])
 AC_SUBST([cachedir])
@@ -1560,7 +1556,6 @@ CFLAGS="${CFLAGS} ${OPTIONAL_PROTOBUF_CFLAGS} ${OPTIONAL_MATH_CFLAGS} ${OPTIONAL
 CXXFLAGS="${CFLAGS} ${CXX11FLAG}"
 
 CPPFLAGS="\
-    -DTARGET_OS=${build_target_id} \
 	-DVARLIB_DIR=\"\\\"${varlibdir}\\\"\" \
 	-DCACHE_DIR=\"\\\"${cachedir}\\\"\" \
 	-DCONFIG_DIR=\"\\\"${configdir}\\\"\" \
diff --git a/daemon/analytics.h b/daemon/analytics.h
index 343448cd71..76c1cbb7e0 100644
--- a/daemon/analytics.h
+++ b/daemon/analytics.h
@@ -17,17 +17,6 @@
 #define ANALYTICS_MAX_JSON_HITS 255
 #define ANALYTICS_MAX_DASHBOARD_HITS 255
 
-#define NETDATA_PLUGIN_HOOK_ANALYTICS \
-    { \
-        .name = "ANALYTICS", \
-        .config_section = NULL, \
-        .config_name = NULL, \
-        .enabled = 0, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = analytics_main \
-    },
-
 /* Needed to calculate the space needed for parameters */
 #define ANALYTICS_NO_OF_ITEMS 39
 
@@ -80,7 +69,6 @@ struct analytics_data {
     uint8_t dashboard_hits;
 };
 
-extern void *analytics_main(void *ptr);
 extern void analytics_get_data(char *name, BUFFER *wb);
 extern void set_late_global_environment(void);
 extern void analytics_free_data(void);
diff --git a/daemon/common.h b/daemon/common.h
index c892dbdb16..5354e2ae00 100644
--- a/daemon/common.h
+++ b/daemon/common.h
@@ -79,8 +79,8 @@
 // the netdata daemon
 #include "daemon.h"
 #include "main.h"
+#include "static_threads.h"
 #include "signals.h"
-#include "service.h"
 #include "commands.h"
 #include "analytics.h"
 
diff --git a/daemon/global_statistics.c b/daemon/global_statistics.c
index a152a00ae2..f4f3e5762b 100644
--- a/daemon/global_statistics.c
+++ b/daemon/global_statistics.c
@@ -172,7 +172,7 @@ static inline void global_statistics_copy(struct global_statistics *gs, uint8_t
 #endif
 }
 
-void global_statistics_charts(void) {
+static void global_statistics_charts(void) {
     static unsigned long long old_web_requests = 0,
                               old_web_usec = 0,
                               old_content_size = 0,
diff --git a/daemon/global_statistics.h b/daemon/global_statistics.h
index c200a693bf..268b5319e7 100644
--- a/daemon/global_statistics.h
+++ b/daemon/global_statistics.h
@@ -8,17 +8,6 @@
 // ----------------------------------------------------------------------------
 // global statistics
 
-#define NETDATA_PLUGIN_HOOK_GLOBAL_STATISTICS                                                                          \
-    {.name = "GLOBAL_STATS",                                                                                           \
-     .config_section = NULL,                                                                                           \
-     .config_name = NULL,                                                                                              \
-     .enabled = 1,                                                                                                     \
-     .thread = NULL,                                                                                                   \
-     .init_routine = NULL,                                                                                             \
-     .start_routine = global_statistics_main},
-
-extern void *global_statistics_main(void *ptr);
-
 extern void rrdr_query_completed(uint64_t db_points_read, uint64_t result_points_generated);
 
 extern void finished_web_request_statistics(uint64_t dt,
@@ -29,6 +18,5 @@ extern void finished_web_request_statistics(uint64_t dt,
 
 extern uint64_t web_client_connected(void);
 extern void web_client_disconnected(void);
-extern void global_statistics_charts(void);
 
 #endif /* NETDATA_GLOBAL_STATISTICS_H */
diff --git a/daemon/main.c b/daemon/main.c
index 2ec5c33f9e..7c8e09a5fe 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -2,10 +2,13 @@
 
 #include "common.h"
 #include "buildinfo.h"
+#include "static_threads.h"
 
 int netdata_zero_metrics_enabled;
 int netdata_anonymous_statistics_enabled;
 
+struct netdata_static_thread *static_threads;
+
 struct config netdata_config = {
         .first_section = NULL,
         .last_section = NULL,
@@ -76,41 +79,6 @@ void netdata_cleanup_and_exit(int ret) {
     exit(ret);
 }
 
-struct netdata_static_thread static_threads[] = {
-    NETDATA_PLUGIN_HOOK_GLOBAL_STATISTICS
-
-    NETDATA_PLUGIN_HOOK_CHECKS
-    NETDATA_PLUGIN_HOOK_FREEBSD
-    NETDATA_PLUGIN_HOOK_MACOS
-
-    // linux internal plugins
-    NETDATA_PLUGIN_HOOK_LINUX_PROC
-    NETDATA_PLUGIN_HOOK_LINUX_DISKSPACE
-    NETDATA_PLUGIN_HOOK_LINUX_TIMEX
-    NETDATA_PLUGIN_HOOK_LINUX_CGROUPS
-    NETDATA_PLUGIN_HOOK_LINUX_TC
-
-    NETDATA_PLUGIN_HOOK_IDLEJITTER
-    NETDATA_PLUGIN_HOOK_STATSD
-
-#if defined(ENABLE_ACLK) || defined(ACLK_NG)
-    NETDATA_ACLK_HOOK
-#endif
-
-        // common plugins for all systems
-    {"BACKENDS",             NULL,                    NULL,         1, NULL, NULL, backends_main},
-    {"EXPORTING",            NULL,                    NULL,         1, NULL, NULL, exporting_main},
-    {"WEB_SERVER[static1]",  NULL,                    NULL,         0, NULL, NULL, socket_listen_main_static_threaded},
-    {"STREAM",               NULL,                    NULL,         0, NULL, NULL, rrdpush_sender_thread},
-
-    NETDATA_PLUGIN_HOOK_PLUGINSD
-    NETDATA_PLUGIN_HOOK_HEALTH
-    NETDATA_PLUGIN_HOOK_ANALYTICS
-    NETDATA_PLUGIN_HOOK_SERVICE
-
-    {NULL,                   NULL,                    NULL,         0, NULL, NULL, NULL}
-};
-
 void web_server_threading_selection(void) {
     web_server_mode = web_server_mode_id(config_get(CONFIG_SECTION_WEB, "mode", web_server_mode_name(web_server_mode)));
 
@@ -281,6 +249,8 @@ void cancel_main_threads() {
     }
     else
         info("All threads finished.");
+
+    free(static_threads);
 }
 
 struct option_def option_definitions[] = {
@@ -723,6 +693,7 @@ int main(int argc, char **argv) {
     size_t default_stacksize;
     char *user = NULL;
 
+    static_threads = static_threads_get();
 
     netdata_ready=0;
     // set the name for logging
diff --git a/daemon/main.h b/daemon/main.h
index 4000ab70b8..63d6c5a095 100644
--- a/daemon/main.h
+++ b/daemon/main.h
@@ -7,10 +7,6 @@
 
 extern struct config netdata_config;
 
-#define NETDATA_MAIN_THREAD_RUNNING   CONFIG_BOOLEAN_YES
-#define NETDATA_MAIN_THREAD_EXITING  (CONFIG_BOOLEAN_YES + 1)
-#define NETDATA_MAIN_THREAD_EXITED    CONFIG_BOOLEAN_NO
-
 /**
  * This struct contains information about command line options.
  */
@@ -26,20 +22,6 @@ struct option_def {
     const char *default_value;
 };
 
-struct netdata_static_thread {
-    char *name;                         // the name of the thread as it should appear in the logs
-
-    char *config_section;               // the section of netdata.conf to check if this is enabled or not
-    char *config_name;                  // the name of the config option to check if it is true or false
-
-    volatile sig_atomic_t enabled;      // the current status of the thread
-
-    netdata_thread_t *thread;           // internal use, to maintain a pointer to the created thread
-
-    void (*init_routine) (void);        // an initialization function to run before spawning the thread
-    void *(*start_routine) (void *);    // the threaded worker
-};
-
 extern void cancel_main_threads(void);
 extern int killpid(pid_t pid);
 extern void netdata_cleanup_and_exit(int ret) NORETURN;
diff --git a/daemon/service.c b/daemon/service.c
index 9cba0694fa..d3a4e5500b 100644
--- a/daemon/service.c
+++ b/daemon/service.c
@@ -5,7 +5,7 @@
 /* Run service jobs every X seconds */
 #define SERVICE_HEARTBEAT 10
 
-void service_main_cleanup(void *ptr)
+static void service_main_cleanup(void *ptr)
 {
     struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
     static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
diff --git a/daemon/service.h b/daemon/service.h
deleted file mode 100644
index cb03bec2cd..0000000000
--- a/daemon/service.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef NETDATA_SERVICE_H
-#define NETDATA_SERVICE_H 1
-
-#define NETDATA_PLUGIN_HOOK_SERVICE \
-    { \
-        .name = "SERVICE", \
-        .config_section = NULL, \
-        .config_name = NULL, \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = service_main \
-    },
-
-extern void *service_main(void *ptr);
-
-#endif //NETDATA_SERVICE_H
diff --git a/daemon/static_threads.c b/daemon/static_threads.c
new file mode 100644
index 0000000000..534b3c3d8c
--- /dev/null
+++ b/daemon/static_threads.c
@@ -0,0 +1,161 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "common.h"
+
+extern void *aclk_starter(void *ptr);
+extern void *analytics_main(void *ptr);
+extern void *checks_main(void *ptr);
+extern void *cpuidlejitter_main(void *ptr);
+extern void *global_statistics_main(void *ptr);
+extern void *health_main(void *ptr);
+extern void *pluginsd_main(void *ptr);
+extern void *service_main(void *ptr);
+extern void *statsd_main(void *ptr);
+
+const struct netdata_static_thread static_threads_common[] = {
+    {
+        .name = "PLUGIN[check]",
+        .config_section = CONFIG_SECTION_PLUGINS,
+        .config_name = "checks",
+        .enabled = 0,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = checks_main
+    },
+    {
+        .name = "PLUGIN[idlejitter]",
+        .config_section = CONFIG_SECTION_PLUGINS,
+        .config_name = "idlejitter",
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = cpuidlejitter_main
+    },
+    {
+        .name = "ANALYTICS",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 0,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = analytics_main
+    },
+    {
+        .name = "GLOBAL_STATS",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = global_statistics_main
+    },
+    {
+        .name = "HEALTH",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = health_main
+    },
+    {
+        .name = "PLUGINSD",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = pluginsd_main
+    },
+    {
+        .name = "SERVICE",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = service_main
+    },
+    {
+        .name = "STATSD",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = statsd_main
+    },
+    {
+        .name = "BACKENDS",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = backends_main
+    },
+    {
+        .name = "EXPORTING",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = exporting_main
+    },
+    {
+        .name = "STREAM",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 0,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = rrdpush_sender_thread
+    },
+    {
+        .name = "WEB_SERVER[static1]",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 0,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = socket_listen_main_static_threaded
+    },
+
+#if defined(ENABLE_ACLK) || defined(ACLK_NG)
+    {
+        .name = "ACLK_Main",
+        .config_section = NULL,
+        .config_name = NULL,
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = aclk_starter
+    },
+#endif
+
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+struct netdata_static_thread *
+static_threads_concat(const struct netdata_static_thread *lhs,
+                      const struct netdata_static_thread *rhs)
+{
+    struct netdata_static_thread *res;
+
+    int lhs_size = 0;
+    for (; lhs[lhs_size].name; lhs_size++) {}
+
+    int rhs_size = 0;
+    for (; rhs[rhs_size].name; rhs_size++) {}
+
+    res = callocz(lhs_size + rhs_size + 1, sizeof(struct netdata_static_thread));
+
+    for (int i = 0; i != lhs_size; i++)
+        memcpy(&res[i], &lhs[i], sizeof(struct netdata_static_thread));
+
+    for (int i = 0; i != rhs_size; i++)
+        memcpy(&res[lhs_size + i], &rhs[i], sizeof(struct netdata_static_thread));
+
+    return res;
+}
diff --git a/daemon/static_threads.h b/daemon/static_threads.h
new file mode 100644
index 0000000000..dac615e76d
--- /dev/null
+++ b/daemon/static_threads.h
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef NETDATA_STATIC_THREADS_H
+#define NETDATA_STATIC_THREADS_H
+
+#include "common.h"
+
+struct netdata_static_thread {
+    // the name of the thread as it should appear in the logs
+    char *name;
+
+    // the section of netdata.conf to check if this is enabled or not
+    char *config_section;
+
+    // the name of the config option to check if it is true or false
+    char *config_name;
+
+    // the current status of the thread
+    volatile sig_atomic_t enabled;
+
+    // internal use, to maintain a pointer to the created thread
+    netdata_thread_t *thread;
+
+    // an initialization function to run before spawning the thread
+    void (*init_routine) (void);
+
+    // the threaded worker
+    void *(*start_routine) (void *);
+};
+
+#define NETDATA_MAIN_THREAD_RUNNING     CONFIG_BOOLEAN_YES
+#define NETDATA_MAIN_THREAD_EXITING     (CONFIG_BOOLEAN_YES + 1)
+#define NETDATA_MAIN_THREAD_EXITED      CONFIG_BOOLEAN_NO
+
+extern const struct netdata_static_thread static_threads_common[];
+extern const struct netdata_static_thread static_threads_linux[];
+extern const struct netdata_static_thread static_threads_freebsd[];
+extern const struct netdata_static_thread static_threads_macos[];
+
+struct netdata_static_thread *
+static_threads_concat(const struct netdata_static_thread *lhs,
+                      const struct netdata_static_thread *rhs);
+
+struct netdata_static_thread *static_threads_get();
+
+#endif /* NETDATA_STATIC_THREADS_H */
diff --git a/daemon/static_threads_freebsd.c b/daemon/static_threads_freebsd.c
new file mode 100644
index 0000000000..48066bff52
--- /dev/null
+++ b/daemon/static_threads_freebsd.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "common.h"
+
+extern void *freebsd_main(void *ptr);
+
+const struct netdata_static_thread static_threads_freebsd[] = {
+    {
+        .name = "PLUGIN[freebsd]",
+        .config_section = CONFIG_SECTION_PLUGINS,
+        .config_name = "freebsd",
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = freebsd_main
+    },
+
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+const struct netdata_static_thread static_threads_linux[] = {
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+const struct netdata_static_thread static_threads_macos[] = {
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+struct netdata_static_thread *static_threads_get() {
+    return static_threads_concat(static_threads_common, static_threads_freebsd);
+}
diff --git a/daemon/static_threads_linux.c b/daemon/static_threads_linux.c
new file mode 100644
index 0000000000..e55c0fec7c
--- /dev/null
+++ b/daemon/static_threads_linux.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "common.h"
+
+extern void *cgroups_main(void *ptr);
+extern void *proc_main(void *ptr);
+extern void *diskspace_main(void *ptr);
+extern void *tc_main(void *ptr);
+extern void *timex_main(void *ptr);
+
+const struct netdata_static_thread static_threads_linux[] = {
+    {
+        .name = "PLUGIN[timex]",
+        .config_section = CONFIG_SECTION_PLUGINS,
+        .config_name = "timex",
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = timex_main
+    },
+    {
+        .name = "PLUGIN[tc]",
+        .config_section = CONFIG_SECTION_PLUGINS,
+        .config_name = "tc",
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = tc_main
+    },
+    {
+        .name = "PLUGIN[diskspace]",
+        .config_section = CONFIG_SECTION_PLUGINS,
+        .config_name = "diskspace",
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = diskspace_main
+    },
+    {
+        .name = "PLUGIN[proc]",
+        .config_section = CONFIG_SECTION_PLUGINS,
+        .config_name = "proc",
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = proc_main
+    },
+    {
+        .name = "PLUGIN[cgroups]",
+        .config_section = CONFIG_SECTION_PLUGINS,
+        .config_name = "cgroups",
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = cgroups_main
+    },
+
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+const struct netdata_static_thread static_threads_freebsd[] = {
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+const struct netdata_static_thread static_threads_macos[] = {
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+struct netdata_static_thread *static_threads_get() {
+    return static_threads_concat(static_threads_common, static_threads_linux);
+}
diff --git a/daemon/static_threads_macos.c b/daemon/static_threads_macos.c
new file mode 100644
index 0000000000..ae34a1363d
--- /dev/null
+++ b/daemon/static_threads_macos.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "common.h"
+
+extern void *macos_main(void *ptr);
+
+const struct netdata_static_thread static_threads_macos[] = {
+    {
+        .name = "PLUGIN[macos]",
+        .config_section = CONFIG_SECTION_PLUGINS,
+        .config_name = "macos",
+        .enabled = 1,
+        .thread = NULL,
+        .init_routine = NULL,
+        .start_routine = macos_main
+    },
+
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+const struct netdata_static_thread static_threads_freebsd[] = {
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+const struct netdata_static_thread static_threads_linux[] = {
+    {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+};
+
+struct netdata_static_thread *static_threads_get() {
+    return static_threads_concat(static_threads_common, static_threads_macos);
+}
diff --git a/health/health.h b/health/health.h
index 09040b3a84..323279bac3 100644
--- a/health/health.h
+++ b/health/health.h
@@ -5,17 +5,6 @@
 
 #include "daemon/common.h"
 
-#define NETDATA_PLUGIN_HOOK_HEALTH \
-    { \
-        .name = "HEALTH", \
-        .config_section = NULL, \
-        .config_name = NULL, \
-        .enabled = 1, \
-        .thread = NULL, \
-        .init_routine = NULL, \
-        .start_routine = health_main \
-    },
-
 extern unsigned int default_health_enabled;
 
 #define HEALTH_ENTRY_FLAG_PROCESSED             0x00000001
@@ -43,7 +32,6 @@ extern unsigned int default_health_enabled;
 extern char *silencers_filename;
 
 extern void health_init(void);
-extern void *health_main(void *ptr);
 
 extern void health_reload(void);
 
diff --git a/libnetdata/libnetdata.c b/libnetdata/libnetdata.c
index eb6fce74f8..18d0224076 100644
--- a/libnetdata/libnetdata.c
+++ b/libnetdata/libnetdata.c
@@ -14,7 +14,6 @@ struct rlimit rlimit_nofile = { .rlim_cur = 1024, .rlim_max = 1024 };
 int enable_ksm = 1;
 
 volatile sig_atomic_t netdata_exit = 0;
-const char *os_type = NETDATA_OS_TYPE;
 const char *program_version = VERSION;
 
 // ----------------------------------------------------------------------------
diff --git a/libnetdata/libnetdata.h b/libnetdata/libnetdata.h
index 432c74f461..809cefa013 100644
--- a/libnetdata/libnetdata.h
+++ b/libnetdata/libnetdata.h
@@ -274,7 +274,6 @@ extern int verify_netdata_host_prefix();
 extern int recursively_delete_dir(const char *path, const char *reason);
 
 extern volatile sig_atomic_t netdata_exit;
-extern const char *os_type;
 
 extern const char *program_version;
 
diff --git a/libnetdata/os.c b/libnetdata/os.c
index 4271a917cd..196288a6ae 100644
--- a/libnetdata/os.c
+++ b/libnetdata/os.c
@@ -123,7 +123,9 @@ void get_system_HZ(void) {
 // =====================================================================================================================
 // FreeBSD
 
-#if (TARGET_OS == OS_FREEBSD)
+#if __FreeBSD__
+
+const char *os_type = "freebsd";
 
 int getsysctl_by_name(const char *name, void *ptr, size_t len) {
     size_t nlen = len;
@@ -198,7 +200,9 @@ int getsysctl_mib(const char *name, int *mib, size_t len) {
 // =====================================================================================================================
 // MacOS
 
-#if (TARGET_OS == OS_MACOS)
+#if __APPLE__
+
+const char *os_type = "macos";
 
 int getsysctl_by_name(const char *name, void *ptr, size_t len) {
     size_t nlen = len;
@@ -214,4 +218,13 @@ int getsysctl_by_name(const char *name, void *ptr, size_t len) {
     return 0;
 }
 
-#endif // (TARGET_OS == OS_MACOS)
+#endif
+
+// =====================================================================================================================
+// Linux
+
+#if __linux__
+
+const char *os_type = "linux";
+
+#endif
diff --git a/libnetdata/os.h b/libnetdata/os.h
index 2494174bc7..7872f82b90 100644
--- a/libnetdata/os.h
+++ b/libnetdata/os.h
@@ -5,16 +5,10 @@
 
 #include "libnetdata.h"
 
-// =====================================================================================================================
-// Linux
-
-#if (TARGET_OS == OS_LINUX)
-
-
 // =====================================================================================================================
 // FreeBSD
 
-#elif (TARGET_OS == OS_FREEBSD)
+#if __FreeBSD__
 
 #include <sys/sysctl.h>
 
@@ -35,28 +29,24 @@ extern int getsysctl_simple(const char *name, int *mib, size_t miblen, void *ptr
 
 extern int getsysctl(const char *name, int *mib, size_t miblen, void *ptr, size_t *len);
 
+#endif
 
 // =====================================================================================================================
 // MacOS
 
-#elif (TARGET_OS == OS_MACOS)
+#if __APPLE__
 
 #include <sys/sysctl.h>
 
 #define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
 extern int getsysctl_by_name(const char *name, void *ptr, size_t len);
 
-
-// =====================================================================================================================
-// unknown O/S
-
-#else
-#error unsupported operating system
 #endif
 
-
 // =====================================================================================================================
-// common for all O/S
+// common defs for Apple/FreeBSD/Linux
+
+extern const char *os_type;
 
 extern int processors;
 extern long get_system_cpus(void);
diff --git a/tests/profile/Makefile b/tests/profile/Makefile
index 9348a48863..b3510e6e3c 100644
--- a/tests/profile/Makefile
+++ b/tests/profile/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 
-COMMON_CFLAGS = -I ../../ -DTARGET_OS=1  -Wall -Wextra
+COMMON_CFLAGS = -I ../../ -Wall -Wextra
 PROFILE_CFLAGS = -O1 -ggdb $(COMMON_CFLAGS)
 PERFORMANCE_CFLAGS = -O2 $(COMMON_CFLAGS)