From d4e0f112868da4bd6e1b39bc6fd0abcc154826de Mon Sep 17 00:00:00 2001 From: thiagoftsm Date: Tue, 1 Nov 2022 12:05:14 +0000 Subject: Fix systemd chart update (eBPF) (#13884) --- collectors/ebpf.plugin/ebpf_cachestat.c | 17 ++++------------- collectors/ebpf.plugin/ebpf_cgroup.c | 27 ++++++++------------------- collectors/ebpf.plugin/ebpf_cgroup.h | 2 +- collectors/ebpf.plugin/ebpf_dcstat.c | 17 ++++------------- collectors/ebpf.plugin/ebpf_fd.c | 17 ++++------------- collectors/ebpf.plugin/ebpf_oomkill.c | 17 ++++------------- collectors/ebpf.plugin/ebpf_process.c | 21 ++++++--------------- collectors/ebpf.plugin/ebpf_shm.c | 17 ++++------------- collectors/ebpf.plugin/ebpf_socket.c | 23 ++++++----------------- collectors/ebpf.plugin/ebpf_swap.c | 18 ++++-------------- collectors/ebpf.plugin/ebpf_vfs.c | 18 ++++-------------- 11 files changed, 49 insertions(+), 145 deletions(-) diff --git a/collectors/ebpf.plugin/ebpf_cachestat.c b/collectors/ebpf.plugin/ebpf_cachestat.c index cd0580885c..aa2bb5a232 100644 --- a/collectors/ebpf.plugin/ebpf_cachestat.c +++ b/collectors/ebpf.plugin/ebpf_cachestat.c @@ -905,21 +905,16 @@ static void ebpf_create_systemd_cachestat_charts(int update_every) * Send Cache Stat charts * * Send collected data to Netdata. - * - * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned - * otherwise function returns 1 to avoid chart recreation */ -static int ebpf_send_systemd_cachestat_charts() +static void ebpf_send_systemd_cachestat_charts() { - int ret = 1; ebpf_cgroup_target_t *ect; write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_CACHESTAT_HIT_RATIO_CHART); for (ect = ebpf_cgroup_pids; ect; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, (long long)ect->publish_cachestat.ratio); - } else if (unlikely(ect->systemd)) - ret = 0; + } } write_end_chart(); @@ -946,8 +941,6 @@ static int ebpf_send_systemd_cachestat_charts() } } write_end_chart(); - - return ret; } /** @@ -1071,13 +1064,11 @@ void ebpf_cachestat_send_cgroup_data(int update_every) int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; if (has_systemd) { - static int systemd_charts = 0; - if (!systemd_charts) { + if (send_cgroup_chart) { ebpf_create_systemd_cachestat_charts(update_every); - systemd_charts = 1; } - systemd_charts = ebpf_send_systemd_cachestat_charts(); + ebpf_send_systemd_cachestat_charts(); } for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { diff --git a/collectors/ebpf.plugin/ebpf_cgroup.c b/collectors/ebpf.plugin/ebpf_cgroup.c index 24469c6420..42c0453689 100644 --- a/collectors/ebpf.plugin/ebpf_cgroup.c +++ b/collectors/ebpf.plugin/ebpf_cgroup.c @@ -6,6 +6,7 @@ #include "ebpf_cgroup.h" ebpf_cgroup_target_t *ebpf_cgroup_pids = NULL; +int send_cgroup_chart = 0; // -------------------------------------------------------------------------------------------------------------------- // Map shared memory @@ -98,24 +99,6 @@ void ebpf_map_cgroup_shared_memory() // -------------------------------------------------------------------------------------------------------------------- // Close and Cleanup -/** - * Close shared memory - */ -void ebpf_close_cgroup_shm() -{ - if (shm_sem_ebpf_cgroup != SEM_FAILED) { - sem_close(shm_sem_ebpf_cgroup); - sem_unlink(NETDATA_NAMED_SEMAPHORE_EBPF_CGROUP_NAME); - shm_sem_ebpf_cgroup = SEM_FAILED; - } - - if (shm_fd_ebpf_cgroup > 0) { - close(shm_fd_ebpf_cgroup); - shm_unlink(NETDATA_SHARED_MEMORY_EBPF_CGROUP_NAME); - shm_fd_ebpf_cgroup = -1; - } -} - /** * Clean Specific cgroup pid * @@ -259,7 +242,7 @@ static void ebpf_update_pid_link_list(ebpf_cgroup_target_t *ect, char *path) * * Set variable remove. If this variable is not reset, the structure will be removed from link list. */ - void ebpf_reset_updated_var() +void ebpf_reset_updated_var() { ebpf_cgroup_target_t *ect; for (ect = ebpf_cgroup_pids; ect; ect = ect->next) { @@ -274,6 +257,7 @@ static void ebpf_update_pid_link_list(ebpf_cgroup_target_t *ect, char *path) */ void ebpf_parse_cgroup_shm_data() { + static int previous = 0; if (shm_ebpf_cgroup.header) { sem_wait(shm_sem_ebpf_cgroup); int i, end = shm_ebpf_cgroup.header->cgroup_root_count; @@ -291,6 +275,11 @@ void ebpf_parse_cgroup_shm_data() ebpf_update_pid_link_list(ect, ptr->path); } } + send_cgroup_chart = previous != shm_ebpf_cgroup.header->cgroup_root_count; + previous = shm_ebpf_cgroup.header->cgroup_root_count; +#ifdef NETDATA_DEV_MODE + error("Updating cgroup %d (Previous: %d, Current: %d)", send_cgroup_chart, previous, shm_ebpf_cgroup.header->cgroup_root_count); +#endif pthread_mutex_unlock(&mutex_cgroup_shm); sem_post(shm_sem_ebpf_cgroup); diff --git a/collectors/ebpf.plugin/ebpf_cgroup.h b/collectors/ebpf.plugin/ebpf_cgroup.h index 5956adee7f..19da7fca97 100644 --- a/collectors/ebpf.plugin/ebpf_cgroup.h +++ b/collectors/ebpf.plugin/ebpf_cgroup.h @@ -62,8 +62,8 @@ typedef struct ebpf_cgroup_target { void ebpf_map_cgroup_shared_memory(); void ebpf_parse_cgroup_shm_data(); -void ebpf_close_cgroup_shm(); void ebpf_create_charts_on_systemd(char *id, char *title, char *units, char *family, char *charttype, int order, char *algorithm, char *context, char *module, int update_every); +extern int send_cgroup_chart; #endif /* NETDATA_EBPF_CGROUP_H */ diff --git a/collectors/ebpf.plugin/ebpf_dcstat.c b/collectors/ebpf.plugin/ebpf_dcstat.c index 43c51a993c..262028f929 100644 --- a/collectors/ebpf.plugin/ebpf_dcstat.c +++ b/collectors/ebpf.plugin/ebpf_dcstat.c @@ -893,21 +893,16 @@ static void ebpf_create_systemd_dc_charts(int update_every) * Send Directory Cache charts * * Send collected data to Netdata. - * - * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned - * otherwise function returns 1 to avoid chart recreation */ -static int ebpf_send_systemd_dc_charts() +static void ebpf_send_systemd_dc_charts() { - int ret = 1; collected_number value; ebpf_cgroup_target_t *ect; write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_DC_HIT_CHART); for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, (long long) ect->publish_dc.ratio); - } else if (unlikely(ect->systemd)) - ret = 0; + } } write_end_chart(); @@ -943,8 +938,6 @@ static int ebpf_send_systemd_dc_charts() } } write_end_chart(); - - return ret; } /** @@ -999,13 +992,11 @@ void ebpf_dc_send_cgroup_data(int update_every) int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; if (has_systemd) { - static int systemd_charts = 0; - if (!systemd_charts) { + if (send_cgroup_chart) { ebpf_create_systemd_dc_charts(update_every); - systemd_charts = 1; } - systemd_charts = ebpf_send_systemd_dc_charts(); + ebpf_send_systemd_dc_charts(); } for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { diff --git a/collectors/ebpf.plugin/ebpf_fd.c b/collectors/ebpf.plugin/ebpf_fd.c index 5bdbc9edfb..100917c1cc 100644 --- a/collectors/ebpf.plugin/ebpf_fd.c +++ b/collectors/ebpf.plugin/ebpf_fd.c @@ -841,20 +841,15 @@ static void ebpf_create_systemd_fd_charts(ebpf_module_t *em) * Send collected data to Netdata. * * @param em the main collector structure - * - * @return It returns the status for chart creation, if it is necessary to remove a specific dimension zero is returned - * otherwise function returns 1 to avoid chart recreation */ -static int ebpf_send_systemd_fd_charts(ebpf_module_t *em) +static void ebpf_send_systemd_fd_charts(ebpf_module_t *em) { - int ret = 1; ebpf_cgroup_target_t *ect; write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_SYSCALL_APPS_FILE_OPEN); for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, ect->publish_systemd_fd.open_call); - } else if (unlikely(ect->systemd)) - ret = 0; + } } write_end_chart(); @@ -885,8 +880,6 @@ static int ebpf_send_systemd_fd_charts(ebpf_module_t *em) } write_end_chart(); } - - return ret; } /** @@ -907,13 +900,11 @@ static void ebpf_fd_send_cgroup_data(ebpf_module_t *em) int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; if (has_systemd) { - static int systemd_charts = 0; - if (!systemd_charts) { + if (send_cgroup_chart) { ebpf_create_systemd_fd_charts(em); - systemd_charts = 1; } - systemd_charts = ebpf_send_systemd_fd_charts(em); + ebpf_send_systemd_fd_charts(em); } for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { diff --git a/collectors/ebpf.plugin/ebpf_oomkill.c b/collectors/ebpf.plugin/ebpf_oomkill.c index 754261febe..488748e0ae 100644 --- a/collectors/ebpf.plugin/ebpf_oomkill.c +++ b/collectors/ebpf.plugin/ebpf_oomkill.c @@ -132,25 +132,18 @@ static void ebpf_create_systemd_oomkill_charts(int update_every) * Send Systemd charts * * Send collected data to Netdata. - * - * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned - * otherwise function returns 1 to avoid chart recreation */ -static int ebpf_send_systemd_oomkill_charts() +static void ebpf_send_systemd_oomkill_charts() { - int ret = 1; ebpf_cgroup_target_t *ect; write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_OOMKILL_CHART); for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, (long long) ect->oomkill); ect->oomkill = 0; - } else if (unlikely(ect->systemd)) - ret = 0; + } } write_end_chart(); - - return ret; } /* @@ -199,12 +192,10 @@ void ebpf_oomkill_send_cgroup_data(int update_every) int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; if (has_systemd) { - static int systemd_charts = 0; - if (!systemd_charts) { + if (send_cgroup_chart) { ebpf_create_systemd_oomkill_charts(update_every); - systemd_charts = 1; } - systemd_charts = ebpf_send_systemd_oomkill_charts(); + ebpf_send_systemd_oomkill_charts(); } for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { diff --git a/collectors/ebpf.plugin/ebpf_process.c b/collectors/ebpf.plugin/ebpf_process.c index 6d2393fb8c..09b9969e7c 100644 --- a/collectors/ebpf.plugin/ebpf_process.c +++ b/collectors/ebpf.plugin/ebpf_process.c @@ -973,20 +973,15 @@ static void ebpf_create_systemd_process_charts(ebpf_module_t *em) * Send collected data to Netdata. * * @param em the structure with thread information - * - * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned - * otherwise function returns 1 to avoid chart recreation */ -static int ebpf_send_systemd_process_charts(ebpf_module_t *em) +static void ebpf_send_systemd_process_charts(ebpf_module_t *em) { - int ret = 1; ebpf_cgroup_target_t *ect; write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_SYSCALL_APPS_TASK_PROCESS); for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, ect->publish_systemd_ps.create_process); - } else if (unlikely(ect->systemd)) - ret = 0; + } } write_end_chart(); @@ -1023,8 +1018,6 @@ static int ebpf_send_systemd_process_charts(ebpf_module_t *em) } write_end_chart(); } - - return ret; } /** @@ -1046,13 +1039,11 @@ static void ebpf_process_send_cgroup_data(ebpf_module_t *em) int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; if (has_systemd) { - static int systemd_chart = 0; - if (!systemd_chart) { + if (send_cgroup_chart) { ebpf_create_systemd_process_charts(em); - systemd_chart = 1; } - systemd_chart = ebpf_send_systemd_process_charts(em); + ebpf_send_systemd_process_charts(em); } for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { @@ -1150,8 +1141,6 @@ static void process_collector(ebpf_module_t *em) update_apps_list = 0; cleanup_exited_pids(); collect_data_for_all_processes(pid_fd); - - ebpf_create_apps_charts(apps_groups_root_target); } pthread_mutex_unlock(&collect_data_mutex); @@ -1162,6 +1151,8 @@ static void process_collector(ebpf_module_t *em) netdata_apps_integration_flags_t apps_enabled = em->apps_charts; pthread_mutex_lock(&collect_data_mutex); + + ebpf_create_apps_charts(apps_groups_root_target); if (all_pids_count > 0) { if (apps_enabled) { ebpf_process_update_apps_data(); diff --git a/collectors/ebpf.plugin/ebpf_shm.c b/collectors/ebpf.plugin/ebpf_shm.c index 5fc3c8615e..2addbf27ba 100644 --- a/collectors/ebpf.plugin/ebpf_shm.c +++ b/collectors/ebpf.plugin/ebpf_shm.c @@ -772,20 +772,15 @@ static void ebpf_create_systemd_shm_charts(int update_every) * Send Systemd charts * * Send collected data to Netdata. - * - * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned - * otherwise function returns 1 to avoid chart recreation */ -static int ebpf_send_systemd_shm_charts() +static void ebpf_send_systemd_shm_charts() { - int ret = 1; ebpf_cgroup_target_t *ect; write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_SHMGET_CHART); for (ect = ebpf_cgroup_pids; ect; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, (long long)ect->publish_shm.get); - } else if (unlikely(ect->systemd)) - ret = 0; + } } write_end_chart(); @@ -812,8 +807,6 @@ static int ebpf_send_systemd_shm_charts() } } write_end_chart(); - - return ret; } /* @@ -861,13 +854,11 @@ void ebpf_shm_send_cgroup_data(int update_every) int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; if (has_systemd) { - static int systemd_charts = 0; - if (!systemd_charts) { + if (send_cgroup_chart) { ebpf_create_systemd_shm_charts(update_every); - systemd_charts = 1; } - systemd_charts = ebpf_send_systemd_shm_charts(); + ebpf_send_systemd_shm_charts(); } for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { diff --git a/collectors/ebpf.plugin/ebpf_socket.c b/collectors/ebpf.plugin/ebpf_socket.c index 15a348743c..93d4e83317 100644 --- a/collectors/ebpf.plugin/ebpf_socket.c +++ b/collectors/ebpf.plugin/ebpf_socket.c @@ -2709,20 +2709,15 @@ static void ebpf_create_systemd_socket_charts(int update_every) * Send Systemd charts * * Send collected data to Netdata. - * - * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned - * otherwise function returns 1 to avoid chart recreation */ -static int ebpf_send_systemd_socket_charts() +static void ebpf_send_systemd_socket_charts() { - int ret = 1; ebpf_cgroup_target_t *ect; write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_NET_APPS_CONNECTION_TCP_V4); for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, (long long)ect->publish_socket.call_tcp_v4_connection); - } else if (unlikely(ect->systemd)) - ret = 0; + } } write_end_chart(); @@ -2730,8 +2725,7 @@ static int ebpf_send_systemd_socket_charts() for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, (long long)ect->publish_socket.call_tcp_v6_connection); - } else - ret = 0; + } } write_end_chart(); @@ -2739,8 +2733,7 @@ static int ebpf_send_systemd_socket_charts() for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, (long long)ect->publish_socket.bytes_sent); - } else - ret = 0; + } } write_end_chart(); @@ -2791,8 +2784,6 @@ static int ebpf_send_systemd_socket_charts() } } write_end_chart(); - - return ret; } /** @@ -2828,12 +2819,10 @@ static void ebpf_socket_send_cgroup_data(int update_every) int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; if (has_systemd) { - static int systemd_charts = 0; - if (!systemd_charts) { + if (send_cgroup_chart) { ebpf_create_systemd_socket_charts(update_every); - systemd_charts = 1; } - systemd_charts = ebpf_send_systemd_socket_charts(); + ebpf_send_systemd_socket_charts(); } for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { diff --git a/collectors/ebpf.plugin/ebpf_swap.c b/collectors/ebpf.plugin/ebpf_swap.c index b1d6ef8f65..c0c42bfb49 100644 --- a/collectors/ebpf.plugin/ebpf_swap.c +++ b/collectors/ebpf.plugin/ebpf_swap.c @@ -540,20 +540,15 @@ static void ebpf_swap_sum_cgroup_pids(netdata_publish_swap_t *swap, struct pid_o * Send Systemd charts * * Send collected data to Netdata. - * - * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned - * otherwise function returns 1 to avoid chart recreation */ -static int ebpf_send_systemd_swap_charts() +static void ebpf_send_systemd_swap_charts() { - int ret = 1; ebpf_cgroup_target_t *ect; write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_MEM_SWAP_READ_CHART); for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, (long long) ect->publish_systemd_swap.read); - } else if (unlikely(ect->systemd)) - ret = 0; + } } write_end_chart(); @@ -564,8 +559,6 @@ static int ebpf_send_systemd_swap_charts() } } write_end_chart(); - - return ret; } /** @@ -679,14 +672,11 @@ void ebpf_swap_send_cgroup_data(int update_every) int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; if (has_systemd) { - static int systemd_charts = 0; - if (!systemd_charts) { + if (send_cgroup_chart) { ebpf_create_systemd_swap_charts(update_every); - systemd_charts = 1; fflush(stdout); } - - systemd_charts = ebpf_send_systemd_swap_charts(); + ebpf_send_systemd_swap_charts(); } for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { diff --git a/collectors/ebpf.plugin/ebpf_vfs.c b/collectors/ebpf.plugin/ebpf_vfs.c index c63a14a8c5..c7786a198b 100644 --- a/collectors/ebpf.plugin/ebpf_vfs.c +++ b/collectors/ebpf.plugin/ebpf_vfs.c @@ -1336,20 +1336,15 @@ static void ebpf_create_systemd_vfs_charts(ebpf_module_t *em) * Send collected data to Netdata. * * @param em the main collector structure - * - * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned - * otherwise function returns 1 to avoid chart recreation */ -static int ebpf_send_systemd_vfs_charts(ebpf_module_t *em) +static void ebpf_send_systemd_vfs_charts(ebpf_module_t *em) { - int ret = 1; ebpf_cgroup_target_t *ect; write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_SYSCALL_APPS_FILE_DELETED); for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { if (unlikely(ect->systemd) && unlikely(ect->updated)) { write_chart_dimension(ect->name, ect->publish_systemd_vfs.unlink_call); - } else if (unlikely(ect->systemd)) - ret = 0; + } } write_end_chart(); @@ -1465,8 +1460,6 @@ static int ebpf_send_systemd_vfs_charts(ebpf_module_t *em) } write_end_chart(); } - - return ret; } /** @@ -1487,13 +1480,10 @@ static void ebpf_vfs_send_cgroup_data(ebpf_module_t *em) int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; if (has_systemd) { - static int systemd_charts = 0; - if (!systemd_charts) { + if (send_cgroup_chart) { ebpf_create_systemd_vfs_charts(em); - systemd_charts = 1; } - - systemd_charts = ebpf_send_systemd_vfs_charts(em); + ebpf_send_systemd_vfs_charts(em); } for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { -- cgit v1.2.3