summaryrefslogtreecommitdiffstats
path: root/collectors
diff options
context:
space:
mode:
authorVladimir Kobal <vlad@prokk.net>2022-05-24 17:45:03 +0300
committerGitHub <noreply@github.com>2022-05-24 16:45:03 +0200
commitcefa2189aef363d766561915c946da3c43ee6d49 (patch)
tree4535cb3ee7f85ae080a24b794571775c0f9978a3 /collectors
parent35ec0545dd797534c42d033b31edff3600bd2c88 (diff)
Run the /net/dev module of the proc plugin in a separate thread (#12996)
Diffstat (limited to 'collectors')
-rw-r--r--collectors/proc.plugin/plugin_proc.c15
-rw-r--r--collectors/proc.plugin/plugin_proc.h4
-rw-r--r--collectors/proc.plugin/proc_net_dev.c36
3 files changed, 53 insertions, 2 deletions
diff --git a/collectors/proc.plugin/plugin_proc.c b/collectors/proc.plugin/plugin_proc.c
index e10e91f82d..5033aa5e28 100644
--- a/collectors/proc.plugin/plugin_proc.c
+++ b/collectors/proc.plugin/plugin_proc.c
@@ -37,7 +37,6 @@ static struct proc_module {
{.name = "/proc/pagetypeinfo", .dim = "pagetypeinfo", .func = do_proc_pagetypeinfo},
// network metrics
- {.name = "/proc/net/dev", .dim = "netdev", .func = do_proc_net_dev},
{.name = "/proc/net/wireless", .dim = "netwireless", .func = do_proc_net_wireless},
{.name = "/proc/net/sockstat", .dim = "sockstat", .func = do_proc_net_sockstat},
{.name = "/proc/net/sockstat6", .dim = "sockstat6", .func = do_proc_net_sockstat6},
@@ -84,6 +83,8 @@ static struct proc_module {
#error WORKER_UTILIZATION_MAX_JOB_TYPES has to be at least 36
#endif
+static netdata_thread_t *netdev_thread = NULL;
+
static void proc_main_cleanup(void *ptr)
{
struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
@@ -91,6 +92,11 @@ static void proc_main_cleanup(void *ptr)
info("cleaning up...");
+ if (netdev_thread) {
+ netdata_thread_join(*netdev_thread, NULL);
+ freez(netdev_thread);
+ }
+
static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
worker_unregister();
@@ -100,6 +106,13 @@ void *proc_main(void *ptr)
{
worker_register("PROC");
+ if (config_get_boolean("plugin:proc", "/proc/net/dev", CONFIG_BOOLEAN_YES)) {
+ netdev_thread = mallocz(sizeof(netdata_thread_t));
+ debug(D_SYSTEM, "Starting thread %s.", THREAD_NETDEV_NAME);
+ netdata_thread_create(
+ netdev_thread, THREAD_NETDEV_NAME, NETDATA_THREAD_OPTION_JOINABLE, netdev_main, netdev_thread);
+ }
+
netdata_thread_cleanup_push(proc_main_cleanup, ptr);
config_get_boolean("plugin:proc", "/proc/pagetypeinfo", CONFIG_BOOLEAN_NO);
diff --git a/collectors/proc.plugin/plugin_proc.h b/collectors/proc.plugin/plugin_proc.h
index 555eb5d075..1e3b829652 100644
--- a/collectors/proc.plugin/plugin_proc.h
+++ b/collectors/proc.plugin/plugin_proc.h
@@ -8,7 +8,9 @@
#define PLUGIN_PROC_CONFIG_NAME "proc"
#define PLUGIN_PROC_NAME PLUGIN_PROC_CONFIG_NAME ".plugin"
-extern int do_proc_net_dev(int update_every, usec_t dt);
+#define THREAD_NETDEV_NAME "PLUGIN[proc netdev]"
+extern void *netdev_main(void *ptr);
+
extern int do_proc_net_wireless(int update_every, usec_t dt);
extern int do_proc_diskstats(int update_every, usec_t dt);
extern int do_proc_mdstat(int update_every, usec_t dt);
diff --git a/collectors/proc.plugin/proc_net_dev.c b/collectors/proc.plugin/proc_net_dev.c
index f9e8539cb7..7e20fe9b0b 100644
--- a/collectors/proc.plugin/proc_net_dev.c
+++ b/collectors/proc.plugin/proc_net_dev.c
@@ -1384,3 +1384,39 @@ int do_proc_net_dev(int update_every, usec_t dt) {
return 0;
}
+
+static void netdev_main_cleanup(void *ptr)
+{
+ UNUSED(ptr);
+
+ info("cleaning up...");
+
+ worker_unregister();
+}
+
+void *netdev_main(void *ptr)
+{
+ worker_register("NETDEV");
+ worker_register_job_name(0, "netdev");
+
+ netdata_thread_cleanup_push(netdev_main_cleanup, ptr);
+
+ usec_t step = localhost->rrd_update_every * USEC_PER_SEC;
+ heartbeat_t hb;
+ heartbeat_init(&hb);
+
+ while (!netdata_exit) {
+ worker_is_idle();
+ usec_t hb_dt = heartbeat_next(&hb, step);
+
+ if (unlikely(netdata_exit))
+ break;
+
+ worker_is_busy(0);
+ if(do_proc_net_dev(localhost->rrd_update_every, hb_dt))
+ break;
+ }
+
+ netdata_thread_cleanup_pop(1);
+ return NULL;
+}