diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2020-05-18 21:03:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-19 11:03:32 +1000 |
commit | edeb82fac99246b7d572744fe1d732fd6d9cb34e (patch) | |
tree | 244bf54702edd4f96cc03b974a0174761a1436c9 /collectors/ebpf.plugin | |
parent | 3cf541f25558ef3b2f43b4bc857e64042a2d09e5 (diff) |
install and enable eBPF Plugin by default (#8665)
* netdata_installer_kernels: New kernels
This commit brings new kernels for our netdata-installer
* RH detection
This commit brings the RH detection to netdata-installer, but it cannot be
tested yet until we merge a PR on kernel-collector
* netdata_installer_kernels: RH kernels
This commit brings updates that allows to install and run the collectors
on RH
* netdata_installer_kernels: Kernel variables
This commit brings definitions instead magic number to the isntaller
* netdata_installer_kernels: remove echo
This commit removes echo to avoid new line
* netdata_installer_kernels: Move C code
This commit removes the C code that will be inserted in another PR
* Update eBPF install to use released version.
This updates the install code for the eBPF plugin to properly utilize
(and verify) a tagged release of the plugin instead of pulling the
upstream master branch.
It also adds support for using a local copy of the tarball, and switchs
the default behavior to install the eBPF plugin instead of not
installing it.
* Tidy-up messages relating to eBPF.
* Fix typos in error handling functions.
* ebpf-release: New kernels
This commit brings the kernels necessary to support Debian 10.0
* ebpf-release: Bring support for new package format
* ebpf-release: collector as loader
This commit brings the necessary changes for the collector loads all
the nfiles depending of the kernel it is running
* Update eBPF install to use released version.
This updates the install code for the eBPF plugin to properly utilize
(and verify) a tagged release of the plugin instead of pulling the
upstream master branch.
It also adds support for using a local copy of the tarball, and switchs
the default behavior to install the eBPF plugin instead of not
installing it.
* netdata_installer_kernels: New kernels
This commit brings new kernels for our netdata-installer
* RH detection
This commit brings the RH detection to netdata-installer, but it cannot be
tested yet until we merge a PR on kernel-collector
* netdata_installer_kernels: RH kernels
This commit brings updates that allows to install and run the collectors
on RH
* netdata_installer_kernels: Kernel variables
This commit brings definitions instead magic number to the isntaller
* netdata_installer_kernels: remove echo
This commit removes echo to avoid new line
* netdata_installer_kernels: Move C code
This commit removes the C code that will be inserted in another PR
* Tidy-up messages relating to eBPF.
* Fix typos in error handling functions.
* ebpf-release: New kernels
This commit brings the kernels necessary to support Debian 10.0
* ebpf-release: Bring support for new package format
* ebpf-release: collector as loader
This commit brings the necessary changes for the collector loads all
the nfiles depending of the kernel it is running
* Fix package name handling.
* Bump eBPF kernel-collector to v0.1.0
* Update --help to state eBPF is enabled by default and add --disable-ebpf option in --help output
* Remove deprecated kernel version compatibility checks
* Fix EBPF_TARBALL
* Remove libc path detection logic (deprecated0
* Use the new package structure of kernel-collector
* Relax the glob on netdata_ebpf as we may develop/distirbute other types of ebpf programs
* Fix ownership of ebpf libraries/programs
* Make the check-kernel-config.sh local to the installer
* Make plugins.ebpf = yes (by default)
Co-authored-by: Thiago Marques <thiagoftsm@gmail.com>
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Diffstat (limited to 'collectors/ebpf.plugin')
-rw-r--r-- | collectors/ebpf.plugin/ebpf.c | 84 |
1 files changed, 66 insertions, 18 deletions
diff --git a/collectors/ebpf.plugin/ebpf.c b/collectors/ebpf.plugin/ebpf.c index b3fa7f71bf..3648ad54c2 100644 --- a/collectors/ebpf.plugin/ebpf.c +++ b/collectors/ebpf.plugin/ebpf.c @@ -71,6 +71,7 @@ static int debug_log = 0; static int use_stdout = 0; struct config collector_config; static int mykernel = 0; +static char kernel_string[64]; static int nprocs; static int isrh; netdata_idx_t *hash_values; @@ -684,28 +685,69 @@ static int ebpf_load_libraries() { char *err = NULL; char lpath[4096]; + char netdatasl[128]; + char *libbase = { "libnetdata_ebpf.so" }; - build_complete_path(lpath, 4096, plugin_dir, "libnetdata_ebpf.so"); + snprintf(netdatasl, 127, "%s.%s", libbase, kernel_string); + build_complete_path(lpath, 4096, plugin_dir, netdatasl); libnetdata = dlopen(lpath, RTLD_LAZY); if (!libnetdata) { - error("[EBPF_PROCESS] Cannot load %s.", lpath); - return -1; + info("[EBPF_PROCESS] Cannot load library %s for the current kernel.", lpath); + + //Update kernel + char *library = ebpf_library_suffix(mykernel, (isrh < 0)?0:1); + size_t length = strlen(library); + strncpyz(kernel_string, library, length); + kernel_string[length] = '\0'; + + //Try to load the default version + snprintf(netdatasl, 127, "%s.%s", libbase, kernel_string); + build_complete_path(lpath, 4096, plugin_dir, netdatasl); + libnetdata = dlopen(lpath, RTLD_LAZY); + if (!libnetdata) { + error("[EBPF_PROCESS] Cannot load %s default library.", lpath); + return -1; + } else { + info("[EBPF_PROCESS] Default shared library %s loaded with success.", lpath); + } } else { - load_bpf_file = dlsym(libnetdata, "load_bpf_file"); + info("[EBPF_PROCESS] Current shared library %s loaded with success.", lpath); + } + + load_bpf_file = dlsym(libnetdata, "load_bpf_file"); + if ((err = dlerror()) != NULL) { + error("[EBPF_PROCESS] Cannot find load_bpf_file: %s", err); + return -1; + } + + map_fd = dlsym(libnetdata, "map_fd"); + if ((err = dlerror()) != NULL) { + error("[EBPF_PROCESS] Cannot find map_fd: %s", err); + return -1; + } + + bpf_map_lookup_elem = dlsym(libnetdata, "bpf_map_lookup_elem"); + if ((err = dlerror()) != NULL) { + error("[EBPF_PROCESS] Cannot find bpf_map_lookup_elem: %s", err); + return -1; + } + + if(mode == 1) { + set_bpf_perf_event = dlsym(libnetdata, "set_bpf_perf_event"); if ((err = dlerror()) != NULL) { - error("[EBPF_PROCESS] Cannot find load_bpf_file: %s", err); + error("[EBPF_PROCESS] Cannot find set_bpf_perf_event: %s", err); return -1; } - map_fd = dlsym(libnetdata, "map_fd"); + perf_event_unmap = dlsym(libnetdata, "perf_event_unmap"); if ((err = dlerror()) != NULL) { - error("[EBPF_PROCESS] Cannot find map_fd: %s", err); + error("[EBPF_PROCESS] Cannot find perf_event_unmap: %s", err); return -1; } - bpf_map_lookup_elem = dlsym(libnetdata, "bpf_map_lookup_elem"); + perf_event_mmap_header = dlsym(libnetdata, "perf_event_mmap_header"); if ((err = dlerror()) != NULL) { - error("[EBPF_PROCESS] Cannot find bpf_map_lookup_elem: %s", err); + error("[EBPF_PROCESS] Cannot find perf_event_mmap_header: %s", err); return -1; } @@ -739,24 +781,30 @@ static int ebpf_load_libraries() return 0; } -char *select_file() { - if(!mode) - return "rnetdata_ebpf_process.o"; - if(mode == MODE_DEVMODE) - return "dnetdata_ebpf_process.o"; +int select_file(char *name, int length) { + int ret = -1; + if (!mode) + ret = snprintf(name, (size_t)length, "rnetdata_ebpf_process.%s.o", kernel_string); + else if(mode == 1) + ret = snprintf(name, (size_t)length, "dnetdata_ebpf_process.%s.o", kernel_string); + else if(mode == 2) + ret = snprintf(name, (size_t)length, "pnetdata_ebpf_process.%s.o", kernel_string); - return "pnetdata_ebpf_process.o"; + return ret; } int process_load_ebpf() { char lpath[4096]; + char name[128]; - char *name = select_file(); + int test = select_file(name, 127); + if (test < 0 || test > 127) + return -1; build_complete_path(lpath, 4096, plugin_dir, name); event_pid = getpid(); - if (load_bpf_file(lpath, event_pid) ) { + if (load_bpf_file(lpath, event_pid)) { error("[EBPF_PROCESS] Cannot load program: %s", lpath); return -1; } else { @@ -1048,7 +1096,7 @@ int main(int argc, char **argv) { parse_args(argc, argv); - mykernel = get_kernel_version(); + mykernel = get_kernel_version(kernel_string, 63); if(!has_condition_to_run(mykernel)) { error("[EBPF PROCESS] The current collector cannot run on this kernel."); return 1; |