diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-06 16:11:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-06 16:11:30 +0000 |
commit | aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7 (patch) | |
tree | 941cbdd387b41c1a81587c20a6df9f0e5e0ff7ab /collectors/proc.plugin/plugin_proc.c | |
parent | Adding upstream version 1.37.1. (diff) | |
download | netdata-upstream/1.38.0.tar.xz netdata-upstream/1.38.0.zip |
Adding upstream version 1.38.0.upstream/1.38.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/proc.plugin/plugin_proc.c')
-rw-r--r-- | collectors/proc.plugin/plugin_proc.c | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/collectors/proc.plugin/plugin_proc.c b/collectors/proc.plugin/plugin_proc.c index 1b24df45f..1f52713ce 100644 --- a/collectors/proc.plugin/plugin_proc.c +++ b/collectors/proc.plugin/plugin_proc.c @@ -86,7 +86,7 @@ static void proc_main_cleanup(void *ptr) struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr; static_thread->enabled = NETDATA_MAIN_THREAD_EXITING; - info("cleaning up..."); + collector_info("cleaning up..."); if (netdev_thread) { netdata_thread_join(*netdev_thread, NULL); @@ -98,6 +98,41 @@ static void proc_main_cleanup(void *ptr) worker_unregister(); } +bool inside_lxc_container = false; + +static bool is_lxcfs_proc_mounted() { + procfile *ff = NULL; + + if (unlikely(!ff)) { + char filename[FILENAME_MAX + 1]; + snprintfz(filename, FILENAME_MAX, "/proc/self/mounts"); + ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT); + if (unlikely(!ff)) + return false; + } + + ff = procfile_readall(ff); + if (unlikely(!ff)) + return false; + + unsigned long l, lines = procfile_lines(ff); + + for (l = 0; l < lines; l++) { + size_t words = procfile_linewords(ff, l); + if (words < 2) { + continue; + } + if (!strcmp(procfile_lineword(ff, l, 0), "lxcfs") && !strncmp(procfile_lineword(ff, l, 1), "/proc", 5)) { + procfile_close(ff); + return true; + } + } + + procfile_close(ff); + + return false; +} + void *proc_main(void *ptr) { worker_register("PROC"); @@ -128,15 +163,17 @@ void *proc_main(void *ptr) heartbeat_t hb; heartbeat_init(&hb); - while (!netdata_exit) { + inside_lxc_container = is_lxcfs_proc_mounted(); + + while (service_running(SERVICE_COLLECTORS)) { worker_is_idle(); usec_t hb_dt = heartbeat_next(&hb, step); - if (unlikely(netdata_exit)) + if (unlikely(!service_running(SERVICE_COLLECTORS))) break; for (i = 0; proc_modules[i].name; i++) { - if (unlikely(netdata_exit)) + if (unlikely(!service_running(SERVICE_COLLECTORS))) break; struct proc_module *pm = &proc_modules[i]; |