From 9f25a1ca2fbf1edc03fab629ef4746bcf3858d37 Mon Sep 17 00:00:00 2001 From: thiagoftsm Date: Thu, 28 May 2020 15:47:12 +0000 Subject: eBPF modular (#9148) Convert the monolithic ebpf.plugin in a modular plugin. --- collectors/ebpf.plugin/ebpf.h | 118 ++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 56 deletions(-) (limited to 'collectors/ebpf.plugin/ebpf.h') diff --git a/collectors/ebpf.plugin/ebpf.h b/collectors/ebpf.plugin/ebpf.h index 5f05389e02..72d40293a7 100644 --- a/collectors/ebpf.plugin/ebpf.h +++ b/collectors/ebpf.plugin/ebpf.h @@ -16,19 +16,6 @@ # include # include -# define NETDATA_GLOBAL_VECTOR 24 -# define NETDATA_MAX_MONITOR_VECTOR 9 -# define NETDATA_VFS_ERRORS 3 -# define NETDATA_PROCESS_ERRORS 4 - -# define NETDATA_DEL_START 2 -# define NETDATA_IN_START_BYTE 3 -# define NETDATA_EXIT_START 5 -# define NETDATA_PROCESS_START 7 -# define NETDATA_PROCESS_RUNNING_COUNT 9 - -# define NETDATA_EBPF_PROCESS_THREADS (uint32_t)3 - # include # include # include @@ -40,6 +27,7 @@ # include "../../libnetdata/clocks/clocks.h" # include "../../libnetdata/config/appconfig.h" # include "../../libnetdata/ebpf/ebpf.h" +# include "../../daemon/main.h" typedef enum { MODE_RETURN = 0, //This attaches kprobe when the function returns @@ -84,26 +72,21 @@ typedef struct netdata_error_report { int err; }netdata_error_report_t; +typedef struct ebpf_module { + const char *thread_name; + const char *config_name; + int enabled; + void *(*start_routine) (void *); + int update_time; + int global_charts; + int apps_charts; + netdata_run_mode_t mode; + netdata_ebpf_events_t *probes; + uint32_t thread_id; +} ebpf_module_t; + //Chart defintions # define NETDATA_EBPF_FAMILY "ebpf" -# define NETDATA_FILE_GROUP "File" -# define NETDATA_VFS_GROUP "VFS" -# define NETDATA_PROCESS_GROUP "Process" - -# define NETDATA_FILE_OPEN_CLOSE_COUNT "file_descriptor" -# define NETDATA_FILE_OPEN_ERR_COUNT "file_error" -# define NETDATA_VFS_FILE_CLEAN_COUNT "deleted_objects" -# define NETDATA_VFS_FILE_IO_COUNT "io" -# define NETDATA_VFS_FILE_ERR_COUNT "io_error" - -# define NETDATA_EXIT_SYSCALL "exit" -# define NETDATA_PROCESS_SYSCALL "process_thread" -# define NETDATA_PROCESS_ERROR_NAME "task_error" -# define NETDATA_PROCESS_STATUS_NAME "process_status" - -# define NETDATA_VFS_IO_FILE_BYTES "io_bytes" -# define NETDATA_VFS_DIM_IN_FILE_BYTES "write" -# define NETDATA_VFS_DIM_OUT_FILE_BYTES "read" //Log file # define NETDATA_DEVELOPER_LOG_FILE "developer.log" @@ -116,40 +99,63 @@ typedef struct netdata_error_report { # define NETDATA_KERNEL_V5_3 328448 # define NETDATA_KERNEL_V4_15 265984 -//Index from kernel -# define NETDATA_KEY_CALLS_DO_SYS_OPEN 0 -# define NETDATA_KEY_ERROR_DO_SYS_OPEN 1 -# define NETDATA_KEY_CALLS_VFS_WRITE 2 -# define NETDATA_KEY_ERROR_VFS_WRITE 3 -# define NETDATA_KEY_BYTES_VFS_WRITE 4 +# define EBPF_MAX_MAPS 32 + + +//Threads +extern void *ebpf_process_thread(void *ptr); +extern void *ebpf_socket_thread(void *ptr); + +//Common variables +extern pthread_mutex_t lock; +extern int close_ebpf_plugin; +extern int ebpf_nprocs; +extern int running_on_kernel; +extern char *ebpf_plugin_dir; +extern char kernel_string[64]; +extern netdata_ebpf_events_t process_probes[]; +extern netdata_ebpf_events_t socket_probes[]; + +//Common functions +extern void ebpf_global_labels(netdata_syscall_stat_t *is, + netdata_publish_syscall_t *pio, + char **dim, + char **name, + int end); + +extern void ebpf_write_chart_cmd(char *type + , char *id + , char *axis + , char *web + , int order); + +extern void ebpf_write_global_dimension(char *n, char *d); -# define NETDATA_KEY_CALLS_VFS_READ 5 -# define NETDATA_KEY_ERROR_VFS_READ 6 -# define NETDATA_KEY_BYTES_VFS_READ 7 +extern void ebpf_create_global_dimension(void *ptr, int end); -# define NETDATA_KEY_CALLS_VFS_UNLINK 8 -# define NETDATA_KEY_ERROR_VFS_UNLINK 9 +extern void ebpf_create_chart(char *family + , char *name + , char *axis + , char *web + , int order + , void (*ncd)(void *, int) + , void *move + , int end); -# define NETDATA_KEY_CALLS_DO_EXIT 10 +extern void write_begin_chart(char *family, char *name); -# define NETDATA_KEY_CALLS_RELEASE_TASK 11 +extern void write_chart_dimension(char *dim, long long value); -# define NETDATA_KEY_CALLS_DO_FORK 12 -# define NETDATA_KEY_ERROR_DO_FORK 13 +extern void write_count_chart(char *name, char *family, netdata_publish_syscall_t *move, int end); -# define NETDATA_KEY_CALLS_CLOSE_FD 14 -# define NETDATA_KEY_ERROR_CLOSE_FD 15 +extern void write_err_chart(char *name, char *family, netdata_publish_syscall_t *move, int end); -# define NETDATA_KEY_CALLS_SYS_CLONE 16 -# define NETDATA_KEY_ERROR_SYS_CLONE 17 +void write_io_chart(char *chart, char *family, char *dwrite, char *dread, netdata_publish_vfs_common_t *pvc); -# define NETDATA_KEY_CALLS_VFS_WRITEV 18 -# define NETDATA_KEY_ERROR_VFS_WRITEV 19 -# define NETDATA_KEY_BYTES_VFS_WRITEV 20 +extern void fill_ebpf_functions(ebpf_functions_t *ef); -# define NETDATA_KEY_CALLS_VFS_READV 21 -# define NETDATA_KEY_ERROR_VFS_READV 22 -# define NETDATA_KEY_BYTES_VFS_READV 23 +# define EBPF_GLOBAL_SECTION "global" +# define EBPF_PROGRAMS_SECTION "ebpf programs" #endif -- cgit v1.2.3