Fixes compatibility with RH 7.x family (#8694)
Brings eBPF collector to RH 7.x family.
thiagoftsm committed
Apr 14, 2020 at 10:34 UTC
4c535a60d16335421d28bd2e1b12d659dcd89bde
4 files changed
+91
-4
collectors/ebpf_process.plugin/ebpf_process.c
+21
-3
@@ -72,6 +72,7 @@ static int use_stdout = 0;
72
struct config collector_config;
73
static int mykernel = 0;
74
static int nprocs;
75
+static int isrh;
76
uint32_t *hash_values;
77
78
pthread_mutex_t lock;
@@ -775,16 +776,24 @@ void set_global_variables() {
776
if (nprocs > NETDATA_MAX_PROCESSOR) {
777
nprocs = NETDATA_MAX_PROCESSOR;
778
}
779
+
780
+ isrh = get_redhat_release();
781
}
782
783
static void change_collector_event() {
784
int i;
785
+ if (mykernel < NETDATA_KERNEL_V5_3)
786
+ collector_events[10].name = NULL;
787
+
788
for (i = 0; collector_events[i].name ; i++ ) {
789
collector_events[i].type = 'p';
790
}
791
+}
792
786
- if (mykernel < 328448)
787
- collector_events[i].name = NULL;
793
+static void change_syscalls() {
794
+ static char *lfork = { "do_fork" };
795
+ id_names[7] = lfork;
796
+ collector_events[8].name = lfork;
797
}
798
799
static inline void what_to_load(char *ptr) {
@@ -796,6 +805,9 @@ static inline void what_to_load(char *ptr) {
805
*/
806
else
807
change_collector_event();
808
+
809
+ if (isrh >= NETDATA_MINIMUM_RH_VERSION && isrh < NETDATA_RH_8)
810
+ change_syscalls();
811
}
812
813
static inline void enable_debug(char *ptr) {
@@ -847,8 +859,10 @@ int main(int argc, char **argv)
859
(void)argv;
860
861
mykernel = get_kernel_version();
850
- if(!has_condition_to_run(mykernel))
862
+ if(!has_condition_to_run(mykernel)) {
863
+ error("[EBPF PROCESS] The current collector cannot run on this kernel.");
864
return 1;
865
+ }
866
867
//set name
868
program_name = "ebpf_process.plugin";
@@ -874,6 +888,9 @@ int main(int argc, char **argv)
888
889
if (load_collector_file(user_config_dir)) {
890
info("[EBPF PROCESS] does not have a configuration file. It is starting with default options.");
891
+ change_collector_event();
892
+ if (isrh >= NETDATA_MINIMUM_RH_VERSION && isrh < NETDATA_RH_8)
893
+ change_syscalls();
894
}
895
896
if(ebpf_load_libraries()) {
@@ -912,6 +929,7 @@ int main(int argc, char **argv)
929
930
if (pthread_mutex_init(&lock, NULL)) {
931
thread_finished++;
932
+ error("[EBPF PROCESS] Cannot start the mutex.");
933
int_exit(7);
934
}
935
collectors/ebpf_process.plugin/ebpf_process.h
+2
@@ -100,4 +100,6 @@ typedef struct netdata_error_report {
100
101
# define NETDATA_MAX_PROCESSOR 512
102
103
+# define NETDATA_KERNEL_V5_3 328448
104
+
105
#endif
libnetdata/ebpf/ebpf.c
+43
-1
@@ -91,8 +91,50 @@ int get_kernel_version() {
91
return ((int)(str2l(major)*65536) + (int)(str2l(minor)*256) + (int)str2l(patch));
92
}
93
94
+int get_redhat_release()
95
+{
96
+ char buffer[256];
97
+ int major,minor;
98
+ FILE *fp = fopen("/etc/redhat-release", "r");
99
+
100
+ if (fp) {
101
+ major = 0;
102
+ minor = -1;
103
+ size_t length = fread(buffer, sizeof(char), 255, fp);
104
+ if (length > 4 ) {
105
+ buffer[length] = '\0';
106
+ char *end = strchr(buffer, '.');
107
+ char *start;
108
+ if (end) {
109
+ *end = 0x0;
110
+
111
+ if (end > buffer) {
112
+ start = end - 1;
113
+
114
+ major = strtol( start, NULL, 10);
115
+ start = ++end;
116
+
117
+ end++;
118
+ if(end) {
119
+ end = 0x00;
120
+ minor = strtol( start, NULL, 10);
121
+ } else {
122
+ minor = -1;
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ fclose(fp);
129
+ return ((major*256) + minor);
130
+ } else {
131
+ return -1;
132
+ }
133
+}
134
+
135
static int has_ebpf_kernel_version(int version) {
95
- return (version >= 264960);
136
+ //Kernel 4.11.0 or RH > 7.5
137
+ return (version >= NETDATA_MINIMUM_EBPF_KERNEL || get_redhat_release() >= NETDATA_MINIMUM_RH_VERSION);
138
}
139
140
int has_condition_to_run(int version) {
libnetdata/ebpf/ebpf.h
+25
@@ -3,6 +3,30 @@
3
4
# define NETDATA_DEBUGFS "/sys/kernel/debug/tracing/"
5
6
+/**
7
+ * The next magic number is got doing the following math:
8
+ * 294960 = 4*65536 + 11*256 + 0
9
+ *
10
+ * For more details, please, read /usr/include/linux/version.h
11
+ */
12
+# define NETDATA_MINIMUM_EBPF_KERNEL 264960
13
+
14
+/**
15
+ * The RedHat magic number was got doing:
16
+ *
17
+ * 1797 = 7*256 + 5
18
+ *
19
+ * For more details, please, read /usr/include/linux/version.h
20
+ * in any Red Hat installation.
21
+ */
22
+# define NETDATA_MINIMUM_RH_VERSION 1797
23
+
24
+/**
25
+ * 2048 = 8*256 + 0
26
+ */
27
+# define NETDATA_RH_8 2048
28
+
29
+
30
typedef struct netdata_ebpf_events {
31
char type;
32
char *name;
@@ -11,6 +35,7 @@ typedef struct netdata_ebpf_events {
35
36
extern int clean_kprobe_events(FILE *out, int pid, netdata_ebpf_events_t *ptr);
37
extern int get_kernel_version();
38
+extern int get_redhat_release();
39
extern int has_condition_to_run(int version);
40
41
#endif