@cryptotaxi247 / netdata-1 / commits / e2c264065

Reduce service exit (#14381)

thiagoftsm committed Feb 3, 2023 at 15:47 UTC e2c26406560caab8a39d87d2ad270dc3ad0f716c
17 files changed +114 -77
collectors/ebpf.plugin/ebpf.c
+14 -4
@@ -483,7 +483,17 @@ static void ebpf_exit()
483 if (unlink(filename))
484 error("Cannot remove PID file %s", filename);
485
486 - ebpf_exit_plugin = 2;
486 +#ifdef NETDATA_INTERNAL_CHECKS
487 + error("Good bye world! I was PID %d", main_thread_id);
488 +#endif
489 + printf("DISABLE\n");
490 +
491 + if (shm_ebpf_cgroup.header) {
492 + munmap(shm_ebpf_cgroup.header, shm_ebpf_cgroup.header->body_length);
493 + shm_unlink(NETDATA_SHARED_MEMORY_EBPF_CGROUP_NAME);
494 + }
495 +
496 + exit(0);
497 }
498
499 /**
@@ -2253,10 +2263,8 @@ int main(int argc, char **argv)
2263 heartbeat_t hb;
2264 heartbeat_init(&hb);
2265 //Plugin will be killed when it receives a signal
2256 - while (ebpf_exit_plugin != 2) {
2266 + while (!ebpf_exit_plugin) {
2267 (void)heartbeat_next(&hb, step);
2258 - if (ebpf_exit_plugin == 2)
2259 - break;
2268
2269 // We are using a small heartbeat time to wake up thread,
2270 // but we should not update so frequently the shared memory data
@@ -2269,5 +2277,7 @@ int main(int argc, char **argv)
2277 }
2278 }
2279
2280 + ebpf_stop_threads(0);
2281 +
2282 return 0;
2283 }
collectors/ebpf.plugin/ebpf.d.conf
+5 -5
@@ -50,7 +50,7 @@
50 # When plugin detects that system has support to BTF, it enables integration with apps.plugin.
51 #
52 [ebpf programs]
53 - cachestat = no
53 + cachestat = yes
54 dcstat = no
55 disk = no
56 fd = yes
@@ -60,10 +60,10 @@
60 mount = yes
61 oomkill = yes
62 process = yes
63 - shm = no
64 - socket = yes
63 + shm = yes
64 + socket = no
65 softirq = yes
66 sync = yes
67 - swap = no
68 - vfs = yes
67 + swap = yes
68 + vfs = no
69 network connections = no
collectors/ebpf.plugin/ebpf_cachestat.c
+6 -4
@@ -1067,13 +1067,15 @@ static void cachestat_collector(ebpf_module_t *em)
1067 int update_every = em->update_every;
1068 heartbeat_t hb;
1069 heartbeat_init(&hb);
1070 - usec_t step = update_every * USEC_PER_SEC;
1070 + int counter = update_every - 1;
1071 //This will be cancelled by its parent
1072 while (!ebpf_exit_plugin) {
1073 - (void)heartbeat_next(&hb, step);
1074 - if (ebpf_exit_plugin)
1075 - break;
1073 + (void)heartbeat_next(&hb, USEC_PER_SEC);
1074 +
1075 + if (ebpf_exit_plugin || ++counter != update_every)
1076 + continue;
1077
1078 + counter = 0;
1079 netdata_apps_integration_flags_t apps = em->apps_charts;
1080 ebpf_cachestat_read_global_table();
1081 pthread_mutex_lock(&collect_data_mutex);
collectors/ebpf.plugin/ebpf_dcstat.c
+6 -4
@@ -985,12 +985,14 @@ static void dcstat_collector(ebpf_module_t *em)
985 int update_every = em->update_every;
986 heartbeat_t hb;
987 heartbeat_init(&hb);
988 - usec_t step = update_every * USEC_PER_SEC;
988 + int counter = update_every - 1;
989 while (!ebpf_exit_plugin) {
990 - (void)heartbeat_next(&hb, step);
991 - if (ebpf_exit_plugin)
992 - break;
990 + (void)heartbeat_next(&hb, USEC_PER_SEC);
991
992 + if (ebpf_exit_plugin || ++counter != update_every)
993 + continue;
994 +
995 + counter = 0;
996 netdata_apps_integration_flags_t apps = em->apps_charts;
997 ebpf_dc_read_global_table();
998 pthread_mutex_lock(&collect_data_mutex);
collectors/ebpf.plugin/ebpf_disk.c
+6 -4
@@ -689,12 +689,14 @@ static void disk_collector(ebpf_module_t *em)
689 int update_every = em->update_every;
690 heartbeat_t hb;
691 heartbeat_init(&hb);
692 - usec_t step = update_every * USEC_PER_SEC;
692 + int counter = update_every - 1;
693 while (!ebpf_exit_plugin) {
694 - (void)heartbeat_next(&hb, step);
695 - if (ebpf_exit_plugin)
696 - break;
694 + (void)heartbeat_next(&hb, USEC_PER_SEC);
695
696 + if (ebpf_exit_plugin || ++counter != update_every)
697 + continue;
698 +
699 + counter = 0;
700 read_hard_disk_tables(disk_maps[NETDATA_DISK_READ].map_fd);
701 pthread_mutex_lock(&lock);
702 ebpf_remove_pointer_from_plot_disk(em);
collectors/ebpf.plugin/ebpf_fd.c
+7 -4
@@ -924,12 +924,15 @@ static void fd_collector(ebpf_module_t *em)
924 int cgroups = em->cgroup_charts;
925 heartbeat_t hb;
926 heartbeat_init(&hb);
927 - usec_t step = em->update_every * USEC_PER_SEC;
927 + int update_every = em->update_every;
928 + int counter = update_every - 1;
929 while (!ebpf_exit_plugin) {
929 - (void)heartbeat_next(&hb, step);
930 - if (ebpf_exit_plugin)
931 - break;
930 + (void)heartbeat_next(&hb, USEC_PER_SEC);
931 +
932 + if (ebpf_exit_plugin || ++counter != update_every)
933 + continue;
934
935 + counter = 0;
936 netdata_apps_integration_flags_t apps = em->apps_charts;
937 ebpf_fd_read_global_table();
938 pthread_mutex_lock(&collect_data_mutex);
collectors/ebpf.plugin/ebpf_filesystem.c
+6 -4
@@ -502,12 +502,14 @@ static void filesystem_collector(ebpf_module_t *em)
502 int update_every = em->update_every;
503 heartbeat_t hb;
504 heartbeat_init(&hb);
505 - usec_t step = update_every * USEC_PER_SEC;
505 + int counter = update_every - 1;
506 while (!ebpf_exit_plugin) {
507 - (void)heartbeat_next(&hb, step);
508 - if (ebpf_exit_plugin)
509 - break;
507 + (void)heartbeat_next(&hb, USEC_PER_SEC);
508
509 + if (ebpf_exit_plugin || ++counter != update_every)
510 + continue;
511 +
512 + counter = 0;
513 ebpf_filesystem_read_hash(em);
514 pthread_mutex_lock(&lock);
515
collectors/ebpf.plugin/ebpf_hardirq.c
+7 -4
@@ -396,13 +396,16 @@ static void hardirq_collector(ebpf_module_t *em)
396 // loop and read from published data until ebpf plugin is closed.
397 heartbeat_t hb;
398 heartbeat_init(&hb);
399 - usec_t step = em->update_every * USEC_PER_SEC;
399 + int update_every = em->update_every;
400 + int counter = update_every - 1;
401 //This will be cancelled by its parent
402 while (!ebpf_exit_plugin) {
402 - (void)heartbeat_next(&hb, step);
403 - if (ebpf_exit_plugin)
404 - break;
403 + (void)heartbeat_next(&hb, USEC_PER_SEC);
404
405 + if (ebpf_exit_plugin || ++counter != update_every)
406 + continue;
407 +
408 + counter = 0;
409 hardirq_reader();
410 pthread_mutex_lock(&lock);
411
collectors/ebpf.plugin/ebpf_mdflush.c
+8 -5
@@ -201,23 +201,26 @@ static void mdflush_collector(ebpf_module_t *em)
201 {
202 mdflush_ebpf_vals = callocz(ebpf_nprocs, sizeof(mdflush_ebpf_val_t));
203
204 + int update_every = em->update_every;
205 avl_init_lock(&mdflush_pub, mdflush_val_cmp);
206
207 // create chart and static dims.
208 pthread_mutex_lock(&lock);
208 - mdflush_create_charts(em->update_every);
209 + mdflush_create_charts(update_every);
210 ebpf_update_stats(&plugin_statistics, em);
211 pthread_mutex_unlock(&lock);
212
213 // loop and read from published data until ebpf plugin is closed.
214 heartbeat_t hb;
215 heartbeat_init(&hb);
215 - usec_t step = em->update_every * USEC_PER_SEC;
216 + int counter = update_every - 1;
217 while (!ebpf_exit_plugin) {
217 - (void)heartbeat_next(&hb, step);
218 - if (ebpf_exit_plugin)
219 - break;
218 + (void)heartbeat_next(&hb, USEC_PER_SEC);
219
220 + if (ebpf_exit_plugin || ++counter != update_every)
221 + continue;
222 +
223 + counter = 0;
224 mdflush_read_count_map();
225 // write dims now for all hitherto discovered devices.
226 write_begin_chart("mdstat", "mdstat_flush");
collectors/ebpf.plugin/ebpf_mount.c
+6 -4
@@ -316,12 +316,14 @@ static void mount_collector(ebpf_module_t *em)
316
317 heartbeat_t hb;
318 heartbeat_init(&hb);
319 - usec_t step = em->update_every * USEC_PER_SEC;
319 + int update_every = em->update_every;
320 + int counter = update_every - 1;
321 while (!ebpf_exit_plugin) {
321 - (void)heartbeat_next(&hb, step);
322 - if (ebpf_exit_plugin)
323 - break;
322 + (void)heartbeat_next(&hb, USEC_PER_SEC);
323 + if (ebpf_exit_plugin || ++counter != update_every)
324 + continue;
325
326 + counter = 0;
327 ebpf_mount_read_global_table();
328 pthread_mutex_lock(&lock);
329
collectors/ebpf.plugin/ebpf_oomkill.c
+5 -4
@@ -296,12 +296,13 @@ static void oomkill_collector(ebpf_module_t *em)
296 // loop and read until ebpf plugin is closed.
297 heartbeat_t hb;
298 heartbeat_init(&hb);
299 - usec_t step = update_every * USEC_PER_SEC;
299 + int counter = update_every - 1;
300 while (!ebpf_exit_plugin) {
301 - (void)heartbeat_next(&hb, step);
302 - if (ebpf_exit_plugin)
303 - break;
301 + (void)heartbeat_next(&hb, USEC_PER_SEC);
302 + if (!ebpf_exit_plugin || ++counter != update_every)
303 + continue;
304
305 + counter = 0;
306 pthread_mutex_lock(&collect_data_mutex);
307 pthread_mutex_lock(&lock);
308
collectors/ebpf.plugin/ebpf_shm.c
+5 -4
@@ -847,12 +847,13 @@ static void shm_collector(ebpf_module_t *em)
847 int update_every = em->update_every;
848 heartbeat_t hb;
849 heartbeat_init(&hb);
850 - usec_t step = update_every * USEC_PER_SEC;
850 + int counter = update_every - 1;
851 while (!ebpf_exit_plugin) {
852 - (void)heartbeat_next(&hb, step);
853 - if (ebpf_exit_plugin)
854 - break;
852 + (void)heartbeat_next(&hb, USEC_PER_SEC);
853 + if (ebpf_exit_plugin || ++counter != update_every)
854 + continue;
855
856 + counter = 0;
857 netdata_apps_integration_flags_t apps = em->apps_charts;
858 ebpf_shm_read_global_table();
859 pthread_mutex_lock(&collect_data_mutex);
collectors/ebpf.plugin/ebpf_socket.c
+10 -11
@@ -2151,17 +2151,15 @@ static void read_listen_table()
2151 void *ebpf_socket_read_hash(void *ptr)
2152 {
2153 netdata_thread_cleanup_push(ebpf_socket_cleanup, ptr);
2154 - ebpf_module_t *em = (ebpf_module_t *)ptr;
2154
2155 heartbeat_t hb;
2156 heartbeat_init(&hb);
2158 - usec_t step = NETDATA_SOCKET_READ_SLEEP_MS * em->update_every;
2157 int fd_ipv4 = socket_maps[NETDATA_SOCKET_TABLE_IPV4].map_fd;
2158 int fd_ipv6 = socket_maps[NETDATA_SOCKET_TABLE_IPV6].map_fd;
2159 while (!ebpf_exit_plugin) {
2162 - (void)heartbeat_next(&hb, step);
2160 + (void)heartbeat_next(&hb, USEC_PER_SEC);
2161 if (ebpf_exit_plugin)
2164 - break;
2162 + continue;
2163
2164 pthread_mutex_lock(&nv_mutex);
2165 ebpf_read_socket_hash_table(fd_ipv4, AF_INET);
@@ -2854,10 +2852,9 @@ static void ebpf_socket_send_cgroup_data(int update_every)
2852 /**
2853 * Main loop for this collector.
2854 *
2857 - * @param step the number of microseconds used with heart beat
2855 * @param em the structure with thread information
2856 */
2860 -static void socket_collector(usec_t step, ebpf_module_t *em)
2857 +static void socket_collector(ebpf_module_t *em)
2858 {
2859 heartbeat_t hb;
2860 heartbeat_init(&hb);
@@ -2877,18 +2874,20 @@ static void socket_collector(usec_t step, ebpf_module_t *em)
2874
2875 int socket_global_enabled = em->global_charts;
2876 int update_every = em->update_every;
2877 + int counter = update_every - 1;
2878 while (!ebpf_exit_plugin) {
2881 - (void)heartbeat_next(&hb, step);
2882 - if (ebpf_exit_plugin)
2883 - break;
2879 + (void)heartbeat_next(&hb, USEC_PER_SEC);
2880 + if (ebpf_exit_plugin || ++counter != update_every)
2881 + continue;
2882
2883 + counter = 0;
2884 netdata_apps_integration_flags_t socket_apps_enabled = em->apps_charts;
2886 - pthread_mutex_lock(&collect_data_mutex);
2885 if (socket_global_enabled) {
2886 read_listen_table();
2887 read_hash_global_tables();
2888 }
2889
2890 + pthread_mutex_lock(&collect_data_mutex);
2891 if (socket_apps_enabled)
2892 ebpf_socket_update_apps_data();
2893
@@ -3968,7 +3967,7 @@ void *ebpf_socket_thread(void *ptr)
3967
3968 pthread_mutex_unlock(&lock);
3969
3971 - socket_collector((usec_t)(em->update_every * USEC_PER_SEC), em);
3970 + socket_collector(em);
3971
3972 endsocket:
3973 ebpf_update_disabled_plugin_stats(em);
collectors/ebpf.plugin/ebpf_softirq.c
+6 -4
@@ -169,13 +169,15 @@ static void softirq_collector(ebpf_module_t *em)
169 // loop and read from published data until ebpf plugin is closed.
170 heartbeat_t hb;
171 heartbeat_init(&hb);
172 - usec_t step = em->update_every * USEC_PER_SEC;
172 + int update_every = em->update_every;
173 + int counter = update_every - 1;
174 //This will be cancelled by its parent
175 while (!ebpf_exit_plugin) {
175 - (void)heartbeat_next(&hb, step);
176 - if (ebpf_exit_plugin)
177 - break;
176 + (void)heartbeat_next(&hb, USEC_PER_SEC);
177 + if (ebpf_exit_plugin || ++counter != update_every)
178 + continue;
179
180 + counter = 0;
181 softirq_read_latency_map();
182 pthread_mutex_lock(&lock);
183
collectors/ebpf.plugin/ebpf_swap.c
+5 -4
@@ -661,12 +661,13 @@ static void swap_collector(ebpf_module_t *em)
661 int update_every = em->update_every;
662 heartbeat_t hb;
663 heartbeat_init(&hb);
664 - usec_t step = update_every * USEC_PER_SEC;
664 + int counter = update_every - 1;
665 while (!ebpf_exit_plugin) {
666 - (void)heartbeat_next(&hb, step);
667 - if (ebpf_exit_plugin)
668 - break;
666 + (void)heartbeat_next(&hb, USEC_PER_SEC);
667 + if (ebpf_exit_plugin || ++counter != update_every)
668 + continue;
669
670 + counter = 0;
671 netdata_apps_integration_flags_t apps = em->apps_charts;
672 ebpf_swap_read_global_table();
673 pthread_mutex_lock(&collect_data_mutex);
collectors/ebpf.plugin/ebpf_sync.c
+6 -4
@@ -398,12 +398,14 @@ static void sync_collector(ebpf_module_t *em)
398 {
399 heartbeat_t hb;
400 heartbeat_init(&hb);
401 - usec_t step = em->update_every * USEC_PER_SEC;
401 + int update_every = em->update_every;
402 + int counter = update_every - 1;
403 while (!ebpf_exit_plugin) {
403 - (void)heartbeat_next(&hb, step);
404 - if (ebpf_exit_plugin)
405 - break;
404 + (void)heartbeat_next(&hb, USEC_PER_SEC);
405 + if (ebpf_exit_plugin || ++counter != update_every)
406 + continue;
407
408 + counter = 0;
409 ebpf_sync_read_global_table();
410 pthread_mutex_lock(&lock);
411
collectors/ebpf.plugin/ebpf_vfs.c
+6 -4
@@ -1470,12 +1470,14 @@ static void vfs_collector(ebpf_module_t *em)
1470 int cgroups = em->cgroup_charts;
1471 heartbeat_t hb;
1472 heartbeat_init(&hb);
1473 - usec_t step = em->update_every * USEC_PER_SEC;
1473 + int update_every = em->update_every;
1474 + int counter = update_every - 1;
1475 while (!ebpf_exit_plugin) {
1475 - (void)heartbeat_next(&hb, step);
1476 - if (ebpf_exit_plugin)
1477 - break;
1476 + (void)heartbeat_next(&hb, USEC_PER_SEC);
1477 + if (ebpf_exit_plugin || ++counter != update_every)
1478 + continue;
1479
1480 + counter = 0;
1481 netdata_apps_integration_flags_t apps = em->apps_charts;
1482 ebpf_vfs_read_global_table();
1483 pthread_mutex_lock(&collect_data_mutex);