diff options
author | Vladimir Kobal <vlad@prokk.net> | 2021-07-19 08:08:36 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-19 08:08:36 +0300 |
commit | 96636b7c6fd8f4e32e733744fecc4a7018c5f198 (patch) | |
tree | acde8051a955ba819738a79abd21d914e6e17f66 /daemon | |
parent | b66f61ae1e1ec17302938e8765230bc7e1701e25 (diff) |
Move cleanup of obsolete charts to a separate thread (#11222)
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/common.h | 1 | ||||
-rw-r--r-- | daemon/main.c | 1 | ||||
-rw-r--r-- | daemon/service.c | 38 | ||||
-rw-r--r-- | daemon/service.h | 19 |
4 files changed, 59 insertions, 0 deletions
diff --git a/daemon/common.h b/daemon/common.h index bd0a8bef53..4c0677d96d 100644 --- a/daemon/common.h +++ b/daemon/common.h @@ -77,6 +77,7 @@ #include "daemon.h" #include "main.h" #include "signals.h" +#include "service.h" #include "commands.h" #include "analytics.h" diff --git a/daemon/main.c b/daemon/main.c index c0ba3cb105..bb85f1a486 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -104,6 +104,7 @@ struct netdata_static_thread static_threads[] = { NETDATA_PLUGIN_HOOK_PLUGINSD NETDATA_PLUGIN_HOOK_HEALTH NETDATA_PLUGIN_HOOK_ANALYTICS + NETDATA_PLUGIN_HOOK_SERVICE {NULL, NULL, NULL, 0, NULL, NULL, NULL} }; diff --git a/daemon/service.c b/daemon/service.c new file mode 100644 index 0000000000..9cba0694fa --- /dev/null +++ b/daemon/service.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common.h" + +/* Run service jobs every X seconds */ +#define SERVICE_HEARTBEAT 10 + +void service_main_cleanup(void *ptr) +{ + struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr; + static_thread->enabled = NETDATA_MAIN_THREAD_EXITING; + + debug(D_SYSTEM, "Cleaning up..."); + + static_thread->enabled = NETDATA_MAIN_THREAD_EXITED; +} + +/* + * The service thread. + */ +void *service_main(void *ptr) +{ + netdata_thread_cleanup_push(service_main_cleanup, ptr); + heartbeat_t hb; + heartbeat_init(&hb); + usec_t step = USEC_PER_SEC * SERVICE_HEARTBEAT; + + debug(D_SYSTEM, "Service thread starts"); + + while (!netdata_exit) { + heartbeat_next(&hb, step); + + rrd_cleanup_obsolete_charts(); + } + + netdata_thread_cleanup_pop(1); + return NULL; +} diff --git a/daemon/service.h b/daemon/service.h new file mode 100644 index 0000000000..cb03bec2cd --- /dev/null +++ b/daemon/service.h @@ -0,0 +1,19 @@ +// 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 |