Fix systemd chart update (eBPF) (#13884)
thiagoftsm committed
Nov 1, 2022 at 12:05 UTC
d4e0f112868da4bd6e1b39bc6fd0abcc154826de
11 files changed
+49
-145
collectors/ebpf.plugin/ebpf_cachestat.c
+4
-13
@@ -905,21 +905,16 @@ static void ebpf_create_systemd_cachestat_charts(int update_every)
905
* Send Cache Stat charts
906
*
907
* Send collected data to Netdata.
908
- *
909
- * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned
910
- * otherwise function returns 1 to avoid chart recreation
908
*/
912
-static int ebpf_send_systemd_cachestat_charts()
909
+static void ebpf_send_systemd_cachestat_charts()
910
{
914
- int ret = 1;
911
ebpf_cgroup_target_t *ect;
912
913
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_CACHESTAT_HIT_RATIO_CHART);
914
for (ect = ebpf_cgroup_pids; ect; ect = ect->next) {
915
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
916
write_chart_dimension(ect->name, (long long)ect->publish_cachestat.ratio);
921
- } else if (unlikely(ect->systemd))
922
- ret = 0;
917
+ }
918
}
919
write_end_chart();
920
@@ -946,8 +941,6 @@ static int ebpf_send_systemd_cachestat_charts()
941
}
942
}
943
write_end_chart();
949
-
950
- return ret;
944
}
945
946
/**
@@ -1071,13 +1064,11 @@ void ebpf_cachestat_send_cgroup_data(int update_every)
1064
1065
int has_systemd = shm_ebpf_cgroup.header->systemd_enabled;
1066
if (has_systemd) {
1074
- static int systemd_charts = 0;
1075
- if (!systemd_charts) {
1067
+ if (send_cgroup_chart) {
1068
ebpf_create_systemd_cachestat_charts(update_every);
1077
- systemd_charts = 1;
1069
}
1070
1080
- systemd_charts = ebpf_send_systemd_cachestat_charts();
1071
+ ebpf_send_systemd_cachestat_charts();
1072
}
1073
1074
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
collectors/ebpf.plugin/ebpf_cgroup.c
+8
-19
@@ -6,6 +6,7 @@
6
#include "ebpf_cgroup.h"
7
8
ebpf_cgroup_target_t *ebpf_cgroup_pids = NULL;
9
+int send_cgroup_chart = 0;
10
11
// --------------------------------------------------------------------------------------------------------------------
12
// Map shared memory
@@ -98,24 +99,6 @@ void ebpf_map_cgroup_shared_memory()
99
// --------------------------------------------------------------------------------------------------------------------
100
// Close and Cleanup
101
101
-/**
102
- * Close shared memory
103
- */
104
-void ebpf_close_cgroup_shm()
105
-{
106
- if (shm_sem_ebpf_cgroup != SEM_FAILED) {
107
- sem_close(shm_sem_ebpf_cgroup);
108
- sem_unlink(NETDATA_NAMED_SEMAPHORE_EBPF_CGROUP_NAME);
109
- shm_sem_ebpf_cgroup = SEM_FAILED;
110
- }
111
-
112
- if (shm_fd_ebpf_cgroup > 0) {
113
- close(shm_fd_ebpf_cgroup);
114
- shm_unlink(NETDATA_SHARED_MEMORY_EBPF_CGROUP_NAME);
115
- shm_fd_ebpf_cgroup = -1;
116
- }
117
-}
118
-
102
/**
103
* Clean Specific cgroup pid
104
*
@@ -259,7 +242,7 @@ static void ebpf_update_pid_link_list(ebpf_cgroup_target_t *ect, char *path)
242
*
243
* Set variable remove. If this variable is not reset, the structure will be removed from link list.
244
*/
262
- void ebpf_reset_updated_var()
245
+void ebpf_reset_updated_var()
246
{
247
ebpf_cgroup_target_t *ect;
248
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)
257
*/
258
void ebpf_parse_cgroup_shm_data()
259
{
260
+ static int previous = 0;
261
if (shm_ebpf_cgroup.header) {
262
sem_wait(shm_sem_ebpf_cgroup);
263
int i, end = shm_ebpf_cgroup.header->cgroup_root_count;
@@ -291,6 +275,11 @@ void ebpf_parse_cgroup_shm_data()
275
ebpf_update_pid_link_list(ect, ptr->path);
276
}
277
}
278
+ send_cgroup_chart = previous != shm_ebpf_cgroup.header->cgroup_root_count;
279
+ previous = shm_ebpf_cgroup.header->cgroup_root_count;
280
+#ifdef NETDATA_DEV_MODE
281
+ error("Updating cgroup %d (Previous: %d, Current: %d)", send_cgroup_chart, previous, shm_ebpf_cgroup.header->cgroup_root_count);
282
+#endif
283
pthread_mutex_unlock(&mutex_cgroup_shm);
284
285
sem_post(shm_sem_ebpf_cgroup);
collectors/ebpf.plugin/ebpf_cgroup.h
+1
-1
@@ -62,8 +62,8 @@ typedef struct ebpf_cgroup_target {
62
63
void ebpf_map_cgroup_shared_memory();
64
void ebpf_parse_cgroup_shm_data();
65
-void ebpf_close_cgroup_shm();
65
void ebpf_create_charts_on_systemd(char *id, char *title, char *units, char *family, char *charttype, int order,
66
char *algorithm, char *context, char *module, int update_every);
67
+extern int send_cgroup_chart;
68
69
#endif /* NETDATA_EBPF_CGROUP_H */
collectors/ebpf.plugin/ebpf_dcstat.c
+4
-13
@@ -893,21 +893,16 @@ static void ebpf_create_systemd_dc_charts(int update_every)
893
* Send Directory Cache charts
894
*
895
* Send collected data to Netdata.
896
- *
897
- * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned
898
- * otherwise function returns 1 to avoid chart recreation
896
*/
900
-static int ebpf_send_systemd_dc_charts()
897
+static void ebpf_send_systemd_dc_charts()
898
{
902
- int ret = 1;
899
collected_number value;
900
ebpf_cgroup_target_t *ect;
901
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_DC_HIT_CHART);
902
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
903
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
904
write_chart_dimension(ect->name, (long long) ect->publish_dc.ratio);
909
- } else if (unlikely(ect->systemd))
910
- ret = 0;
905
+ }
906
}
907
write_end_chart();
908
@@ -943,8 +938,6 @@ static int ebpf_send_systemd_dc_charts()
938
}
939
}
940
write_end_chart();
946
-
947
- return ret;
941
}
942
943
/**
@@ -999,13 +992,11 @@ void ebpf_dc_send_cgroup_data(int update_every)
992
993
int has_systemd = shm_ebpf_cgroup.header->systemd_enabled;
994
if (has_systemd) {
1002
- static int systemd_charts = 0;
1003
- if (!systemd_charts) {
995
+ if (send_cgroup_chart) {
996
ebpf_create_systemd_dc_charts(update_every);
1005
- systemd_charts = 1;
997
}
998
1008
- systemd_charts = ebpf_send_systemd_dc_charts();
999
+ ebpf_send_systemd_dc_charts();
1000
}
1001
1002
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
collectors/ebpf.plugin/ebpf_fd.c
+4
-13
@@ -841,20 +841,15 @@ static void ebpf_create_systemd_fd_charts(ebpf_module_t *em)
841
* Send collected data to Netdata.
842
*
843
* @param em the main collector structure
844
- *
845
- * @return It returns the status for chart creation, if it is necessary to remove a specific dimension zero is returned
846
- * otherwise function returns 1 to avoid chart recreation
844
*/
848
-static int ebpf_send_systemd_fd_charts(ebpf_module_t *em)
845
+static void ebpf_send_systemd_fd_charts(ebpf_module_t *em)
846
{
850
- int ret = 1;
847
ebpf_cgroup_target_t *ect;
848
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_SYSCALL_APPS_FILE_OPEN);
849
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
850
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
851
write_chart_dimension(ect->name, ect->publish_systemd_fd.open_call);
856
- } else if (unlikely(ect->systemd))
857
- ret = 0;
852
+ }
853
}
854
write_end_chart();
855
@@ -885,8 +880,6 @@ static int ebpf_send_systemd_fd_charts(ebpf_module_t *em)
880
}
881
write_end_chart();
882
}
888
-
889
- return ret;
883
}
884
885
/**
@@ -907,13 +900,11 @@ static void ebpf_fd_send_cgroup_data(ebpf_module_t *em)
900
901
int has_systemd = shm_ebpf_cgroup.header->systemd_enabled;
902
if (has_systemd) {
910
- static int systemd_charts = 0;
911
- if (!systemd_charts) {
903
+ if (send_cgroup_chart) {
904
ebpf_create_systemd_fd_charts(em);
913
- systemd_charts = 1;
905
}
906
916
- systemd_charts = ebpf_send_systemd_fd_charts(em);
907
+ ebpf_send_systemd_fd_charts(em);
908
}
909
910
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
collectors/ebpf.plugin/ebpf_oomkill.c
+4
-13
@@ -132,25 +132,18 @@ static void ebpf_create_systemd_oomkill_charts(int update_every)
132
* Send Systemd charts
133
*
134
* Send collected data to Netdata.
135
- *
136
- * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned
137
- * otherwise function returns 1 to avoid chart recreation
135
*/
139
-static int ebpf_send_systemd_oomkill_charts()
136
+static void ebpf_send_systemd_oomkill_charts()
137
{
141
- int ret = 1;
138
ebpf_cgroup_target_t *ect;
139
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_OOMKILL_CHART);
140
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
141
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
142
write_chart_dimension(ect->name, (long long) ect->oomkill);
143
ect->oomkill = 0;
148
- } else if (unlikely(ect->systemd))
149
- ret = 0;
144
+ }
145
}
146
write_end_chart();
152
-
153
- return ret;
147
}
148
149
/*
@@ -199,12 +192,10 @@ void ebpf_oomkill_send_cgroup_data(int update_every)
192
193
int has_systemd = shm_ebpf_cgroup.header->systemd_enabled;
194
if (has_systemd) {
202
- static int systemd_charts = 0;
203
- if (!systemd_charts) {
195
+ if (send_cgroup_chart) {
196
ebpf_create_systemd_oomkill_charts(update_every);
205
- systemd_charts = 1;
197
}
207
- systemd_charts = ebpf_send_systemd_oomkill_charts();
198
+ ebpf_send_systemd_oomkill_charts();
199
}
200
201
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
collectors/ebpf.plugin/ebpf_process.c
+6
-15
@@ -973,20 +973,15 @@ static void ebpf_create_systemd_process_charts(ebpf_module_t *em)
973
* Send collected data to Netdata.
974
*
975
* @param em the structure with thread information
976
- *
977
- * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned
978
- * otherwise function returns 1 to avoid chart recreation
976
*/
980
-static int ebpf_send_systemd_process_charts(ebpf_module_t *em)
977
+static void ebpf_send_systemd_process_charts(ebpf_module_t *em)
978
{
982
- int ret = 1;
979
ebpf_cgroup_target_t *ect;
980
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_SYSCALL_APPS_TASK_PROCESS);
981
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
982
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
983
write_chart_dimension(ect->name, ect->publish_systemd_ps.create_process);
988
- } else if (unlikely(ect->systemd))
989
- ret = 0;
984
+ }
985
}
986
write_end_chart();
987
@@ -1023,8 +1018,6 @@ static int ebpf_send_systemd_process_charts(ebpf_module_t *em)
1018
}
1019
write_end_chart();
1020
}
1026
-
1027
- return ret;
1021
}
1022
1023
/**
@@ -1046,13 +1039,11 @@ static void ebpf_process_send_cgroup_data(ebpf_module_t *em)
1039
int has_systemd = shm_ebpf_cgroup.header->systemd_enabled;
1040
1041
if (has_systemd) {
1049
- static int systemd_chart = 0;
1050
- if (!systemd_chart) {
1042
+ if (send_cgroup_chart) {
1043
ebpf_create_systemd_process_charts(em);
1052
- systemd_chart = 1;
1044
}
1045
1055
- systemd_chart = ebpf_send_systemd_process_charts(em);
1046
+ ebpf_send_systemd_process_charts(em);
1047
}
1048
1049
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
@@ -1150,8 +1141,6 @@ static void process_collector(ebpf_module_t *em)
1141
update_apps_list = 0;
1142
cleanup_exited_pids();
1143
collect_data_for_all_processes(pid_fd);
1153
-
1154
- ebpf_create_apps_charts(apps_groups_root_target);
1144
}
1145
pthread_mutex_unlock(&collect_data_mutex);
1146
@@ -1162,6 +1151,8 @@ static void process_collector(ebpf_module_t *em)
1151
1152
netdata_apps_integration_flags_t apps_enabled = em->apps_charts;
1153
pthread_mutex_lock(&collect_data_mutex);
1154
+
1155
+ ebpf_create_apps_charts(apps_groups_root_target);
1156
if (all_pids_count > 0) {
1157
if (apps_enabled) {
1158
ebpf_process_update_apps_data();
collectors/ebpf.plugin/ebpf_shm.c
+4
-13
@@ -772,20 +772,15 @@ static void ebpf_create_systemd_shm_charts(int update_every)
772
* Send Systemd charts
773
*
774
* Send collected data to Netdata.
775
- *
776
- * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned
777
- * otherwise function returns 1 to avoid chart recreation
775
*/
779
-static int ebpf_send_systemd_shm_charts()
776
+static void ebpf_send_systemd_shm_charts()
777
{
781
- int ret = 1;
778
ebpf_cgroup_target_t *ect;
779
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_SHMGET_CHART);
780
for (ect = ebpf_cgroup_pids; ect; ect = ect->next) {
781
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
782
write_chart_dimension(ect->name, (long long)ect->publish_shm.get);
787
- } else if (unlikely(ect->systemd))
788
- ret = 0;
783
+ }
784
}
785
write_end_chart();
786
@@ -812,8 +807,6 @@ static int ebpf_send_systemd_shm_charts()
807
}
808
}
809
write_end_chart();
815
-
816
- return ret;
810
}
811
812
/*
@@ -861,13 +854,11 @@ void ebpf_shm_send_cgroup_data(int update_every)
854
855
int has_systemd = shm_ebpf_cgroup.header->systemd_enabled;
856
if (has_systemd) {
864
- static int systemd_charts = 0;
865
- if (!systemd_charts) {
857
+ if (send_cgroup_chart) {
858
ebpf_create_systemd_shm_charts(update_every);
867
- systemd_charts = 1;
859
}
860
870
- systemd_charts = ebpf_send_systemd_shm_charts();
861
+ ebpf_send_systemd_shm_charts();
862
}
863
864
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
collectors/ebpf.plugin/ebpf_socket.c
+6
-17
@@ -2709,20 +2709,15 @@ static void ebpf_create_systemd_socket_charts(int update_every)
2709
* Send Systemd charts
2710
*
2711
* Send collected data to Netdata.
2712
- *
2713
- * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned
2714
- * otherwise function returns 1 to avoid chart recreation
2712
*/
2716
-static int ebpf_send_systemd_socket_charts()
2713
+static void ebpf_send_systemd_socket_charts()
2714
{
2718
- int ret = 1;
2715
ebpf_cgroup_target_t *ect;
2716
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_NET_APPS_CONNECTION_TCP_V4);
2717
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
2718
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
2719
write_chart_dimension(ect->name, (long long)ect->publish_socket.call_tcp_v4_connection);
2724
- } else if (unlikely(ect->systemd))
2725
- ret = 0;
2720
+ }
2721
}
2722
write_end_chart();
2723
@@ -2730,8 +2725,7 @@ static int ebpf_send_systemd_socket_charts()
2725
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
2726
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
2727
write_chart_dimension(ect->name, (long long)ect->publish_socket.call_tcp_v6_connection);
2733
- } else
2734
- ret = 0;
2728
+ }
2729
}
2730
write_end_chart();
2731
@@ -2739,8 +2733,7 @@ static int ebpf_send_systemd_socket_charts()
2733
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
2734
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
2735
write_chart_dimension(ect->name, (long long)ect->publish_socket.bytes_sent);
2742
- } else
2743
- ret = 0;
2736
+ }
2737
}
2738
write_end_chart();
2739
@@ -2791,8 +2784,6 @@ static int ebpf_send_systemd_socket_charts()
2784
}
2785
}
2786
write_end_chart();
2794
-
2795
- return ret;
2787
}
2788
2789
/**
@@ -2828,12 +2819,10 @@ static void ebpf_socket_send_cgroup_data(int update_every)
2819
2820
int has_systemd = shm_ebpf_cgroup.header->systemd_enabled;
2821
if (has_systemd) {
2831
- static int systemd_charts = 0;
2832
- if (!systemd_charts) {
2822
+ if (send_cgroup_chart) {
2823
ebpf_create_systemd_socket_charts(update_every);
2834
- systemd_charts = 1;
2824
}
2836
- systemd_charts = ebpf_send_systemd_socket_charts();
2825
+ ebpf_send_systemd_socket_charts();
2826
}
2827
2828
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
collectors/ebpf.plugin/ebpf_swap.c
+4
-14
@@ -540,20 +540,15 @@ static void ebpf_swap_sum_cgroup_pids(netdata_publish_swap_t *swap, struct pid_o
540
* Send Systemd charts
541
*
542
* Send collected data to Netdata.
543
- *
544
- * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned
545
- * otherwise function returns 1 to avoid chart recreation
543
*/
547
-static int ebpf_send_systemd_swap_charts()
544
+static void ebpf_send_systemd_swap_charts()
545
{
549
- int ret = 1;
546
ebpf_cgroup_target_t *ect;
547
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_MEM_SWAP_READ_CHART);
548
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
549
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
550
write_chart_dimension(ect->name, (long long) ect->publish_systemd_swap.read);
555
- } else if (unlikely(ect->systemd))
556
- ret = 0;
551
+ }
552
}
553
write_end_chart();
554
@@ -564,8 +559,6 @@ static int ebpf_send_systemd_swap_charts()
559
}
560
}
561
write_end_chart();
567
-
568
- return ret;
562
}
563
564
/**
@@ -679,14 +672,11 @@ void ebpf_swap_send_cgroup_data(int update_every)
672
int has_systemd = shm_ebpf_cgroup.header->systemd_enabled;
673
674
if (has_systemd) {
682
- static int systemd_charts = 0;
683
- if (!systemd_charts) {
675
+ if (send_cgroup_chart) {
676
ebpf_create_systemd_swap_charts(update_every);
685
- systemd_charts = 1;
677
fflush(stdout);
678
}
688
-
689
- systemd_charts = ebpf_send_systemd_swap_charts();
679
+ ebpf_send_systemd_swap_charts();
680
}
681
682
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
collectors/ebpf.plugin/ebpf_vfs.c
+4
-14
@@ -1336,20 +1336,15 @@ static void ebpf_create_systemd_vfs_charts(ebpf_module_t *em)
1336
* Send collected data to Netdata.
1337
*
1338
* @param em the main collector structure
1339
- *
1340
- * @return It returns the status for chart creation, if it is necessary to remove a specific dimension, zero is returned
1341
- * otherwise function returns 1 to avoid chart recreation
1339
*/
1343
-static int ebpf_send_systemd_vfs_charts(ebpf_module_t *em)
1340
+static void ebpf_send_systemd_vfs_charts(ebpf_module_t *em)
1341
{
1345
- int ret = 1;
1342
ebpf_cgroup_target_t *ect;
1343
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_SYSCALL_APPS_FILE_DELETED);
1344
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
1345
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
1346
write_chart_dimension(ect->name, ect->publish_systemd_vfs.unlink_call);
1351
- } else if (unlikely(ect->systemd))
1352
- ret = 0;
1347
+ }
1348
}
1349
write_end_chart();
1350
@@ -1465,8 +1460,6 @@ static int ebpf_send_systemd_vfs_charts(ebpf_module_t *em)
1460
}
1461
write_end_chart();
1462
}
1468
-
1469
- return ret;
1463
}
1464
1465
/**
@@ -1487,13 +1480,10 @@ static void ebpf_vfs_send_cgroup_data(ebpf_module_t *em)
1480
1481
int has_systemd = shm_ebpf_cgroup.header->systemd_enabled;
1482
if (has_systemd) {
1490
- static int systemd_charts = 0;
1491
- if (!systemd_charts) {
1483
+ if (send_cgroup_chart) {
1484
ebpf_create_systemd_vfs_charts(em);
1493
- systemd_charts = 1;
1485
}
1495
-
1496
- systemd_charts = ebpf_send_systemd_vfs_charts(em);
1486
+ ebpf_send_systemd_vfs_charts(em);
1487
}
1488
1489
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {