summaryrefslogtreecommitdiffstats
path: root/collectors/ebpf.plugin
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-14 18:12:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-14 18:12:10 +0000
commitb5321aff06d6ea8d730d62aec2ffd8e9271c1ffc (patch)
tree36c41e35994786456154f9d3bf88c324763aeea4 /collectors/ebpf.plugin
parentAdding upstream version 1.33.1. (diff)
downloadnetdata-b5321aff06d6ea8d730d62aec2ffd8e9271c1ffc.tar.xz
netdata-b5321aff06d6ea8d730d62aec2ffd8e9271c1ffc.zip
Adding upstream version 1.34.0.upstream/1.34.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/ebpf.plugin')
-rw-r--r--collectors/ebpf.plugin/README.md1101
-rw-r--r--collectors/ebpf.plugin/ebpf.c128
-rw-r--r--collectors/ebpf.plugin/ebpf.d/mount.conf13
-rw-r--r--collectors/ebpf.plugin/ebpf.d/network.conf12
-rw-r--r--collectors/ebpf.plugin/ebpf.d/shm.conf14
-rw-r--r--collectors/ebpf.plugin/ebpf.d/sync.conf13
-rw-r--r--collectors/ebpf.plugin/ebpf.h4
-rw-r--r--collectors/ebpf.plugin/ebpf_apps.c2
-rw-r--r--collectors/ebpf.plugin/ebpf_apps.h4
-rw-r--r--collectors/ebpf.plugin/ebpf_cachestat.c40
-rw-r--r--collectors/ebpf.plugin/ebpf_cgroup.c2
-rw-r--r--collectors/ebpf.plugin/ebpf_dcstat.c34
-rw-r--r--collectors/ebpf.plugin/ebpf_mount.c238
-rw-r--r--collectors/ebpf.plugin/ebpf_mount.h8
-rw-r--r--collectors/ebpf.plugin/ebpf_oomkill.c4
-rw-r--r--collectors/ebpf.plugin/ebpf_oomkill.h3
-rw-r--r--collectors/ebpf.plugin/ebpf_shm.c243
-rw-r--r--collectors/ebpf.plugin/ebpf_shm.h1
-rw-r--r--collectors/ebpf.plugin/ebpf_socket.c743
-rw-r--r--collectors/ebpf.plugin/ebpf_socket.h85
-rw-r--r--collectors/ebpf.plugin/ebpf_swap.c2
-rw-r--r--collectors/ebpf.plugin/ebpf_sync.c205
-rw-r--r--collectors/ebpf.plugin/ebpf_sync.h24
-rw-r--r--collectors/ebpf.plugin/ebpf_vfs.c36
-rw-r--r--collectors/ebpf.plugin/ebpf_vfs.h12
25 files changed, 2238 insertions, 733 deletions
diff --git a/collectors/ebpf.plugin/README.md b/collectors/ebpf.plugin/README.md
index babcd5206..c32133b1c 100644
--- a/collectors/ebpf.plugin/README.md
+++ b/collectors/ebpf.plugin/README.md
@@ -8,51 +8,405 @@ sidebar_label: "eBPF"
# eBPF monitoring with Netdata
-eBPF consists of a wide toolchain that ultimately outputs a set of bytecode that will run inside the eBPF virtual
-machine (VM) which lives inside the Linux kernel. The program in particular is executed in response to a [tracepoint
-or kprobe](#probes-and-tracepoints) activation.
+The Netdata Agent provides many [eBPF](https://ebpf.io/what-is-ebpf/) programs to help you troubleshoot and debug how applications interact with the Linux kernel. The `ebpf.plugin` uses [tracepoints, trampoline, and2 kprobes](#data-collection) to collect a wide array of high value data about the host that would otherwise be impossible to capture.
-Netdata has written many eBPF programs, which, when compiled and integrated into the Netdata Agent, are able to collect
-a wide array of data about the host that would otherwise be impossible. The data eBPF programs can collect is truly unique,
-which gives the Netdata Agent access to data that is high value but normally hard to capture.
+> ❗ eBPF monitoring only works on Linux systems and with specific Linux kernels, including all kernels newer than `4.11.0`, and all kernels on CentOS 7.6 or later. For kernels older than `4.11.0`, improved support is in active development.
-eBPF monitoring can help you troubleshoot and debug how applications interact with the Linux kernel. See
-our [guide on troubleshooting apps with eBPF metrics](/docs/guides/troubleshoot/monitor-debug-applications-ebpf.md) for
-configuration and troubleshooting tips.
+This document provides comprehensive details about the `ebpf.plugin`.
+For hands-on configuration and troubleshooting tips see our [tutorial on troubleshooting apps with eBPF metrics](/docs/guides/troubleshoot/monitor-debug-applications-ebpf.md).
<figure>
<img src="https://user-images.githubusercontent.com/1153921/74746434-ad6a1e00-5222-11ea-858a-a7882617ae02.png" alt="An example of VFS charts, made possible by the eBPF collector plugin" />
- <figcaption>An example of VFS charts made possible by the eBPF collector plugin.</figcaption>
+ <figcaption>An example of virtual file system (VFS) charts made possible by the eBPF collector plugin.</figcaption>
</figure>
-## Probes and Tracepoints
+<a id="data-collection"> </a>
-The following two features from the Linux kernel are used by Netdata to run eBPF programs:
+## How Netdata collects data using probes and tracepoints
-- Kprobes and return probes (kretprobe): Probes can insert virtually into any kernel instruction. When eBPF runs in
- `entry` mode, it attaches only `kprobes` for internal functions monitoring calls and some arguments every time a
- function is called. The user can also change configuration to use [`return`](#global) mode, and this will allow users
- to monitor return from these functions and detect possible failures.
-- Tracepoints are hooks to call specific functions. Tracepoints are more stable than `kprobes` and are preferred when
- both options are available.
+Netdata uses the following features from the Linux kernel to run eBPF programs:
-In each case, wherever a normal kprobe, kretprobe, or tracepoint would have run its hook function, an eBPF program is
-run instead, performing various collection logic before letting the kernel continue its normal control flow.
+- Tracepoints are hooks to call specific functions. Tracepoints are more stable than `kprobes` and are preferred when
+ both options are available.
+- Trampolines are bridges between kernel functions, and BPF programs. Netdata uses them by default whenever available.
+- Kprobes and return probes (`kretprobe`): Probes can insert virtually into any kernel instruction. When eBPF runs in `entry` mode, it attaches only `kprobes` for internal functions monitoring calls and some arguments every time a function is called. The user can also change configuration to use [`return`](#global) mode, and this will allow users to monitor return from these functions and detect possible failures.
-There are more methods by which eBPF programs can be triggered but which are not currently supported, such as via uprobes
-which allow hooking into arbitrary user-space functions in a similar manner to kprobes.
+In each case, wherever a normal kprobe, kretprobe, or tracepoint would have run its hook function, an eBPF program is run instead, performing various collection logic before letting the kernel continue its normal control flow.
-## Manually enable the collector on Linux
+There are more methods to trigger eBPF programs, such as uprobes, but currently are not supported.
-**The eBPF collector is installed and enabled by default on most new installations of the Agent**. The eBPF collector
-does not currently work with [static build installations](/packaging/installer/methods/kickstart.md#static-builds) for kernels older
-than `4.11`, but improved support is in active development.
+## Configuring ebpf.plugin
-eBPF monitoring only works on Linux systems and with specific Linux kernels, including all kernels newer than `4.11.0`,
-and all kernels on CentOS 7.6 or later.
+The eBPF collector is installed and enabled by default on most new installations of the Agent.
+If your Agent is v1.22 or older, you may to enable the collector yourself.
-If your Agent is v1.22 or older, you may to enable the collector yourself. See the [configuration](#configuration)
-section for details.
+### Enable the eBPF collector
+
+To enable or disable the entire eBPF collector:
+
+1. Navigate to the [Netdata config directory](/docs/configure/nodes.md#the-netdata-config-directory).
+ ```bash
+ cd /etc/netdata
+ ```
+
+2. Use the [`edit-config`](/docs/configure/nodes.md#use-edit-config-to-edit-configuration-files) script to edit `netdata.conf`.
+
+ ```bash
+ ./edit-config netdata.conf
+ ```
+
+3. Enable the collector by scrolling down to the `[plugins]` section. Uncomment the line `ebpf` (not
+ `ebpf_process`) and set it to `yes`.
+
+ ```conf
+ [plugins]
+ ebpf = yes
+ ```
+
+### Configure the eBPF collector
+
+You can configure the eBPF collector's behavior to fine-tune which metrics you receive and [optimize performance]\(#performance opimization).
+
+To edit the `ebpf.d.conf`:
+
+1. Navigate to the [Netdata config directory](/docs/configure/nodes.md#the-netdata-config-directory).
+ ```bash
+ cd /etc/netdata
+ ```
+2. Use the [`edit-config`](/docs/configure/nodes.md#use-edit-config-to-edit-configuration-files) script to edit [`ebpf.d.conf`](https://github.com/netdata/netdata/blob/master/collectors/ebpf.plugin/ebpf.d.conf).
+
+ ```bash
+ ./edit-config ebpf.d.conf
+ ```
+
+ You can now edit the behavior of the eBPF collector. The following sections describe each configuration option in detail.
+
+### `[global]` configuration options
+
+The `[global]` section defines settings for the whole eBPF collector.
+
+#### eBPF load mode
+
+The collector uses two different eBPF programs. These programs rely on the same functions inside the kernel, but they
+monitor, process, and display different kinds of information.
+
+By default, this plugin uses the `entry` mode. Changing this mode can create significant overhead on your operating
+system, but also offer valuable information if you are developing or debugging software. The `ebpf load mode` option
+accepts the following values:
+
+- `entry`: This is the default mode. In this mode, the eBPF collector only monitors calls for the functions described in
+ the sections above, and does not show charts related to errors.
+- `return`: In the `return` mode, the eBPF collector monitors the same kernel functions as `entry`, but also creates new
+ charts for the return of these functions, such as errors. Monitoring function returns can help in debugging software,
+ such as failing to close file descriptors or creating zombie processes.
+- `update every`: Number of seconds used for eBPF to send data for Netdata.
+- `pid table size`: Defines the maximum number of PIDs stored inside the application hash table.
+
+#### Integration with `apps.plugin`
+
+The eBPF collector also creates charts for each running application through an integration with the
+[`apps.plugin`](/collectors/apps.plugin/README.md). This integration helps you understand how specific applications
+interact with the Linux kernel.
+
+If you want to _disable_ the integration with `apps.plugin` along with the above charts, change the setting `apps` to
+`no`.
+
+```conf
+[global]
+ apps = yes
+```
+
+When the integration is enabled, eBPF collector allocates memory for each process running. The total allocated memory
+has direct relationship with the kernel version. When the eBPF plugin is running on kernels newer than `4.15`, it uses
+per-cpu maps to speed up the update of hash tables. This also implies storing data for the same PID for each processor
+it runs.
+
+#### Integration with `cgroups.plugin`
+
+The eBPF collector also creates charts for each cgroup through an integration with the
+[`cgroups.plugin`](/collectors/cgroups.plugin/README.md). This integration helps you understand how a specific cgroup
+interacts with the Linux kernel.
+
+The integration with `cgroups.plugin` is disabled by default to avoid creating overhead on your system. If you want to
+_enable_ the integration with `cgroups.plugin`, change the `cgroups` setting to `yes`.
+
+```conf
+[global]
+ cgroups = yes
+```
+
+If you do not need to monitor specific metrics for your `cgroups`, you can enable `cgroups` inside
+`ebpf.d.conf`, and then disable the plugin for a specific `thread` by following the steps in the
+[Configuration](#configuration) section.
+
+#### Integration Dashboard Elements
+
+When an integration is enabled, your dashboard will also show the following cgroups and apps charts using low-level
+Linux metrics:
+
+> Note: The parenthetical accompanying each bulleted item provides the chart name.
+
+- mem
+ - Number of processes killed due out of memory. (`oomkills`)
+- process
+ - Number of processes created with `do_fork`. (`process_create`)
+ - Number of threads created with `do_fork` or `clone (2)`, depending on your system's kernel
+ version. (`thread_create`)
+ - Number of times that a process called `do_exit`. (`task_exit`)
+ - Number of times that a process called `release_task`. (`task_close`)
+ - Number of times that an error happened to create thread or process. (`task_error`)
+- swap
+ - Number of calls to `swap_readpage`. (`swap_read_call`)
+ - Number of calls to `swap_writepage`. (`swap_write_call`)
+- network
+ - Number of outbound connections using TCP/IPv4. (`outbound_conn_ipv4`)
+ - Number of outbound connections using TCP/IPv6. (`outbound_conn_ipv6`)
+ - Number of bytes sent. (`total_bandwidth_sent`)
+ - Number of bytes received. (`total_bandwidth_recv`)
+ - Number of calls to `tcp_sendmsg`. (`bandwidth_tcp_send`)
+ - Number of calls to `tcp_cleanup_rbuf`. (`bandwidth_tcp_recv`)
+ - Number of calls to `tcp_retransmit_skb`. (`bandwidth_tcp_retransmit`)
+ - Number of calls to `udp_sendmsg`. (`bandwidth_udp_send`)
+ - Number of calls to `udp_recvmsg`. (`bandwidth_udp_recv`)
+- file access
+ - Number of calls to open files. (`file_open`)
+ - Number of calls to open files that returned errors. (`open_error`)
+ - Number of files closed. (`file_closed`)
+ - Number of calls to close files that returned errors. (`file_error_closed`)
+- vfs
+ - Number of calls to `vfs_unlink`. (`file_deleted`)
+ - Number of calls to `vfs_write`. (`vfs_write_call`)
+ - Number of calls to write a file that returned errors. (`vfs_write_error`)
+ - Number of calls to `vfs_read`. (`vfs_read_call`)
+ - - Number of calls to read a file that returned errors. (`vfs_read_error`)
+ - Number of bytes written with `vfs_write`. (`vfs_write_bytes`)
+ - Number of bytes read with `vfs_read`. (`vfs_read_bytes`)
+ - Number of calls to `vfs_fsync`. (`vfs_fsync`)
+ - Number of calls to sync file that returned errors. (`vfs_fsync_error`)
+ - Number of calls to `vfs_open`. (`vfs_open`)
+ - Number of calls to open file that returned errors. (`vfs_open_error`)
+ - Number of calls to `vfs_create`. (`vfs_create`)
+ - Number of calls to open file that returned errors. (`vfs_create_error`)
+- page cache
+ - Ratio of pages accessed. (`cachestat_ratio`)
+ - Number of modified pages ("dirty"). (`cachestat_dirties`)
+ - Number of accessed pages. (`cachestat_hits`)
+ - Number of pages brought from disk. (`cachestat_misses`)
+- directory cache
+ - Ratio of files available in directory cache. (`dc_hit_ratio`)
+ - Number of files accessed. (`dc_reference`)
+ - Number of files accessed that were not in cache. (`dc_not_cache`)
+ - Number of files not found. (`dc_not_found`)
+- ipc shm
+ - Number of calls to `shm_get`. (`shmget_call`)
+ - Number of calls to `shm_at`. (`shmat_call`)
+ - Number of calls to `shm_dt`. (`shmdt_call`)
+ - Number of calls to `shm_ctl`. (`shmctl_call`)
+
+### `[ebpf programs]` configuration options
+
+The eBPF collector enables and runs the following eBPF programs by default:
+
+- `fd` : This eBPF program creates charts that show information about calls to open files.
+- `mount`: This eBPF program creates charts that show calls to syscalls mount(2) and umount(2).
+- `shm`: This eBPF program creates charts that show calls to syscalls shmget(2), shmat(2), shmdt(2) and shmctl(2).
+- `sync`: Monitor calls to syscalls sync(2), fsync(2), fdatasync(2), syncfs(2), msync(2), and sync_file_range(2).
+- `network viewer`: This eBPF program creates charts with information about `TCP` and `UDP` functions, including the
+ bandwidth consumed by each.
+- `vfs`: This eBPF program creates charts that show information about VFS (Virtual File System) functions.
+- `process`: This eBPF program creates charts that show information about process life. When in `return` mode, it also
+ creates charts showing errors when these operations are executed.
+- `hardirq`: This eBPF program creates charts that show information about time spent servicing individual hardware
+ interrupt requests (hard IRQs).
+- `softirq`: This eBPF program creates charts that show information about time spent servicing individual software
+ interrupt requests (soft IRQs).
+- `oomkill`: This eBPF program creates a chart that shows OOM kills for all applications recognized via
+ the `apps.plugin` integration. Note that this program will show application charts regardless of whether apps
+ integration is turned on or off.
+
+You can also enable the following eBPF programs:
+
+- `cachestat`: Netdata's eBPF data collector creates charts about the memory page cache. When the integration with
+ [`apps.plugin`](/collectors/apps.plugin/README.md) is enabled, this collector creates charts for the whole host _and_
+ for each application.
+- `dcstat` : This eBPF program creates charts that show information about file access using directory cache. It appends
+ `kprobes` for `lookup_fast()` and `d_lookup()` to identify if files are inside directory cache, outside and files are
+ not found.
+- `disk` : This eBPF program creates charts that show information about disk latency independent of filesystem.
+- `filesystem` : This eBPF program creates charts that show information about some filesystem latency.
+- `swap` : This eBPF program creates charts that show information about swap access.
+- `mdflush`: This eBPF program creates charts that show information about
+ multi-device software flushes.
+
+### Configuring eBPF threads
+
+You can configure each thread of the eBPF data collector. This allows you to overwrite global options defined in `/etc/netdata/ebpf.d.conf` and configure specific options for each thread.
+
+To configure an eBPF thread:
+
+1. Navigate to the [Netdata config directory](/docs/configure/nodes.md#the-netdata-config-directory).
+ ```bash
+ cd /etc/netdata
+ ```
+2. Use the [`edit-config`](/docs/configure/nodes.md#use-edit-config-to-edit-configuration-files) script to edit a thread configuration file. The following configuration files are available:
+
+ - `network.conf`: Configuration for the [`network` thread](#network-configuration). This config file overwrites the global options and also
+ lets you specify which network the eBPF collector monitors.
+ - `process.conf`: Configuration for the [`process` thread](#sync-configuration).
+ - `cachestat.conf`: Configuration for the `cachestat` thread(#filesystem-configuration).
+ - `dcstat.conf`: Configuration for the `dcstat` thread.
+ - `disk.conf`: Configuration for the `disk` thread.
+ - `fd.conf`: Configuration for the `file descriptor` thread.
+ - `filesystem.conf`: Configuration for the `filesystem` thread.
+ - `hardirq.conf`: Configuration for the `hardirq` thread.
+ - `softirq.conf`: Configuration for the `softirq` thread.
+ - `sync.conf`: Configuration for the `sync` thread.
+ - `vfs.conf`: Configuration for the `vfs` thread.
+
+ ```bash
+ ./edit-config FILE.conf
+ ```
+
+### Network configuration
+
+The network configuration has specific options to configure which network(s) the eBPF collector monitors. These options
+are divided in the following sections:
+
+#### `[network connections]`
+
+You can configure the information shown on `outbound` and `inbound` charts with the settings in this section.
+
+```conf
+[network connections]
+ maximum dimensions = 500
+ resolve hostname ips = no
+ ports = 1-1024 !145 !domain
+ hostnames = !example.com
+ ips = !127.0.0.1/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 fc00::/7
+```
+
+When you define a `ports` setting, Netdata will collect network metrics for that specific port. For example, if you
+write `ports = 19999`, Netdata will collect only connections for itself. The `hostnames` setting accepts
+[simple patterns](/libnetdata/simple_pattern/README.md). The `ports`, and `ips` settings accept negation (`!`) to deny
+specific values or asterisk alone to define all values.
+
+In the above example, Netdata will collect metrics for all ports between 1 and 443, with the exception of 53 (domain)
+and 145.
+
+The following options are available:
+
+- `ports`: Define the destination ports for Netdata to monitor.
+- `hostnames`: The list of hostnames that can be resolved to an IP address.
+- `ips`: The IP or range of IPs that you want to monitor. You can use IPv4 or IPv6 addresses, use dashes to define a
+ range of IPs, or use CIDR values. By default, only data for private IP addresses is collected, but this can
+ be changed with the `ips` setting.
+
+By default, Netdata displays up to 500 dimensions on network connection charts. If there are more possible dimensions,
+they will be bundled into the `other` dimension. You can increase the number of shown dimensions by changing
+the `maximum dimensions` setting.
+
+The dimensions for the traffic charts are created using the destination IPs of the sockets by default. This can be
+changed setting `resolve hostname ips = yes` and restarting Netdata, after this Netdata will create dimensions using
+the `hostnames` every time that is possible to resolve IPs to their hostnames.
+
+#### `[service name]`
+
+Netdata uses the list of services in `/etc/services` to plot network connection charts. If this file does not contain
+the name for a particular service you use in your infrastructure, you will need to add it to the `[service name]`
+section.
+
+For example, Netdata's default port (`19999`) is not listed in `/etc/services`. To associate that port with the Netdata
+service in network connection charts, and thus see the name of the service instead of its port, define it:
+
+```conf
+[service name]
+ 19999 = Netdata
+```
+
+### Sync configuration
+
+The sync configuration has specific options to disable monitoring for syscalls. All syscalls are monitored by default.
+
+```conf
+[syscalls]
+ sync = yes
+ msync = yes
+ fsync = yes
+ fdatasync = yes
+ syncfs = yes
+ sync_file_range = yes
+```
+
+### Filesystem configuration
+
+The filesystem configuration has specific options to disable monitoring for filesystems; by default, all filesystems are
+monitored.
+
+```conf
+[filesystem]
+ btrfsdist = yes
+ ext4dist = yes
+ nfsdist = yes
+ xfsdist = yes
+ zfsdist = yes
+```
+
+The ebpf program `nfsdist` monitors only `nfs` mount points.
+
+## Troubleshooting
+
+If the eBPF collector does not work, you can troubleshoot it by running the `ebpf.plugin` command and investigating its
+output.
+
+```bash
+cd /usr/libexec/netdata/plugins.d/
+sudo su -s /bin/bash ./ebpf.plugin
+```
+
+You can also use `grep` to search the Agent's `error.log` for messages related to eBPF monitoring.
+
+```bash
+grep -i ebpf /var/log/netdata/error.log
+```
+
+### Confirm kernel compatibility
+
+The eBPF collector only works on Linux systems and with specific Linux kernels. We support all kernels more recent than
+`4.11.0`, and all kernels on CentOS 7.6 or later.
+
+You can run our helper script to determine whether your system can support eBPF monitoring. If it returns no output, your system is ready to compile and run the eBPF collector.
+
+```bash
+curl -sSL https://raw.githubusercontent.com/netdata/kernel-collector/master/tools/check-kernel-config.sh | sudo bash
+```
+
+
+If you see a warning about a missing kernel
+configuration (`KPROBES KPROBES_ON_FTRACE HAVE_KPROBES BPF BPF_SYSCALL BPF_JIT`), you will need to recompile your kernel
+to support this configuration. The process of recompiling Linux kernels varies based on your distribution and version.
+Read the documentation for your system's distribution to learn more about the specific workflow for recompiling the
+kernel, ensuring that you set all the necessary
+
+- [Ubuntu](https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel)
+- [Debian](https://kernel-team.pages.debian.net/kernel-handbook/ch-common-tasks.html#s-common-official)
+- [Fedora](https://fedoraproject.org/wiki/Building_a_custom_kernel)
+- [CentOS](https://wiki.centos.org/HowTos/Custom_Kernel)
+- [Arch Linux](https://wiki.archlinux.org/index.php/Kernel/Traditional_compilation)
+- [Slackware](https://docs.slackware.com/howtos:slackware_admin:kernelbuilding)
+
+### Mount `debugfs` and `tracefs`
+
+The eBPF collector also requires both the `tracefs` and `debugfs` filesystems. Try mounting the `tracefs` and `debugfs`
+filesystems using the commands below:
+
+```bash
+sudo mount -t debugfs nodev /sys/kernel/debug
+sudo mount -t tracefs nodev /sys/kernel/tracing
+```
+
+If they are already mounted, you will see an error. You can also configure your system's `/etc/fstab` configuration to
+mount these filesystems on startup. More information can be found in
+the [ftrace documentation](https://www.kernel.org/doc/Documentation/trace/ftrace.txt).
## Charts
@@ -64,8 +418,7 @@ collected in the previous and current seconds.
### System overview
-Not all charts within the System Overview menu are enabled by default, because they add around 100ns overhead for each
-function call, this number is small for a human perspective, but the functions are called many times creating an impact
+Not all charts within the System Overview menu are enabled by default. Charts that rely on `kprobes` are disabled by default because they add around 100ns overhead for each function call. This is a small number from a human's perspective, but the functions are called many times and create an impact
on host. See the [configuration](#configuration) section for details about how to enable them.
#### Processes
@@ -74,12 +427,12 @@ Internally, the Linux kernel treats both processes and threads as `tasks`. To cr
system calls: `fork(2)`, `vfork(2)`, and `clone(2)`. To generate this chart, the eBPF
collector uses the following `tracepoints` and `kprobe`:
-- `sched/sched_process_fork`: Tracepoint called after a call for `fork (2)`, `vfork (2)` and `clone (2)`.
-- `sched/sched_process_exec`: Tracepoint called after a exec-family syscall.
-- `kprobe/kernel_clone`: This is the main [`fork()`](https://elixir.bootlin.com/linux/v5.10/source/kernel/fork.c#L2415)
- routine since kernel `5.10.0` was released.
-- `kprobe/_do_fork`: Like `kernel_clone`, but this was the main function between kernels `4.2.0` and `5.9.16`
-- `kprobe/do_fork`: This was the main function before kernel `4.2.0`.
+- `sched/sched_process_fork`: Tracepoint called after a call for `fork (2)`, `vfork (2)` and `clone (2)`.
+- `sched/sched_process_exec`: Tracepoint called after a exec-family syscall.
+- `kprobe/kernel_clone`: This is the main [`fork()`](https://elixir.bootlin.com/linux/v5.10/source/kernel/fork.c#L2415)
+ routine since kernel `5.10.0` was released.
+- `kprobe/_do_fork`: Like `kernel_clone`, but this was the main function between kernels `4.2.0` and `5.9.16`
+- `kprobe/do_fork`: This was the main function before kernel `4.2.0`.
#### Process Exit
@@ -88,9 +441,9 @@ system that the task is finishing its work. The second step is to release the ke
function `release_task`. The difference between the two dimensions can help you discover
[zombie processes](https://en.wikipedia.org/wiki/Zombie_process). To get the metrics, the collector uses:
-- `sched/sched_process_exit`: Tracepoint called after a task exits.
-- `kprobe/release_task`: This function is called when a process exits, as the kernel still needs to remove the process
- descriptor.
+- `sched/sched_process_exit`: Tracepoint called after a task exits.
+- `kprobe/release_task`: This function is called when a process exits, as the kernel still needs to remove the process
+ descriptor.
#### Task error
@@ -100,7 +453,7 @@ process and thread creation only.
#### Swap
Inside the swap submenu the eBPF plugin creates the chart `swapcalls`; this chart is displaying when processes are
-calling functions [`swap_readpage` and `swap_writepage`](https://hzliu123.github.io/linux-kernel/Page%20Cache%20in%20Linux%202.6.pdf ),
+calling functions [`swap_readpage` and `swap_writepage`](https://hzliu123.github.io/linux-kernel/Page%20Cache%20in%20Linux%202.6.pdf),
which are functions responsible for doing IO in swap memory. To collect the exact moment that an access to swap happens,
the collector attaches `kprobes` for cited functions.
@@ -108,91 +461,108 @@ the collector attaches `kprobes` for cited functions.
The following `tracepoints` are used to measure time usage for soft IRQs:
-- [`irq/softirq_entry`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_softirq_entry): Called
- before softirq handler
-- [`irq/softirq_exit`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_softirq_exit): Called when
- softirq handler returns.
+- [`irq/softirq_entry`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_softirq_entry): Called
+ before softirq handler
+- [`irq/softirq_exit`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_softirq_exit): Called when
+ softirq handler returns.
#### Hard IRQ
The following tracepoints are used to measure the latency of servicing a
hardware interrupt request (hard IRQ).
-- [`irq/irq_handler_entry`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_irq_handler_entry):
- Called immediately before the IRQ action handler.
-- [`irq/irq_handler_exit`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_irq_handler_exit):
- Called immediately after the IRQ action handler returns.
-- `irq_vectors`: These are traces from `irq_handler_entry` and
- `irq_handler_exit` when an IRQ is handled. The following elements from vector
- are triggered:
- - `irq_vectors/local_timer_entry`
- - `irq_vectors/local_timer_exit`
- - `irq_vectors/reschedule_entry`
- - `irq_vectors/reschedule_exit`
- - `irq_vectors/call_function_entry`
- - `irq_vectors/call_function_exit`
- - `irq_vectors/call_function_single_entry`
- - `irq_vectors/call_function_single_xit`
- - `irq_vectors/irq_work_entry`
- - `irq_vectors/irq_work_exit`
- - `irq_vectors/error_apic_entry`
- - `irq_vectors/error_apic_exit`
- - `irq_vectors/thermal_apic_entry`
- - `irq_vectors/thermal_apic_exit`
- - `irq_vectors/threshold_apic_entry`
- - `irq_vectors/threshold_apic_exit`
- - `irq_vectors/deferred_error_entry`
- - `irq_vectors/deferred_error_exit`
- - `irq_vectors/spurious_apic_entry`
- - `irq_vectors/spurious_apic_exit`
- - `irq_vectors/x86_platform_ipi_entry`
- - `irq_vectors/x86_platform_ipi_exit`
+- [`irq/irq_handler_entry`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_irq_handler_entry):
+ Called immediately before the IRQ action handler.
+- [`irq/irq_handler_exit`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_irq_handler_exit):
+ Called immediately after the IRQ action handler returns.
+- `irq_vectors`: These are traces from `irq_handler_entry` and
+ `irq_handler_exit` when an IRQ is handled. The following elements from vector
+ are triggered:
+ - `irq_vectors/local_timer_entry`
+ - `irq_vectors/local_timer_exit`
+ - `irq_vectors/reschedule_entry`
+ - `irq_vectors/reschedule_exit`
+ - `irq_vectors/call_function_entry`
+ - `irq_vectors/call_function_exit`
+ - `irq_vectors/call_function_single_entry`
+ - `irq_vectors/call_function_single_xit`
+ - `irq_vectors/irq_work_entry`
+ - `irq_vectors/irq_work_exit`
+ - `irq_vectors/error_apic_entry`
+ - `irq_vectors/error_apic_exit`
+ - `irq_vectors/thermal_apic_entry`
+ - `irq_vectors/thermal_apic_exit`
+ - `irq_vectors/threshold_apic_entry`
+ - `irq_vectors/threshold_apic_exit`
+ - `irq_vectors/deferred_error_entry`
+ - `irq_vectors/deferred_error_exit`
+ - `irq_vectors/spurious_apic_entry`
+ - `irq_vectors/spurious_apic_exit`
+ - `irq_vectors/x86_platform_ipi_entry`
+ - `irq_vectors/x86_platform_ipi_exit`
#### IPC shared memory
-To monitor shared memory system call counts, the following `kprobes` are used:
+To monitor shared memory system call counts, Netdata attaches tracing in the following functions:
-- `shmget`: Runs when [`shmget`](https://man7.org/linux/man-pages/man2/shmget.2.html) is called.
-- `shmat`: Runs when [`shmat`](https://man7.org/linux/man-pages/man2/shmat.2.html) is called.
-- `shmdt`: Runs when [`shmdt`](https://man7.org/linux/man-pages/man2/shmat.2.html) is called.
-- `shmctl`: Runs when [`shmctl`](https://man7.org/linux/man-pages/man2/shmctl.2.html) is called.
+- `shmget`: Runs when [`shmget`](https://man7.org/linux/man-pages/man2/shmget.2.html) is called.
+- `shmat`: Runs when [`shmat`](https://man7.org/linux/man-pages/man2/shmat.2.html) is called.
+- `shmdt`: Runs when [`shmdt`](https://man7.org/linux/man-pages/man2/shmat.2.html) is called.
+- `shmctl`: Runs when [`shmctl`](https://man7.org/linux/man-pages/man2/shmctl.2.html) is called.
### Memory
In the memory submenu the eBPF plugin creates two submenus **page cache** and **synchronization** with the following
organization:
-* Page Cache
- * Page cache ratio
- * Dirty pages
- * Page cache hits
- * Page cache misses
-* Synchronization
- * File sync
- * Memory map sync
- * File system sync
- * File range sync
+- Page Cache
+ - Page cache ratio
+ - Dirty pages
+ - Page cache hits
+ - Page cache misses
+- Synchronization
+ - File sync
+ - Memory map sync
+ - File system sync
+ - File range sync
-#### Page cache ratio
+#### Page cache hits
-The chart `cachestat_ratio` shows how processes are accessing page cache. In a normal scenario, we expect values around
-100%, which means that the majority of the work on the machine is processed in memory. To calculate the ratio, Netdata
-attaches `kprobes` for kernel functions:
+When the processor needs to read or write a location in main memory, it checks for a corresponding entry in the page cache.
+ If the entry is there, a page cache hit has occurred and the read is from the cache.
-- `add_to_page_cache_lru`: Page addition.
-- `mark_page_accessed`: Access to cache.
-- `account_page_dirtied`: Dirty (modified) pages.
-- `mark_buffer_dirty`: Writes to page cache.
+A page cache hit is when the page cache is successfully accessed with a read operation. We do not count pages that were
+added relatively recently.
#### Dirty pages
+A "dirty page" is a page in the page cache that was modified after being created. Since non-dirty pages in the page cache
+ have identical copies in secondary storage (e.g. hard disk drive or solid-state drive), discarding and reusing their space
+ is much quicker than paging out application memory, and is often preferred over flushing the dirty pages into secondary storage
+ and reusing their space.
+
On `cachestat_dirties` Netdata demonstrates the number of pages that were modified. This chart shows the number of calls
to the function `mark_buffer_dirty`.
-#### Page cache hits
+#### Page cache ratio
-A page cache hit is when the page cache is successfully accessed with a read operation. We do not count pages that were
-added relatively recently.
+When the processor needs to read or write in a specific memory address, it checks for a corresponding entry in the page cache.
+If the processor hits a page cache (`page cache hit`), it reads the entry from the cache. If there is no entry (`page cache miss`),
+ the kernel allocates a new entry and copies data from the disk. Netdata calculates the percentage of accessed files that are cached on
+ memory. The ratio is calculated counting the accessed cached pages
+ (without counting [dirty pages](#dirty-pages) and pages added because of read misses) divided by total access without dirty pages.
+
+> \_\_**\_\_\_\_**<ins>Number of accessed cached pages</ins>\***\*\_\_\*\***<br/>
+> Number of total accessed pages - dirty pages - missed pages
+
+The chart `cachestat_ratio` shows how processes are accessing page cache. In a normal scenario, we expect values around
+100%, which means that the majority of the work on the machine is processed in memory. To calculate the ratio, Netdata
+attaches `kprobes` for kernel functions:
+
+- `add_to_page_cache_lru`: Page addition.
+- `mark_page_accessed`: Access to cache.
+- `account_page_dirtied`: Dirty (modified) pages.
+- `mark_buffer_dirty`: Writes to page cache.
#### Page cache misses
@@ -213,7 +583,7 @@ changes to a file that was mapped into memory using [`mmap(2)`](https://man7.org
#### File system sync
-This chart monitors calls demonstrating commits from filesystem caches to disk. Netdata attaches `kprobes` for
+This chart monitors calls demonstrating commits from filesystem caches to disk. Netdata attaches `tracing` for
[`sync(2)`](https://man7.org/linux/man-pages/man2/sync.2.html), and [`syncfs(2)`](https://man7.org/linux/man-pages/man2/sync.2.html).
#### File range sync
@@ -240,23 +610,35 @@ By default, MD flush is disabled. To enable it, configure your
To collect data related to Linux multi-device (MD) flushing, the following kprobe is used:
-- `kprobe/md_flush_request`: called whenever a request for flushing multi-device data is made.
+- `kprobe/md_flush_request`: called whenever a request for flushing multi-device data is made.
### Disk
-The eBPF plugin also shows a chart in the Disk section when the `disk` thread is enabled. This will create the
-chart `disk_latency_io` for each disk on the host. The following tracepoints are used:
+The eBPF plugin also shows a chart in the Disk section when the `disk` thread is enabled.
+
+#### Disk Latency
+
+This will create the chart `disk_latency_io` for each disk on the host. The following tracepoints are used:
-- [`block/block_rq_issue`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_block_rq_issue):
- IO request operation to a device drive.
-- [`block/block_rq_complete`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_block_rq_complete):
- IO operation completed by device.
+- [`block/block_rq_issue`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_block_rq_issue):
+ IO request operation to a device drive.
+- [`block/block_rq_complete`](https://www.kernel.org/doc/html/latest/core-api/tracepoint.html#c.trace_block_rq_complete):
+ IO operation completed by device.
+
+Disk Latency is the single most important metric to focus on when it comes to storage performance, under most circumstances.
+For hard drives, an average latency somewhere between 10 to 20 ms can be considered acceptable. For SSD (Solid State Drives),
+in most cases, workloads experience less than 1 ms latency numbers, but workloads should never reach higher than 3 ms.
+The dimensions refer to time intervals.
### Filesystem
-This group has charts demonstrating how applications interact with the Linux
-kernel to open and close file descriptors. It also brings latency charts for
-several different filesystems.
+This group has charts demonstrating how applications interact with the Linux kernel to open and close file descriptors.
+It also brings latency charts for several different filesystems.
+
+#### Latency Algorithm
+
+We calculate the difference between the calling and return times, spanning disk I/O, file system operations (lock, I/O),
+run queue latency and all events related to the monitored action.
#### ext4
@@ -265,10 +647,10 @@ To measure the latency of executing some actions in an
collector needs to attach `kprobes` and `kretprobes` for each of the following
functions:
-- `ext4_file_read_iter`: Function used to measure read latency.
-- `ext4_file_write_iter`: Function used to measure write latency.
-- `ext4_file_open`: Function used to measure open latency.
-- `ext4_sync_file`: Function used to measure sync latency.
+- `ext4_file_read_iter`: Function used to measure read latency.
+- `ext4_file_write_iter`: Function used to measure write latency.
+- `ext4_file_open`: Function used to measure open latency.
+- `ext4_sync_file`: Function used to measure sync latency.
#### ZFS
@@ -276,10 +658,10 @@ To measure the latency of executing some actions in a zfs filesystem, the
collector needs to attach `kprobes` and `kretprobes` for each of the following
functions:
-- `zpl_iter_read`: Function used to measure read latency.
-- `zpl_iter_write`: Function used to measure write latency.
-- `zpl_open`: Function used to measure open latency.
-- `zpl_fsync`: Function used to measure sync latency.
+- `zpl_iter_read`: Function used to measure read latency.
+- `zpl_iter_write`: Function used to measure write latency.
+- `zpl_open`: Function used to measure open latency.
+- `zpl_fsync`: Function used to measure sync latency.
#### XFS
@@ -288,10 +670,10 @@ To measure the latency of executing some actions in an
collector needs to attach `kprobes` and `kretprobes` for each of the following
functions:
-- `xfs_file_read_iter`: Function used to measure read latency.
-- `xfs_file_write_iter`: Function used to measure write latency.
-- `xfs_file_open`: Function used to measure open latency.
-- `xfs_file_fsync`: Function used to measure sync latency.
+- `xfs_file_read_iter`: Function used to measure read latency.
+- `xfs_file_write_iter`: Function used to measure write latency.
+- `xfs_file_open`: Function used to measure open latency.
+- `xfs_file_fsync`: Function used to measure sync latency.
#### NFS
@@ -300,11 +682,11 @@ To measure the latency of executing some actions in an
collector needs to attach `kprobes` and `kretprobes` for each of the following
functions:
-- `nfs_file_read`: Function used to measure read latency.
-- `nfs_file_write`: Function used to measure write latency.
-- `nfs_file_open`: Functions used to measure open latency.
-- `nfs4_file_open`: Functions used to measure open latency for NFS v4.
-- `nfs_getattr`: Function used to measure sync latency.
+- `nfs_file_read`: Function used to measure read latency.
+- `nfs_file_write`: Function used to measure write latency.
+- `nfs_file_open`: Functions used to measure open latency.
+- `nfs4_file_open`: Functions used to measure open latency for NFS v4.
+- `nfs_getattr`: Function used to measure sync latency.
#### btrfs
@@ -312,26 +694,26 @@ To measure the latency of executing some actions in a [btrfs](https://elixir.boo
filesystem, the collector needs to attach `kprobes` and `kretprobes` for each of the following functions:
> Note: We are listing two functions used to measure `read` latency, but we use either `btrfs_file_read_iter` or
-`generic_file_read_iter`, depending on kernel version.
+> `generic_file_read_iter`, depending on kernel version.
-- `btrfs_file_read_iter`: Function used to measure read latency since kernel `5.10.0`.
-- `generic_file_read_iter`: Like `btrfs_file_read_iter`, but this function was used before kernel `5.10.0`.
-- `btrfs_file_write_iter`: Function used to write data.
-- `btrfs_file_open`: Function used to open files.
-- `btrfs_sync_file`: Function used to synchronize data to filesystem.
+- `btrfs_file_read_iter`: Function used to measure read latency since kernel `5.10.0`.
+- `generic_file_read_iter`: Like `btrfs_file_read_iter`, but this function was used before kernel `5.10.0`.
+- `btrfs_file_write_iter`: Function used to write data.
+- `btrfs_file_open`: Function used to open files.
+- `btrfs_sync_file`: Function used to synchronize data to filesystem.
#### File descriptor
To give metrics related to `open` and `close` events, instead of attaching kprobes for each syscall used to do these
events, the collector attaches `kprobes` for the common function used for syscalls:
-- [`do_sys_open`](https://0xax.gitbooks.io/linux-insides/content/SysCall/linux-syscall-5.html ): Internal function used to
- open files.
-- [`do_sys_openat2`](https://elixir.bootlin.com/linux/v5.6/source/fs/open.c#L1162):
- Function called from `do_sys_open` since version `5.6.0`.
-- [`close_fd`](https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg2271761.html): Function used to close file
- descriptor since kernel `5.11.0`.
-- `__close_fd`: Function used to close files before version `5.11.0`.
+- [`do_sys_open`](https://0xax.gitbooks.io/linux-insides/content/SysCall/linux-syscall-5.html): Internal function used to
+ open files.
+- [`do_sys_openat2`](https://elixir.bootlin.com/linux/v5.6/source/fs/open.c#L1162):
+ Function called from `do_sys_open` since version `5.6.0`.
+- [`close_fd`](https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg2271761.html): Function used to close file
+ descriptor since kernel `5.11.0`.
+- `__close_fd`: Function used to close files before version `5.11.0`.
#### File error
@@ -351,22 +733,22 @@ To measure the latency and total quantity of executing some VFS-level
functions, ebpf.plugin needs to attach kprobes and kretprobes for each of the
following functions:
-- `vfs_write`: Function used monitoring the number of successful & failed
- filesystem write calls, as well as the total number of written bytes.
-- `vfs_writev`: Same function as `vfs_write` but for vector writes (i.e. a
- single write operation using a group of buffers rather than 1).
-- `vfs_read`: Function used for monitoring the number of successful & failed
- filesystem read calls, as well as the total number of read bytes.
-- `vfs_readv` Same function as `vfs_read` but for vector reads (i.e. a single
- read operation using a group of buffers rather than 1).
-- `vfs_unlink`: Function used for monitoring the number of successful & failed
- filesystem unlink calls.
-- `vfs_fsync`: Function used for monitoring the number of successful & failed
- filesystem fsync calls.
-- `vfs_open`: Function used for monitoring the number of successful & failed
- filesystem open calls.
-- `vfs_create`: Function used for monitoring the number of successful & failed
- filesystem create calls.
+- `vfs_write`: Function used monitoring the number of successful & failed
+ filesystem write calls, as well as the total number of written bytes.
+- `vfs_writev`: Same function as `vfs_write` but for vector writes (i.e. a
+ single write operation using a group of buffers rather than 1).
+- `vfs_read`: Function used for monitoring the number of successful & failed
+ filesystem read calls, as well as the total number of read bytes.
+- `vfs_readv` Same function as `vfs_read` but for vector reads (i.e. a single
+ read operation using a group of buffers rather than 1).
+- `vfs_unlink`: Function used for monitoring the number of successful & failed
+ filesystem unlink calls.
+- `vfs_fsync`: Function used for monitoring the number of successful & failed
+ filesystem fsync calls.
+- `vfs_open`: Function used for monitoring the number of successful & failed
+ filesystem open calls.
+- `vfs_create`: Function used for monitoring the number of successful & failed
+ filesystem create calls.
##### VFS Deleted objects
@@ -406,30 +788,49 @@ Metrics for directory cache are collected using kprobe for `lookup_fast`, becaus
times this function is accessed. On the other hand, for `d_lookup` we are not only interested in the number of times it
is accessed, but also in possible errors, so we need to attach a `kretprobe`. For this reason, the following is used:
-- [`lookup_fast`](https://lwn.net/Articles/649115/): Called to look at data inside the directory cache.
-- [`d_lookup`](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/dcache.c?id=052b398a43a7de8c68c13e7fa05d6b3d16ce6801#n2223):
- Called when the desired file is not inside the directory cache.
+- [`lookup_fast`](https://lwn.net/Articles/649115/): Called to look at data inside the directory cache.
+- [`d_lookup`](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/dcache.c?id=052b398a43a7de8c68c13e7fa05d6b3d16ce6801#n2223):
+ Called when the desired file is not inside the directory cache.
+
+##### Directory Cache Interpretation
+
+When directory cache is showing 100% that means that every accessed file was present in the directory cache.
+If files are not present in the directory cache, they are either not present in the file system or the files were not
+accessed before.
### Mount Points
-The following `kprobes` are used to collect `mount` & `unmount` call counts:
+The following `tracing` are used to collect `mount` & `unmount` call counts:
-- [`mount`](https://man7.org/linux/man-pages/man2/mount.2.html): mount filesystem on host.
-- [`umount`](https://man7.org/linux/man-pages/man2/umount.2.html): umount filesystem on host.
+- [`mount`](https://man7.org/linux/man-pages/man2/mount.2.html): mount filesystem on host.
+- [`umount`](https://man7.org/linux/man-pages/man2/umount.2.html): umount filesystem on host.
### Networking Stack
-Netdata monitors socket bandwidth attaching `kprobes` for internal functions.
+Netdata monitors socket bandwidth attaching `tracing` for internal functions.
+
+#### TCP outbound connections
+
+This chart demonstrates calls to `tcp_v4_connection` and `tcp_v6_connection` that start connections for IPV4 and IPV6, respectively.
-#### TCP functions
+#### TCP inbound connections
+
+This chart demonstrates TCP and UDP connections that the host receives.
+To collect this information, netdata attaches a tracing to `inet_csk_accept`.
+
+#### TCP bandwidth functions
This chart demonstrates calls to functions `tcp_sendmsg`, `tcp_cleanup_rbuf`, and `tcp_close`; these functions are used
to send & receive data and to close connections when `TCP` protocol is used.
#### TCP bandwidth
-Like the previous chart, this one also monitors `tcp_sendmsg` and `tcp_cleanup_rbuf`, but instead of showing the number
-of calls, it demonstrates the number of bytes sent and received.
+This chart demonstrates calls to functions:
+
+- `tcp_sendmsg`: Function responsible to send data for a specified destination.
+- `tcp_cleanup_rbuf`: We use this function instead of `tcp_recvmsg`, because the last one misses `tcp_read_sock` traffic
+ and we would also need to add more `tracing` to get the socket and package size.
+- `tcp_close`: Function responsible to close connection.
#### TCP retransmit
@@ -452,359 +853,11 @@ calls, it monitors the number of bytes sent and received.
These are tracepoints related to [OOM](https://en.wikipedia.org/wiki/Out_of_memory) killing processes.
-- `oom/mark_victim`: Monitors when an oomkill event happens.
-
-## Configuration
-
-Enable or disable the entire eBPF collector by editing `netdata.conf`.
-
-```bash
-cd /etc/netdata/ # Replace with your Netdata configuration directory, if not /etc/netdata/
-./edit-config netdata.conf
-```
-
-To enable the collector, scroll down to the `[plugins]` section ensure the relevant line references `ebpf` (not
-`ebpf_process`), is uncommented, and is set to `yes`.
-
-```conf
-[plugins]
- ebpf = yes
-```
-
-You can also configure the eBPF collector's behavior by editing `ebpf.d.conf`.
-
-```bash
-cd /etc/netdata/ # Replace with your Netdata configuration directory, if not /etc/netdata/
-./edit-config ebpf.d.conf
-```
-
-### `[global]`
-
-The `[global]` section defines settings for the whole eBPF collector.
-
-#### eBPF load mode
-
-The collector has two different eBPF programs. These programs monitor the same functions inside the kernel, but they
-monitor, process, and display different kinds of information.
-
-By default, this plugin uses the `entry` mode. Changing this mode can create significant overhead on your operating
-system, but also offer valuable information if you are developing or debugging software. The `ebpf load mode` option
-accepts the following values: ​
-
-- `entry`: This is the default mode. In this mode, the eBPF collector only monitors calls for the functions described in
- the sections above, and does not show charts related to errors.
-- `return`: In the `return` mode, the eBPF collector monitors the same kernel functions as `entry`, but also creates new
- charts for the return of these functions, such as errors. Monitoring function returns can help in debugging software,
- such as failing to close file descriptors or creating zombie processes.
-- `update every`: Number of seconds used for eBPF to send data for Netdata.
-- `pid table size`: Defines the maximum number of PIDs stored inside the application hash table.
-
-#### Integration with `apps.plugin`
-
-The eBPF collector also creates charts for each running application through an integration with the
-[`apps.plugin`](/collectors/apps.plugin/README.md). This integration helps you understand how specific applications
-interact with the Linux kernel.
-
-If you want to _disable_ the integration with `apps.plugin` along with the above charts, change the setting `apps` to
-`no`.
-
-```conf
-[global]
- apps = yes
-```
-
-When the integration is enabled, eBPF collector allocates memory for each process running. The total allocated memory
-has direct relationship with the kernel version. When the eBPF plugin is running on kernels newer than `4.15`, it uses
-per-cpu maps to speed up the update of hash tables. This also implies storing data for the same PID for each processor
-it runs.
-
-#### Integration with `cgroups.plugin`
-
-The eBPF collector also creates charts for each cgroup through an integration with the
-[`cgroups.plugin`](/collectors/cgroups.plugin/README.md). This integration helps you understand how a specific cgroup
-interacts with the Linux kernel.
-
-The integration with `cgroups.plugin` is disabled by default to avoid creating overhead on your system. If you want to
-_enable_ the integration with `cgroups.plugin`, change the `cgroups` setting to `yes`.
-
-```conf
-[global]
- cgroups = yes
-```
-
-If you do not need to monitor specific metrics for your `cgroups`, you can enable `cgroups` inside
-`ebpf.d.conf`, and then disable the plugin for a specific `thread` by following the steps in the
-[Configuration](#configuration) section.
-
-#### Integration Dashboard Elements
-
-When an integration is enabled, your dashboard will also show the following cgroups and apps charts using low-level
-Linux metrics:
-
-> Note: The parenthetical accompanying each bulleted item provides the chart name.
-
-- mem
- - Number of processes killed due out of memory. (`oomkills`)
-- process
- - Number of processes created with `do_fork`. (`process_create`)
- - Number of threads created with `do_fork` or `clone (2)`, depending on your system's kernel
- version. (`thread_create`)
- - Number of times that a process called `do_exit`. (`task_exit`)
- - Number of times that a process called `release_task`. (`task_close`)
- - Number of times that an error happened to create thread or process. (`task_error`)
-- swap
- - Number of calls to `swap_readpage`. (`swap_read_call`)
- - Number of calls to `swap_writepage`. (`swap_write_call`)
-- network
- - Number of bytes sent. (`total_bandwidth_sent`)
- - Number of bytes received. (`total_bandwidth_recv`)
- - Number of calls to `tcp_sendmsg`. (`bandwidth_tcp_send`)
- - Number of calls to `tcp_cleanup_rbuf`. (`bandwidth_tcp_recv`)
- - Number of calls to `tcp_retransmit_skb`. (`bandwidth_tcp_retransmit`)
- - Number of calls to `udp_sendmsg`. (`bandwidth_udp_send`)
- - Number of calls to `udp_recvmsg`. (`bandwidth_udp_recv`)
-- file access
- - Number of calls to open files. (`file_open`)
- - Number of calls to open files that returned errors. (`open_error`)
- - Number of files closed. (`file_closed`)
- - Number of calls to close files that returned errors. (`file_error_closed`)
-- vfs
- - Number of calls to `vfs_unlink`. (`file_deleted`)
- - Number of calls to `vfs_write`. (`vfs_write_call`)
- - Number of calls to write a file that returned errors. (`vfs_write_error`)
- - Number of calls to `vfs_read`. (`vfs_read_call`)
- - Number of bytes written with `vfs_write`. (`vfs_write_bytes`)
- - Number of bytes read with `vfs_read`. (`vfs_read_bytes`)
- - Number of calls to read a file that returned errors. (`vfs_read_error`)
- - Number of calls to `vfs_fsync`. (`vfs_fsync`)
- - Number of calls to sync file that returned errors. (`vfs_fsync_error`)
- - Number of calls to `vfs_open`. (`vfs_open`)
- - Number of calls to open file that returned errors. (`vfs_open_error`)
- - Number of calls to `vfs_create`. (`vfs_create`)
- - Number of calls to open file that returned errors. (`vfs_create_error`)
-- page cache
- - Ratio of pages accessed. (`cachestat_ratio`)
- - Number of modified pages ("dirty"). (`cachestat_dirties`)
- - Number of accessed pages. (`cachestat_hits`)
- - Number of pages brought from disk. (`cachestat_misses`)
-- directory cache
- - Ratio of files available in directory cache. (`dc_hit_ratio`)
- - Number of files accessed. (`dc_reference`)
- - Number of files accessed that were not in cache. (`dc_not_cache`)
- - Number of files not found. (`dc_not_found`)
-- ipc shm
- - Number of calls to `shm_get`. (`shmget_call`)
- - Number of calls to `shm_at`. (`shmat_call`)
- - Number of calls to `shm_dt`. (`shmdt_call`)
- - Number of calls to `shm_ctl`. (`shmctl_call`)
-
-### `[ebpf programs]`
-
-The eBPF collector enables and runs the following eBPF programs by default:
-
-- `fd` : This eBPF program creates charts that show information about calls to open files.
-- `mount`: This eBPF program creates charts that show calls to syscalls mount(2) and umount(2).
-- `shm`: This eBPF program creates charts that show calls to syscalls shmget(2), shmat(2), shmdt(2) and shmctl(2).
-- `sync`: Monitor calls to syscalls sync(2), fsync(2), fdatasync(2), syncfs(2), msync(2), and sync_file_range(2).
-- `network viewer`: This eBPF program creates charts with information about `TCP` and `UDP` functions, including the
- bandwidth consumed by each.
-- `vfs`: This eBPF program creates charts that show information about VFS (Virtual File System) functions.
-- `process`: This eBPF program creates charts that show information about process life. When in `return` mode, it also
- creates charts showing errors when these operations are executed.
-- `hardirq`: This eBPF program creates charts that show information about time spent servicing individual hardware
- interrupt requests (hard IRQs).
-- `softirq`: This eBPF program creates charts that show information about time spent servicing individual software
- interrupt requests (soft IRQs).
-- `oomkill`: This eBPF program creates a chart that shows OOM kills for all applications recognized via
- the `apps.plugin` integration. Note that this program will show application charts regardless of whether apps
- integration is turned on or off.
-
-You can also enable the following eBPF programs:
-
-- `cachestat`: Netdata's eBPF data collector creates charts about the memory page cache. When the integration with
- [`apps.plugin`](/collectors/apps.plugin/README.md) is enabled, this collector creates charts for the whole host _and_
- for each application.
-- `dcstat` : This eBPF program creates charts that show information about file access using directory cache. It appends
- `kprobes` for `lookup_fast()` and `d_lookup()` to identify if files are inside directory cache, outside and files are
- not found.
-- `disk` : This eBPF program creates charts that show information about disk latency independent of filesystem.
-- `filesystem` : This eBPF program creates charts that show information about some filesystem latency.
-- `swap` : This eBPF program creates charts that show information about swap access.
-- `mdflush`: This eBPF program creates charts that show information about
- multi-device software flushes.
-
-## Thread configuration
-
-You can configure each thread of the eBPF data collector by editing either the `cachestat.conf`, `process.conf`,
-or `network.conf` files. Use [`edit-config`](/docs/configure/nodes.md) from your Netdata config directory:
-
-```bash
-cd /etc/netdata/ # Replace with your Netdata configuration directory, if not /etc/netdata/
-./edit-config ebpf.d/process.conf
-```
-
-### Configuration files
-
-The following configuration files are available:
-
-- `cachestat.conf`: Configuration for the `cachestat` thread.
-- `dcstat.conf`: Configuration for the `dcstat` thread.
-- `disk.conf`: Configuration for the `disk` thread.
-- `fd.conf`: Configuration for the `file descriptor` thread.
-- `filesystem.conf`: Configuration for the `filesystem` thread.
-- `hardirq.conf`: Configuration for the `hardirq` thread.
-- `process.conf`: Configuration for the `process` thread.
-- `network.conf`: Configuration for the `network viewer` thread. This config file overwrites the global options and also
- lets you specify which network the eBPF collector monitors.
-- `softirq.conf`: Configuration for the `softirq` thread.
-- `sync.conf`: Configuration for the `sync` thread.
-- `vfs.conf`: Configuration for the `vfs` thread.
-
-### Network configuration
-
-The network configuration has specific options to configure which network(s) the eBPF collector monitors. These options
-are divided in the following sections:
-
-#### `[network connections]`
-
-You can configure the information shown on `outbound` and `inbound` charts with the settings in this section.
-
-```conf
-[network connections]
- maximum dimensions = 500
- resolve hostname ips = no
- ports = 1-1024 !145 !domain
- hostnames = !example.com
- ips = !127.0.0.1/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 fc00::/7
-```
-
-When you define a `ports` setting, Netdata will collect network metrics for that specific port. For example, if you
-write `ports = 19999`, Netdata will collect only connections for itself. The `hostnames` setting accepts
-[simple patterns](/libnetdata/simple_pattern/README.md). The `ports`, and `ips` settings accept negation (`!`) to deny
-specific values or asterisk alone to define all values.
-
-In the above example, Netdata will collect metrics for all ports between 1 and 443, with the exception of 53 (domain)
-and 145.
-
-The following options are available:
-
-- `ports`: Define the destination ports for Netdata to monitor.
-- `hostnames`: The list of hostnames that can be resolved to an IP address.
-- `ips`: The IP or range of IPs that you want to monitor. You can use IPv4 or IPv6 addresses, use dashes to define a
- range of IPs, or use CIDR values. The default behavior is to only collect data for private IP addresses, but this can
- be changed with the `ips` setting.
-
-By default, Netdata displays up to 500 dimensions on network connection charts. If there are more possible dimensions,
-they will be bundled into the `other` dimension. You can increase the number of shown dimensions by changing
-the `maximum dimensions` setting.
-
-The dimensions for the traffic charts are created using the destination IPs of the sockets by default. This can be
-changed setting `resolve hostname ips = yes` and restarting Netdata, after this Netdata will create dimensions using
-the `hostnames` every time that is possible to resolve IPs to their hostnames.
-
-#### `[service name]`
-
-Netdata uses the list of services in `/etc/services` to plot network connection charts. If this file does not contain
-the name for a particular service you use in your infrastructure, you will need to add it to the `[service name]`
-section.
-
-For example, Netdata's default port (`19999`) is not listed in `/etc/services`. To associate that port with the Netdata
-service in network connection charts, and thus see the name of the service instead of its port, define it:
-
-```conf
-[service name]
- 19999 = Netdata
-```
-
-### Sync configuration
-
-The sync configuration has specific options to disable monitoring for syscalls, as default option all syscalls are
-monitored.
-
-```conf
-[syscalls]
- sync = yes
- msync = yes
- fsync = yes
- fdatasync = yes
- syncfs = yes
- sync_file_range = yes
-```
-
-### Filesystem configuration
-
-The filesystem configuration has specific options to disable monitoring for filesystems, by default all filesystems are
-monitored.
-
-```conf
-[filesystem]
- btrfsdist = yes
- ext4dist = yes
- nfsdist = yes
- xfsdist = yes
- zfsdist = yes
-```
-
-The ebpf program `nfsdist` monitors only `nfs` mount points.
-
-## Troubleshooting
-
-If the eBPF collector does not work, you can troubleshoot it by running the `ebpf.plugin` command and investigating its
-output.
-
-```bash
-cd /usr/libexec/netdata/plugins.d/
-sudo su -s /bin/bash netdata
-./ebpf.plugin
-```
-
-You can also use `grep` to search the Agent's `error.log` for messages related to eBPF monitoring.
-
-```bash
-grep -i ebpf /var/log/netdata/error.log
-```
+- `oom/mark_victim`: Monitors when an oomkill event happens.
-### Confirm kernel compatibility
+## Known issues
-The eBPF collector only works on Linux systems and with specific Linux kernels. We support all kernels more recent than
-`4.11.0`, and all kernels on CentOS 7.6 or later.
-
-You can run our helper script to determine whether your system can support eBPF monitoring.
-
-```bash
-curl -sSL https://raw.githubusercontent.com/netdata/kernel-collector/master/tools/check-kernel-config.sh | sudo bash
-```
-
-If this script returns no output, your system is ready to compile and run the eBPF collector.
-
-If you see a warning about a missing kernel
-configuration (`KPROBES KPROBES_ON_FTRACE HAVE_KPROBES BPF BPF_SYSCALL BPF_JIT`), you will need to recompile your kernel
-to support this configuration. The process of recompiling Linux kernels varies based on your distribution and version.
-Read the documentation for your system's distribution to learn more about the specific workflow for recompiling the
-kernel, ensuring that you set all the necessary
-
-- [Ubuntu](https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel)
-- [Debian](https://kernel-team.pages.debian.net/kernel-handbook/ch-common-tasks.html#s-common-official)
-- [Fedora](https://fedoraproject.org/wiki/Building_a_custom_kernel)
-- [CentOS](https://wiki.centos.org/HowTos/Custom_Kernel)
-- [Arch Linux](https://wiki.archlinux.org/index.php/Kernel/Traditional_compilation)
-- [Slackware](https://docs.slackware.com/howtos:slackware_admin:kernelbuilding)
-
-### Mount `debugfs` and `tracefs`
-
-The eBPF collector also requires both the `tracefs` and `debugfs` filesystems. Try mounting the `tracefs` and `debugfs`
-filesystems using the commands below:
-
-```bash
-sudo mount -t debugfs nodev /sys/kernel/debug
-sudo mount -t tracefs nodev /sys/kernel/tracing
-```
-
-If they are already mounted, you will see an error. You can also configure your system's `/etc/fstab` configuration to
-mount these filesystems on startup. More information can be found in
-the [ftrace documentation](https://www.kernel.org/doc/Documentation/trace/ftrace.txt).
-
-## Performance
+### Performance opimization
eBPF monitoring is complex and produces a large volume of metrics. We've discovered scenarios where the eBPF plugin
significantly increases kernel memory usage by several hundred MB.
@@ -817,7 +870,7 @@ usage (see the `system.ram` chart) has dropped significantly.
Beginning with `v1.31`, kernel memory usage is configurable via the [`pid table size` setting](#ebpf-load-mode)
in `ebpf.conf`.
-## SELinux
+### SELinux
When [SELinux](https://www.redhat.com/en/topics/linux/what-is-selinux) is enabled, it may prevent `ebpf.plugin` from
starting correctly. Check the Agent's `error.log` file for errors like the ones below:
@@ -837,7 +890,7 @@ ess.pl" exe="/usr/libexec/netdata/plugins.d/ebpf.plugin" subj=system_u:system_r:
If you see similar errors, you will have to adjust SELinux's policies to enable the eBPF collector.
-### Creation of bpf policies
+#### Creation of bpf policies
To enable `ebpf.plugin` to run on a distribution with SELinux enabled, it will be necessary to take the following
actions.
@@ -883,14 +936,14 @@ Finally, you can load the new policy and start the Netdata agent again:
# systemctl start netdata
```
-## Lockdown
+### Linux kernel lockdown
Beginning with [version 5.4](https://www.zdnet.com/article/linux-to-get-kernel-lockdown-feature/), the Linux kernel has
a feature called "lockdown," which may affect `ebpf.plugin` depending how the kernel was compiled. The following table
shows how the lockdown module impacts `ebpf.plugin` based on the selected options:
| Enforcing kernel lockdown | Enable lockdown LSM early in init | Default lockdown mode | Can `ebpf.plugin` run with this? |
-|:------------------------- |:--------------------------------- |:--------------------- |:-------------------------------- |
+| :------------------------ | :-------------------------------- | :-------------------- | :------------------------------- |
| YES | NO | NO | YES |
| YES | Yes | None | YES |
| YES | Yes | Integrity | YES |
@@ -898,5 +951,3 @@ shows how the lockdown module impacts `ebpf.plugin` based on the selected option
If you or your distribution compiled the kernel with the last combination, your system cannot load shared libraries
required to run `ebpf.plugin`.
-
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fcollectors%2Febpf.plugin%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
diff --git a/collectors/ebpf.plugin/ebpf.c b/collectors/ebpf.plugin/ebpf.c
index d51d378bd..b93c2dfd7 100644
--- a/collectors/ebpf.plugin/ebpf.c
+++ b/collectors/ebpf.plugin/ebpf.c
@@ -51,14 +51,15 @@ ebpf_module_t ebpf_modules[] = {
.pid_map_size = ND_EBPF_DEFAULT_PID_SIZE, .names = NULL, .cfg = &socket_config,
.config_file = NETDATA_NETWORK_CONFIG_FILE,
.kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4,
- .load = EBPF_LOAD_LEGACY, .targets = NULL},
+ .load = EBPF_LOAD_LEGACY, .targets = socket_targets},
{ .thread_name = "cachestat", .config_name = "cachestat", .enabled = 0, .start_routine = ebpf_cachestat_thread,
.update_every = EBPF_DEFAULT_UPDATE_EVERY, .global_charts = 1, .apps_charts = CONFIG_BOOLEAN_NO,
.cgroup_charts = CONFIG_BOOLEAN_NO, .mode = MODE_ENTRY, .optional = 0,
.apps_routine = ebpf_cachestat_create_apps_charts, .maps = NULL,
.pid_map_size = ND_EBPF_DEFAULT_PID_SIZE, .names = NULL, .cfg = &cachestat_config,
.config_file = NETDATA_CACHESTAT_CONFIG_FILE,
- .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_15,
+ .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18|
+ NETDATA_V5_4 | NETDATA_V5_15 | NETDATA_V5_16,
.load = EBPF_LOAD_LEGACY, .targets = NULL},
{ .thread_name = "sync", .config_name = "sync", .enabled = 0, .start_routine = ebpf_sync_thread,
.update_every = EBPF_DEFAULT_UPDATE_EVERY, .global_charts = 1, .apps_charts = CONFIG_BOOLEAN_NO,
@@ -67,7 +68,7 @@ ebpf_module_t ebpf_modules[] = {
.config_file = NETDATA_SYNC_CONFIG_FILE,
// All syscalls have the same kernels
.kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4,
- .load = EBPF_LOAD_LEGACY, .targets = NULL},
+ .load = EBPF_LOAD_LEGACY, .targets = sync_targets},
{ .thread_name = "dc", .config_name = "dc", .enabled = 0, .start_routine = ebpf_dcstat_thread,
.update_every = EBPF_DEFAULT_UPDATE_EVERY, .global_charts = 1, .apps_charts = CONFIG_BOOLEAN_NO,
.cgroup_charts = CONFIG_BOOLEAN_NO, .mode = MODE_ENTRY, .optional = 0,
@@ -112,7 +113,7 @@ ebpf_module_t ebpf_modules[] = {
.pid_map_size = ND_EBPF_DEFAULT_PID_SIZE, .names = NULL, .cfg = &mount_config,
.config_file = NETDATA_MOUNT_CONFIG_FILE,
.kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4,
- .load = EBPF_LOAD_LEGACY, .targets = NULL},
+ .load = EBPF_LOAD_LEGACY, .targets = mount_targets},
{ .thread_name = "fd", .config_name = "fd", .enabled = 0, .start_routine = ebpf_fd_thread,
.update_every = EBPF_DEFAULT_UPDATE_EVERY, .global_charts = 1, .apps_charts = CONFIG_BOOLEAN_NO,
.cgroup_charts = CONFIG_BOOLEAN_NO, .mode = MODE_ENTRY, .optional = 0,
@@ -150,7 +151,7 @@ ebpf_module_t ebpf_modules[] = {
.pid_map_size = ND_EBPF_DEFAULT_PID_SIZE, .names = NULL, .cfg = &shm_config,
.config_file = NETDATA_DIRECTORY_SHM_CONFIG_FILE,
.kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4,
- .load = EBPF_LOAD_LEGACY, .targets = NULL},
+ .load = EBPF_LOAD_LEGACY, .targets = shm_targets},
{ .thread_name = "mdflush", .config_name = "mdflush", .enabled = 0, .start_routine = ebpf_mdflush_thread,
.update_every = EBPF_DEFAULT_UPDATE_EVERY, .global_charts = 1, .apps_charts = CONFIG_BOOLEAN_NO,
.cgroup_charts = CONFIG_BOOLEAN_NO, .mode = MODE_ENTRY, .optional = 0, .apps_routine = NULL, .maps = NULL,
@@ -180,6 +181,11 @@ ebpf_network_viewer_options_t network_viewer_opt;
ebpf_plugin_stats_t plugin_statistics = {.core = 0, .legacy = 0, .running = 0, .threads = 0, .tracepoints = 0,
.probes = 0, .retprobes = 0, .trampolines = 0};
+#ifdef LIBBPF_MAJOR_VERSION
+struct btf *default_btf = NULL;
+#endif
+char *btf_path = NULL;
+
/*****************************************************************
*
* FUNCTIONS USED TO CLEAN MEMORY AND OPERATE SYSTEM FILES
@@ -206,6 +212,7 @@ void clean_loaded_events()
static void ebpf_exit(int sig)
{
close_ebpf_plugin = 1;
+ static int remove_pid = 0;
// When both threads were not finished case I try to go in front this address, the collector will crash
if (!thread_finished) {
@@ -289,6 +296,21 @@ static void ebpf_exit(int sig)
}
*/
+#ifdef LIBBPF_MAJOR_VERSION
+ if (default_btf) {
+ btf__free(default_btf);
+ default_btf = NULL;
+ }
+#endif
+
+ if (!remove_pid) {
+ remove_pid = 1;
+ char filename[FILENAME_MAX + 1];
+ ebpf_pid_file(filename, FILENAME_MAX);
+ if (unlink(filename))
+ error("Cannot remove PID file %s", filename);
+ }
+
exit(sig);
}
@@ -957,6 +979,7 @@ static void read_local_ports(char *filename, uint8_t proto)
return;
size_t lines = procfile_lines(ff), l;
+ netdata_passive_connection_t values = {.counter = 0, .tgid = 0, .pid = 0};
for(l = 0; l < lines ;l++) {
size_t words = procfile_linewords(ff, l);
// This is header or end of file
@@ -970,7 +993,7 @@ static void read_local_ports(char *filename, uint8_t proto)
// Read local port
uint16_t port = (uint16_t)strtol(procfile_lineword(ff, l, 2), NULL, 16);
- update_listen_table(htons(port), proto);
+ update_listen_table(htons(port), proto, &values);
}
procfile_close(ff);
@@ -1115,6 +1138,56 @@ static void ebpf_update_table_size()
}
}
+/**
+ * Set Load mode
+ *
+ * @param load default load mode.
+ */
+static inline void ebpf_set_load_mode(netdata_ebpf_load_mode_t load)
+{
+#ifdef LIBBPF_MAJOR_VERSION
+ if (load == EBPF_LOAD_CORE || load == EBPF_LOAD_PLAY_DICE) {
+ load = (!default_btf) ? EBPF_LOAD_LEGACY : EBPF_LOAD_CORE;
+ }
+#else
+ load = EBPF_LOAD_LEGACY;
+#endif
+
+ int i;
+ for (i = 0; ebpf_modules[i].thread_name; i++) {
+ // TO DO: Use `load` variable after we change all threads.
+ ebpf_modules[i].load = EBPF_LOAD_LEGACY; // load ;
+ }
+}
+
+/**
+ * Update mode
+ *
+ * @param str value read from configuration file.
+ */
+static inline void epbf_update_load_mode(char *str)
+{
+ netdata_ebpf_load_mode_t load = epbf_convert_string_to_load_mode(str);
+
+ ebpf_set_load_mode(load);
+}
+
+#ifdef LIBBPF_MAJOR_VERSION
+/**
+ * Set default btf file
+ *
+ * Load the default BTF file on environment.
+ */
+static void ebpf_set_default_btf_file()
+{
+ char path[PATH_MAX + 1];
+ snprintfz(path, PATH_MAX, "%s/vmlinux", btf_path);
+ default_btf = ebpf_parse_btf_file(path);
+ if (!default_btf)
+ info("Your environment does not have BTF file %s/vmlinux. The plugin will work with 'legacy' code.",
+ btf_path);
+}
+#endif
/**
* Read collector values
@@ -1136,6 +1209,17 @@ static void read_collector_values(int *disable_apps, int *disable_cgroups, int u
how_to_load(value);
+ btf_path = appconfig_get(&collector_config, EBPF_GLOBAL_SECTION, EBPF_CFG_PROGRAM_PATH,
+ EBPF_DEFAULT_BTF_FILE);
+
+#ifdef LIBBPF_MAJOR_VERSION
+ ebpf_set_default_btf_file();
+#endif
+
+ value = appconfig_get(&collector_config, EBPF_GLOBAL_SECTION, EBPF_CFG_TYPE_FORMAT, EBPF_CFG_DEFAULT_PROGRAM);
+
+ epbf_update_load_mode(value);
+
ebpf_update_interval(update_every);
ebpf_update_table_size();
@@ -1372,19 +1456,6 @@ static inline void ebpf_load_thread_config()
}
/**
- * Set Load mode
- *
- * @param load default load mode.
- */
-static inline void ebpf_set_load_mode(netdata_ebpf_load_mode_t load)
-{
- int i;
- for (i = 0; ebpf_modules[i].thread_name; i++) {
- ebpf_modules[i].load = load;
- }
-}
-
-/**
* Parse arguments given from user.
*
* @param argc the number of arguments
@@ -1772,6 +1843,19 @@ static void ebpf_kill_previous_process(char *filename, pid_t pid)
}
/**
+ * PID file
+ *
+ * Write the filename for PID inside the given vector.
+ *
+ * @param filename vector where we will store the name.
+ * @param length number of bytes available in filename vector
+ */
+void ebpf_pid_file(char *filename, size_t length)
+{
+ snprintfz(filename, length, "%s%s/ebpf.d/ebpf.pid", netdata_configured_host_prefix, ebpf_plugin_dir);
+}
+
+/**
* Manage PID
*
* This function kills another instance of eBPF whether it is necessary and update the file content.
@@ -1781,7 +1865,7 @@ static void ebpf_kill_previous_process(char *filename, pid_t pid)
static void ebpf_manage_pid(pid_t pid)
{
char filename[FILENAME_MAX + 1];
- snprintfz(filename, FILENAME_MAX, "%s%s/ebpf.d/ebpf.pid", netdata_configured_host_prefix, ebpf_plugin_dir);
+ ebpf_pid_file(filename, FILENAME_MAX);
ebpf_kill_previous_process(filename, pid);
ebpf_update_pid_file(filename, pid);
@@ -1841,6 +1925,10 @@ int main(int argc, char **argv)
ebpf_allocate_common_vectors();
+#ifdef LIBBPF_MAJOR_VERSION
+ libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
+#endif
+
read_local_addresses();
read_local_ports("/proc/net/tcp", IPPROTO_TCP);
read_local_ports("/proc/net/tcp6", IPPROTO_TCP);
diff --git a/collectors/ebpf.plugin/ebpf.d/mount.conf b/collectors/ebpf.plugin/ebpf.d/mount.conf
index 9d3174755..fdd82f220 100644
--- a/collectors/ebpf.plugin/ebpf.d/mount.conf
+++ b/collectors/ebpf.plugin/ebpf.d/mount.conf
@@ -3,6 +3,17 @@
# `return : In the `return` mode, the eBPF collector monitors the same kernel functions as `entry`, but also creates
# new charts for the return of these functions, such as errors.
#
-#[global]
+# The `ebpf type format` option accepts the following values :
+# `auto` : The eBPF collector will investigate hardware and select between the two next options.
+# `legacy`: The eBPF collector will load the legacy code. Note: This has a bigger overload.
+# `co-re` : The eBPF collector will use latest tracing method. Note: This is not available on all platforms.
+#
+# The `ebpf co-re tracing` option accepts the following values:
+# `trampoline`: This is the default mode used by the eBPF collector, due the small overhead added to host.
+# `tracepoint`: When available, the eBPF collector will use kernel tracepoint to monitor syscall.
+# `probe` : This is the same as legacy code.
+[global]
# ebpf load mode = entry
# update every = 1
+ ebpf type format = auto
+ ebpf co-re tracing = trampoline
diff --git a/collectors/ebpf.plugin/ebpf.d/network.conf b/collectors/ebpf.plugin/ebpf.d/network.conf
index e692622a9..d939d8e1f 100644
--- a/collectors/ebpf.plugin/ebpf.d/network.conf
+++ b/collectors/ebpf.plugin/ebpf.d/network.conf
@@ -14,6 +14,16 @@
# `ipv6 connection table size`: Maximum number of IPV6 connections monitored
# `udp connection table size`: Maximum number of UDP connections monitored
#
+# The `ebpf type format` option accepts the following values :
+# `auto` : The eBPF collector will investigate hardware and select between the two next options.
+# `legacy`: The eBPF collector will load the legacy code. Note: This has a bigger overload.
+# `co-re` : The eBPF collector will use latest tracing method. Note: This is not available on all platforms.
+#
+# The `ebpf co-re tracing` option accepts the following values:
+# `trampoline`: This is the default mode used by the eBPF collector, due the small overhead added to host.
+# `tracepoint`: When available, the eBPF collector will use kernel tracepoint to monitor syscall.
+# `probe` : This is the same as legacy code.
+#
[global]
# ebpf load mode = entry
# apps = yes
@@ -23,6 +33,8 @@
ipv4 connection table size = 16384
ipv6 connection table size = 16384
udp connection table size = 4096
+ ebpf type format = auto
+ ebpf co-re tracing = trampoline
#
# Network Connection
diff --git a/collectors/ebpf.plugin/ebpf.d/shm.conf b/collectors/ebpf.plugin/ebpf.d/shm.conf
index c0a10c98e..23ab96da4 100644
--- a/collectors/ebpf.plugin/ebpf.d/shm.conf
+++ b/collectors/ebpf.plugin/ebpf.d/shm.conf
@@ -8,13 +8,25 @@
# If you want to disable the integration with `apps.plugin` or `cgroups.plugin` along with the above charts, change
# the setting `apps` and `cgroups` to 'no'.
#
+# The `ebpf type format` option accepts the following values :
+# `auto` : The eBPF collector will investigate hardware and select between the two next options.
+# `legacy`: The eBPF collector will load the legacy code. Note: This has a bigger overload.
+# `co-re` : The eBPF collector will use latest tracing method. Note: This is not available on all platforms.
+#
+# The `ebpf co-re tracing` option accepts the following values:
+# `trampoline`: This is the default mode used by the eBPF collector, due the small overhead added to host.
+# `tracepoint`: When available, the eBPF collector will use kernel tracepoint to monitor syscall.
+# `probe` : This is the same as legacy code.
+#
# Uncomment lines to define specific options for thread.
-#[global]
+[global]
# ebpf load mode = entry
# apps = yes
# cgroups = no
# update every = 10
# pid table size = 32768
+ ebpf type format = auto
+ ebpf co-re tracing = trampoline
# List of monitored syscalls
[syscalls]
diff --git a/collectors/ebpf.plugin/ebpf.d/sync.conf b/collectors/ebpf.plugin/ebpf.d/sync.conf
index 03c469f68..ebec5d38e 100644
--- a/collectors/ebpf.plugin/ebpf.d/sync.conf
+++ b/collectors/ebpf.plugin/ebpf.d/sync.conf
@@ -8,12 +8,23 @@
# If you want to disable the integration with `apps.plugin` or `cgroups.plugin` along with the above charts, change
# the setting `apps` and `cgroups` to 'no'.
#
+# The `ebpf type format` option accepts the following values :
+# `auto` : The eBPF collector will investigate hardware and select between the two next options.
+# `legacy`: The eBPF collector will load the legacy code. Note: This has a bigger overload.
+# `co-re` : The eBPF collector will use latest tracing method. Note: This is not available on all platforms.
+#
+# The `ebpf co-re tracing` option accepts the following values:
+# `trampoline`: This is the default mode used by the eBPF collector, due the small overhead added to host.
+# `tracepoint`: When available, the eBPF collector will use kernel tracepoint to monitor syscall.
+# `probe` : This is the same as legacy code.
#
-#[global]
+[global]
# ebpf load mode = entry
# apps = yes
# cgroups = no
# update every = 10
+ ebpf type format = auto
+ ebpf co-re tracing = trampoline
# List of monitored syscalls
[syscalls]
diff --git a/collectors/ebpf.plugin/ebpf.h b/collectors/ebpf.plugin/ebpf.h
index 165a6bf36..337e4f471 100644
--- a/collectors/ebpf.plugin/ebpf.h
+++ b/collectors/ebpf.plugin/ebpf.h
@@ -238,10 +238,13 @@ extern int ebpf_enable_tracepoint(ebpf_tracepoint_t *tp);
extern int ebpf_disable_tracepoint(ebpf_tracepoint_t *tp);
extern uint32_t ebpf_enable_tracepoints(ebpf_tracepoint_t *tps);
+extern void ebpf_pid_file(char *filename, size_t length);
+
#define EBPF_PROGRAMS_SECTION "ebpf programs"
#define EBPF_COMMON_DIMENSION_PERCENTAGE "%"
#define EBPF_COMMON_DIMENSION_CALL "calls/s"
+#define EBPF_COMMON_DIMENSION_CONNECTIONS "connections/s"
#define EBPF_COMMON_DIMENSION_BITS "kilobits/s"
#define EBPF_COMMON_DIMENSION_BYTES "bytes/s"
#define EBPF_COMMON_DIMENSION_DIFFERENCE "difference"
@@ -264,6 +267,7 @@ extern pthread_mutex_t mutex_cgroup_shm;
extern size_t all_pids_count;
extern uint32_t finalized_threads;
extern ebpf_plugin_stats_t plugin_statistics;
+extern struct btf *default_btf;
// Socket functions and variables
// Common functions
diff --git a/collectors/ebpf.plugin/ebpf_apps.c b/collectors/ebpf.plugin/ebpf_apps.c
index 015d1bf21..abc112642 100644
--- a/collectors/ebpf.plugin/ebpf_apps.c
+++ b/collectors/ebpf.plugin/ebpf_apps.c
@@ -275,7 +275,7 @@ int ebpf_read_apps_groups_conf(struct target **agdt, struct target **agrt, const
// ----------------------------------------
- procfile *ff = procfile_open(filename, " :\t", PROCFILE_FLAG_DEFAULT);
+ procfile *ff = procfile_open_no_log(filename, " :\t", PROCFILE_FLAG_DEFAULT);
if (!ff)
return -1;
diff --git a/collectors/ebpf.plugin/ebpf_apps.h b/collectors/ebpf.plugin/ebpf_apps.h
index 0c72b8782..259e642ad 100644
--- a/collectors/ebpf.plugin/ebpf_apps.h
+++ b/collectors/ebpf.plugin/ebpf_apps.h
@@ -379,6 +379,10 @@ typedef struct ebpf_bandwidth {
uint64_t retransmit; // Number of times tcp_retransmit was called
uint64_t call_udp_sent; // Number of times udp_sendmsg was called
uint64_t call_udp_received; // Number of times udp_recvmsg was called
+ uint64_t close; // Number of times tcp_close was called
+ uint64_t drop; // THIS IS NOT USED FOR WHILE, we are in groom section
+ uint32_t tcp_v4_connection; // Number of times tcp_v4_connection was called.
+ uint32_t tcp_v6_connection; // Number of times tcp_v6_connection was called.
} ebpf_bandwidth_t;
/**
diff --git a/collectors/ebpf.plugin/ebpf_cachestat.c b/collectors/ebpf.plugin/ebpf_cachestat.c
index 0cc16234b..ed4c14288 100644
--- a/collectors/ebpf.plugin/ebpf_cachestat.c
+++ b/collectors/ebpf.plugin/ebpf_cachestat.c
@@ -327,7 +327,7 @@ void ebpf_cachestat_create_apps_charts(struct ebpf_module *em, void *ptr)
{
struct target *root = ptr;
ebpf_create_charts_on_apps(NETDATA_CACHESTAT_HIT_RATIO_CHART,
- "The ratio is calculated dividing the Hit pages per total cache accesses without counting dirties.",
+ "Hit ratio",
EBPF_COMMON_DIMENSION_PERCENTAGE,
NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -336,7 +336,7 @@ void ebpf_cachestat_create_apps_charts(struct ebpf_module *em, void *ptr)
root, em->update_every, NETDATA_EBPF_MODULE_NAME_CACHESTAT);
ebpf_create_charts_on_apps(NETDATA_CACHESTAT_DIRTY_CHART,
- "Number of pages marked as dirty. When a page is called dirty, this means that the data stored inside the page needs to be written to devices.",
+ "Number of dirty pages",
EBPF_CACHESTAT_DIMENSION_PAGE,
NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_STACKED,
@@ -345,7 +345,7 @@ void ebpf_cachestat_create_apps_charts(struct ebpf_module *em, void *ptr)
root, em->update_every, NETDATA_EBPF_MODULE_NAME_CACHESTAT);
ebpf_create_charts_on_apps(NETDATA_CACHESTAT_HIT_CHART,
- "Number of cache access without counting dirty pages and page additions.",
+ "Number of accessed files",
EBPF_CACHESTAT_DIMENSION_HITS,
NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_STACKED,
@@ -354,7 +354,7 @@ void ebpf_cachestat_create_apps_charts(struct ebpf_module *em, void *ptr)
root, em->update_every, NETDATA_EBPF_MODULE_NAME_CACHESTAT);
ebpf_create_charts_on_apps(NETDATA_CACHESTAT_MISSES_CHART,
- "Page caches added without counting dirty pages",
+ "Files out of page cache",
EBPF_CACHESTAT_DIMENSION_MISSES,
NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_STACKED,
@@ -599,7 +599,7 @@ void ebpf_cachestat_calc_chart_values()
static void ebpf_create_systemd_cachestat_charts(int update_every)
{
ebpf_create_charts_on_systemd(NETDATA_CACHESTAT_HIT_RATIO_CHART,
- "Hit is calculating using total cache added without dirties per total added because of red misses.",
+ "Hit ratio",
EBPF_COMMON_DIMENSION_PERCENTAGE, NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, 21100,
ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX],
@@ -607,21 +607,21 @@ static void ebpf_create_systemd_cachestat_charts(int update_every)
update_every);
ebpf_create_charts_on_systemd(NETDATA_CACHESTAT_DIRTY_CHART,
- "Number of dirty pages added to the page cache.",
+ "Number of dirty pages",
EBPF_CACHESTAT_DIMENSION_PAGE, NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, 21101,
ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX],
NETDATA_SYSTEMD_CACHESTAT_MODIFIED_CACHE_CONTEXT, NETDATA_EBPF_MODULE_NAME_CACHESTAT,
update_every);
- ebpf_create_charts_on_systemd(NETDATA_CACHESTAT_HIT_CHART, "Hits are function calls that Netdata counts.",
+ ebpf_create_charts_on_systemd(NETDATA_CACHESTAT_HIT_CHART, "Number of accessed files",
EBPF_CACHESTAT_DIMENSION_HITS, NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, 21102,
ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX],
NETDATA_SYSTEMD_CACHESTAT_HIT_FILE_CONTEXT, NETDATA_EBPF_MODULE_NAME_CACHESTAT,
update_every);
- ebpf_create_charts_on_systemd(NETDATA_CACHESTAT_MISSES_CHART, "Misses are function calls that Netdata counts.",
+ ebpf_create_charts_on_systemd(NETDATA_CACHESTAT_MISSES_CHART, "Files out of page cache",
EBPF_CACHESTAT_DIMENSION_MISSES, NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, 21103,
ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX],
@@ -713,7 +713,7 @@ static void ebpf_send_specific_cachestat_data(char *type, netdata_publish_caches
static void ebpf_create_specific_cachestat_charts(char *type, int update_every)
{
ebpf_create_chart(type, NETDATA_CACHESTAT_HIT_RATIO_CHART,
- "Hit is calculating using total cache added without dirties per total added because of red misses.",
+ "Hit ratio",
EBPF_COMMON_DIMENSION_PERCENTAGE, NETDATA_CACHESTAT_CGROUP_SUBMENU,
NETDATA_CGROUP_CACHESTAT_HIT_RATIO_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5200,
@@ -721,7 +721,7 @@ static void ebpf_create_specific_cachestat_charts(char *type, int update_every)
cachestat_counter_publish_aggregated, 1, update_every, NETDATA_EBPF_MODULE_NAME_CACHESTAT);
ebpf_create_chart(type, NETDATA_CACHESTAT_DIRTY_CHART,
- "Number of dirty pages added to the page cache.",
+ "Number of dirty pages",
EBPF_CACHESTAT_DIMENSION_PAGE, NETDATA_CACHESTAT_CGROUP_SUBMENU,
NETDATA_CGROUP_CACHESTAT_MODIFIED_CACHE_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5201,
@@ -730,7 +730,7 @@ static void ebpf_create_specific_cachestat_charts(char *type, int update_every)
update_every, NETDATA_EBPF_MODULE_NAME_CACHESTAT);
ebpf_create_chart(type, NETDATA_CACHESTAT_HIT_CHART,
- "Hits are function calls that Netdata counts.",
+ "Number of accessed files",
EBPF_CACHESTAT_DIMENSION_HITS, NETDATA_CACHESTAT_CGROUP_SUBMENU,
NETDATA_CGROUP_CACHESTAT_HIT_FILES_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5202,
@@ -739,7 +739,7 @@ static void ebpf_create_specific_cachestat_charts(char *type, int update_every)
update_every, NETDATA_EBPF_MODULE_NAME_CACHESTAT);
ebpf_create_chart(type, NETDATA_CACHESTAT_MISSES_CHART,
- "Misses are function calls that Netdata counts.",
+ "Files out of page cache",
EBPF_CACHESTAT_DIMENSION_MISSES, NETDATA_CACHESTAT_CGROUP_SUBMENU,
NETDATA_CGROUP_CACHESTAT_MISS_FILES_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5203,
@@ -759,25 +759,25 @@ static void ebpf_create_specific_cachestat_charts(char *type, int update_every)
static void ebpf_obsolete_specific_cachestat_charts(char *type, int update_every)
{
ebpf_write_chart_obsolete(type, NETDATA_CACHESTAT_HIT_RATIO_CHART,
- "Hit is calculating using total cache added without dirties per total added because of red misses.",
+ "Hit ratio",
EBPF_COMMON_DIMENSION_PERCENTAGE, NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_CACHESTAT_HIT_RATIO_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5200, update_every);
ebpf_write_chart_obsolete(type, NETDATA_CACHESTAT_DIRTY_CHART,
- "Number of dirty pages added to the page cache.",
+ "Number of dirty pages",
EBPF_CACHESTAT_DIMENSION_PAGE, NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_CACHESTAT_MODIFIED_CACHE_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5201, update_every);
ebpf_write_chart_obsolete(type, NETDATA_CACHESTAT_HIT_CHART,
- "Hits are function calls that Netdata counts.",
+ "Number of accessed files",
EBPF_CACHESTAT_DIMENSION_HITS, NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_CACHESTAT_HIT_FILES_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5202, update_every);
ebpf_write_chart_obsolete(type, NETDATA_CACHESTAT_MISSES_CHART,
- "Misses are function calls that Netdata counts.",
+ "Files out of page cache",
EBPF_CACHESTAT_DIMENSION_MISSES, NETDATA_CACHESTAT_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_CACHESTAT_MISS_FILES_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5203, update_every);
@@ -892,7 +892,7 @@ static void cachestat_collector(ebpf_module_t *em)
static void ebpf_create_memory_charts(ebpf_module_t *em)
{
ebpf_create_chart(NETDATA_EBPF_MEMORY_GROUP, NETDATA_CACHESTAT_HIT_RATIO_CHART,
- "Hit is calculating using total cache added without dirties per total added because of red misses.",
+ "Hit ratio",
EBPF_COMMON_DIMENSION_PERCENTAGE, NETDATA_CACHESTAT_SUBMENU,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -901,7 +901,7 @@ static void ebpf_create_memory_charts(ebpf_module_t *em)
cachestat_counter_publish_aggregated, 1, em->update_every, NETDATA_EBPF_MODULE_NAME_CACHESTAT);
ebpf_create_chart(NETDATA_EBPF_MEMORY_GROUP, NETDATA_CACHESTAT_DIRTY_CHART,
- "Number of dirty pages added to the page cache.",
+ "Number of dirty pages",
EBPF_CACHESTAT_DIMENSION_PAGE, NETDATA_CACHESTAT_SUBMENU,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -911,7 +911,7 @@ static void ebpf_create_memory_charts(ebpf_module_t *em)
em->update_every, NETDATA_EBPF_MODULE_NAME_CACHESTAT);
ebpf_create_chart(NETDATA_EBPF_MEMORY_GROUP, NETDATA_CACHESTAT_HIT_CHART,
- "Hits are function calls that Netdata counts.",
+ "Number of accessed files",
EBPF_CACHESTAT_DIMENSION_HITS, NETDATA_CACHESTAT_SUBMENU,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -921,7 +921,7 @@ static void ebpf_create_memory_charts(ebpf_module_t *em)
em->update_every, NETDATA_EBPF_MODULE_NAME_CACHESTAT);
ebpf_create_chart(NETDATA_EBPF_MEMORY_GROUP, NETDATA_CACHESTAT_MISSES_CHART,
- "Misses are function calls that Netdata counts.",
+ "Files out of page cache",
EBPF_CACHESTAT_DIMENSION_MISSES, NETDATA_CACHESTAT_SUBMENU,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
diff --git a/collectors/ebpf.plugin/ebpf_cgroup.c b/collectors/ebpf.plugin/ebpf_cgroup.c
index ecdc46c0b..e6b483baf 100644
--- a/collectors/ebpf.plugin/ebpf_cgroup.c
+++ b/collectors/ebpf.plugin/ebpf_cgroup.c
@@ -242,7 +242,7 @@ static ebpf_cgroup_target_t * ebpf_cgroup_find_or_create(netdata_ebpf_cgroup_shm
*/
static void ebpf_update_pid_link_list(ebpf_cgroup_target_t *ect, char *path)
{
- procfile *ff = procfile_open(path, " \t:", PROCFILE_FLAG_DEFAULT);
+ procfile *ff = procfile_open_no_log(path, " \t:", PROCFILE_FLAG_DEFAULT);
if (!ff)
return;
diff --git a/collectors/ebpf.plugin/ebpf_dcstat.c b/collectors/ebpf.plugin/ebpf_dcstat.c
index 820e24e39..fba87007f 100644
--- a/collectors/ebpf.plugin/ebpf_dcstat.c
+++ b/collectors/ebpf.plugin/ebpf_dcstat.c
@@ -160,7 +160,7 @@ void ebpf_dcstat_create_apps_charts(struct ebpf_module *em, void *ptr)
{
struct target *root = ptr;
ebpf_create_charts_on_apps(NETDATA_DC_HIT_CHART,
- "Percentage of files listed inside directory cache",
+ "Percentage of files inside directory cache",
EBPF_COMMON_DIMENSION_PERCENTAGE,
NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -169,7 +169,7 @@ void ebpf_dcstat_create_apps_charts(struct ebpf_module *em, void *ptr)
root, em->update_every, NETDATA_EBPF_MODULE_NAME_DCSTAT);
ebpf_create_charts_on_apps(NETDATA_DC_REFERENCE_CHART,
- "Count file access.",
+ "Count file access",
EBPF_COMMON_DIMENSION_FILES,
NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_STACKED,
@@ -178,7 +178,7 @@ void ebpf_dcstat_create_apps_charts(struct ebpf_module *em, void *ptr)
root, em->update_every, NETDATA_EBPF_MODULE_NAME_DCSTAT);
ebpf_create_charts_on_apps(NETDATA_DC_REQUEST_NOT_CACHE_CHART,
- "Access to files that were not present inside directory cache.",
+ "Files not present inside directory cache",
EBPF_COMMON_DIMENSION_FILES,
NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_STACKED,
@@ -187,7 +187,7 @@ void ebpf_dcstat_create_apps_charts(struct ebpf_module *em, void *ptr)
root, em->update_every, NETDATA_EBPF_MODULE_NAME_DCSTAT);
ebpf_create_charts_on_apps(NETDATA_DC_REQUEST_NOT_FOUND_CHART,
- "Number of requests for files that were not found on filesystem.",
+ "Files not found",
EBPF_COMMON_DIMENSION_FILES,
NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_STACKED,
@@ -520,14 +520,14 @@ static void dcstat_send_global(netdata_publish_dcstat_t *publish)
*/
static void ebpf_create_specific_dc_charts(char *type, int update_every)
{
- ebpf_create_chart(type, NETDATA_DC_HIT_CHART, "Percentage of files listed inside directory cache.",
+ ebpf_create_chart(type, NETDATA_DC_HIT_CHART, "Percentage of files inside directory cache",
EBPF_COMMON_DIMENSION_PERCENTAGE, NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_CGROUP_DC_HIT_RATIO_CONTEXT, NETDATA_EBPF_CHART_TYPE_LINE,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5700,
ebpf_create_global_dimension,
dcstat_counter_publish_aggregated, 1, update_every, NETDATA_EBPF_MODULE_NAME_DCSTAT);
- ebpf_create_chart(type, NETDATA_DC_REFERENCE_CHART, "Count file access.",
+ ebpf_create_chart(type, NETDATA_DC_REFERENCE_CHART, "Count file access",
EBPF_COMMON_DIMENSION_FILES, NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_CGROUP_DC_REFERENCE_CONTEXT, NETDATA_EBPF_CHART_TYPE_LINE,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5701,
@@ -536,7 +536,7 @@ static void ebpf_create_specific_dc_charts(char *type, int update_every)
update_every, NETDATA_EBPF_MODULE_NAME_DCSTAT);
ebpf_create_chart(type, NETDATA_DC_REQUEST_NOT_CACHE_CHART,
- "Access to files that were not present inside directory cache.",
+ "Files not present inside directory cache",
EBPF_COMMON_DIMENSION_FILES, NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_CGROUP_DC_NOT_CACHE_CONTEXT, NETDATA_EBPF_CHART_TYPE_LINE,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5702,
@@ -545,7 +545,7 @@ static void ebpf_create_specific_dc_charts(char *type, int update_every)
update_every, NETDATA_EBPF_MODULE_NAME_DCSTAT);
ebpf_create_chart(type, NETDATA_DC_REQUEST_NOT_FOUND_CHART,
- "Number of requests for files that were not found on filesystem.",
+ "Files not found",
EBPF_COMMON_DIMENSION_FILES, NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_CGROUP_DC_NOT_FOUND_CONTEXT, NETDATA_EBPF_CHART_TYPE_LINE,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5703,
@@ -565,25 +565,25 @@ static void ebpf_create_specific_dc_charts(char *type, int update_every)
static void ebpf_obsolete_specific_dc_charts(char *type, int update_every)
{
ebpf_write_chart_obsolete(type, NETDATA_DC_HIT_CHART,
- "Percentage of files listed inside directory cache.",
+ "Percentage of files inside directory cache",
EBPF_COMMON_DIMENSION_PERCENTAGE, NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_DC_HIT_RATIO_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5700, update_every);
ebpf_write_chart_obsolete(type, NETDATA_DC_REFERENCE_CHART,
- "Count file access.",
+ "Count file access",
EBPF_COMMON_DIMENSION_FILES, NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_DC_REFERENCE_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5701, update_every);
ebpf_write_chart_obsolete(type, NETDATA_DC_REQUEST_NOT_CACHE_CHART,
- "Access to files that were not present inside directory cache.",
+ "Files not present inside directory cache",
EBPF_COMMON_DIMENSION_FILES, NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_DC_NOT_CACHE_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5702, update_every);
ebpf_write_chart_obsolete(type, NETDATA_DC_REQUEST_NOT_FOUND_CHART,
- "Number of requests for files that were not found on filesystem.",
+ "Files not found",
EBPF_COMMON_DIMENSION_FILES, NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_DC_NOT_FOUND_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5703, update_every);
@@ -647,7 +647,7 @@ void ebpf_dc_calc_chart_values()
static void ebpf_create_systemd_dc_charts(int update_every)
{
ebpf_create_charts_on_systemd(NETDATA_DC_HIT_CHART,
- "Percentage of files listed inside directory cache.",
+ "Percentage of files inside directory cache",
EBPF_COMMON_DIMENSION_PERCENTAGE,
NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -657,7 +657,7 @@ static void ebpf_create_systemd_dc_charts(int update_every)
update_every);
ebpf_create_charts_on_systemd(NETDATA_DC_REFERENCE_CHART,
- "Count file access.",
+ "Count file access",
EBPF_COMMON_DIMENSION_FILES,
NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -667,7 +667,7 @@ static void ebpf_create_systemd_dc_charts(int update_every)
update_every);
ebpf_create_charts_on_systemd(NETDATA_DC_REQUEST_NOT_CACHE_CHART,
- "Access to files that were not present inside directory cache.",
+ "Files not present inside directory cache",
EBPF_COMMON_DIMENSION_FILES,
NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -677,7 +677,7 @@ static void ebpf_create_systemd_dc_charts(int update_every)
update_every);
ebpf_create_charts_on_systemd(NETDATA_DC_REQUEST_NOT_FOUND_CHART,
- "Number of requests for files that were not found on filesystem.",
+ "Files not found",
EBPF_COMMON_DIMENSION_FILES,
NETDATA_DIRECTORY_CACHE_SUBMENU,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -890,7 +890,7 @@ static void dcstat_collector(ebpf_module_t *em)
static void ebpf_create_filesystem_charts(int update_every)
{
ebpf_create_chart(NETDATA_FILESYSTEM_FAMILY, NETDATA_DC_HIT_CHART,
- "Percentage of files listed inside directory cache",
+ "Percentage of files inside directory cache",
EBPF_COMMON_DIMENSION_PERCENTAGE, NETDATA_DIRECTORY_CACHE_SUBMENU,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
diff --git a/collectors/ebpf.plugin/ebpf_mount.c b/collectors/ebpf.plugin/ebpf_mount.c
index 666936d86..1ba1e135c 100644
--- a/collectors/ebpf.plugin/ebpf_mount.c
+++ b/collectors/ebpf.plugin/ebpf_mount.c
@@ -30,6 +30,196 @@ struct netdata_static_thread mount_thread = {"MOUNT KERNEL",
NULL, NULL, 1, NULL,
NULL, NULL};
+netdata_ebpf_targets_t mount_targets[] = { {.name = "mount", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "umount", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}};
+
+#ifdef LIBBPF_MAJOR_VERSION
+#include "includes/mount.skel.h" // BTF code
+
+static struct mount_bpf *bpf_obj = NULL;
+
+/*****************************************************************
+ *
+ * BTF FUNCTIONS
+ *
+ *****************************************************************/
+
+/*
+ * Disable probe
+ *
+ * Disable all probes to use exclusively another method.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static inline void ebpf_mount_disable_probe(struct mount_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_mount_probe, false);
+ bpf_program__set_autoload(obj->progs.netdata_umount_probe, false);
+
+ bpf_program__set_autoload(obj->progs.netdata_mount_retprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_umount_retprobe, false);
+}
+
+/*
+ * Disable tracepoint
+ *
+ * Disable all tracepoints to use exclusively another method.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static inline void ebpf_mount_disable_tracepoint(struct mount_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_mount_exit, false);
+ bpf_program__set_autoload(obj->progs.netdata_umount_exit, false);
+}
+
+/*
+ * Disable trampoline
+ *
+ * Disable all trampoline to use exclusively another method.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static inline void ebpf_mount_disable_trampoline(struct mount_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_mount_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_umount_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_mount_fexit, false);
+ bpf_program__set_autoload(obj->progs.netdata_umount_fexit, false);
+}
+
+/**
+ * Set trampoline target
+ *
+ * Set the targets we will monitor.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static inline void netdata_set_trampoline_target(struct mount_bpf *obj)
+{
+ char syscall[NETDATA_EBPF_MAX_SYSCALL_LENGTH + 1];
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ mount_targets[NETDATA_MOUNT_SYSCALL].name, running_on_kernel);
+
+ bpf_program__set_attach_target(obj->progs.netdata_mount_fentry, 0,
+ syscall);
+
+ bpf_program__set_attach_target(obj->progs.netdata_mount_fexit, 0,
+ syscall);
+
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ mount_targets[NETDATA_UMOUNT_SYSCALL].name, running_on_kernel);
+
+ bpf_program__set_attach_target(obj->progs.netdata_umount_fentry, 0,
+ syscall);
+
+ bpf_program__set_attach_target(obj->progs.netdata_umount_fexit, 0,
+ syscall);
+}
+
+/**
+ * Mount Attach Probe
+ *
+ * Attach probes to target
+ *
+ * @param obj is the main structure for bpf objects.
+ *
+ * @return It returns 0 on success and -1 otherwise.
+ */
+static int ebpf_mount_attach_probe(struct mount_bpf *obj)
+{
+ char syscall[NETDATA_EBPF_MAX_SYSCALL_LENGTH + 1];
+
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ mount_targets[NETDATA_MOUNT_SYSCALL].name, running_on_kernel);
+
+ obj->links.netdata_mount_probe = bpf_program__attach_kprobe(obj->progs.netdata_mount_probe,
+ false, syscall);
+ int ret = (int)libbpf_get_error(obj->links.netdata_mount_probe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_mount_retprobe = bpf_program__attach_kprobe(obj->progs.netdata_mount_retprobe,
+ true, syscall);
+ ret = (int)libbpf_get_error(obj->links.netdata_mount_retprobe);
+ if (ret)
+ return -1;
+
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ mount_targets[NETDATA_UMOUNT_SYSCALL].name, running_on_kernel);
+
+ obj->links.netdata_umount_probe = bpf_program__attach_kprobe(obj->progs.netdata_umount_probe,
+ false, syscall);
+ ret = (int)libbpf_get_error(obj->links.netdata_umount_probe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_umount_retprobe = bpf_program__attach_kprobe(obj->progs.netdata_umount_retprobe,
+ true, syscall);
+ ret = (int)libbpf_get_error(obj->links.netdata_umount_retprobe);
+ if (ret)
+ return -1;
+
+ return 0;
+}
+
+/**
+ * Set hash tables
+ *
+ * Set the values for maps according the value given by kernel.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static void ebpf_mount_set_hash_tables(struct mount_bpf *obj)
+{
+ mount_maps[NETDATA_KEY_MOUNT_TABLE].map_fd = bpf_map__fd(obj->maps.tbl_mount);
+}
+
+/**
+ * Load and attach
+ *
+ * Load and attach the eBPF code in kernel.
+ *
+ * @param obj is the main structure for bpf objects.
+ * @param em structure with configuration
+ *
+ * @return it returns 0 on succes and -1 otherwise
+ */
+static inline int ebpf_mount_load_and_attach(struct mount_bpf *obj, ebpf_module_t *em)
+{
+ netdata_ebpf_targets_t *mt = em->targets;
+ netdata_ebpf_program_loaded_t test = mt[NETDATA_MOUNT_SYSCALL].mode;
+
+ // We are testing only one, because all will have the same behavior
+ if (test == EBPF_LOAD_TRAMPOLINE ) {
+ ebpf_mount_disable_probe(obj);
+ ebpf_mount_disable_tracepoint(obj);
+
+ netdata_set_trampoline_target(obj);
+ } else if (test == EBPF_LOAD_PROBE ||
+ test == EBPF_LOAD_RETPROBE ) {
+ ebpf_mount_disable_tracepoint(obj);
+ ebpf_mount_disable_trampoline(obj);
+ } else {
+ ebpf_mount_disable_probe(obj);
+ ebpf_mount_disable_trampoline(obj);
+ }
+
+ int ret = mount_bpf__load(obj);
+ if (!ret) {
+ if (test != EBPF_LOAD_PROBE && test != EBPF_LOAD_RETPROBE )
+ ret = mount_bpf__attach(obj);
+ else
+ ret = ebpf_mount_attach_probe(obj);
+
+ if (!ret)
+ ebpf_mount_set_hash_tables(obj);
+ }
+
+ return ret;
+}
+#endif
/*****************************************************************
*
* FUNCTIONS TO CLOSE THE THREAD
@@ -59,6 +249,11 @@ static void ebpf_mount_cleanup(void *ptr)
}
bpf_object__close(objects);
}
+#ifdef LIBBPF_MAJOR_VERSION
+ else if (bpf_obj)
+ mount_bpf__destroy(bpf_obj);
+#endif
+
}
/*****************************************************************
@@ -191,7 +386,7 @@ static void mount_collector(ebpf_module_t *em)
static void ebpf_create_mount_charts(int update_every)
{
ebpf_create_chart(NETDATA_EBPF_MOUNT_GLOBAL_FAMILY, NETDATA_EBPF_MOUNT_CALLS,
- "Calls to mount and umount syscalls.",
+ "Calls to mount and umount syscalls",
EBPF_COMMON_DIMENSION_CALL, NETDATA_EBPF_MOUNT_FAMILY,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -201,7 +396,7 @@ static void ebpf_create_mount_charts(int update_every)
update_every, NETDATA_EBPF_MODULE_NAME_MOUNT);
ebpf_create_chart(NETDATA_EBPF_MOUNT_GLOBAL_FAMILY, NETDATA_EBPF_MOUNT_ERRORS,
- "Errors to mount and umount syscalls.",
+ "Errors to mount and umount file systems",
EBPF_COMMON_DIMENSION_CALL, NETDATA_EBPF_MOUNT_FAMILY,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
@@ -219,6 +414,39 @@ static void ebpf_create_mount_charts(int update_every)
*
*****************************************************************/
+/*
+ * Load BPF
+ *
+ * Load BPF files.
+ *
+ * @param em the structure with configuration
+ */
+static int ebpf_mount_load_bpf(ebpf_module_t *em)
+{
+ int ret = 0;
+ if (em->load == EBPF_LOAD_LEGACY) {
+ probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &objects);
+ if (!probe_links) {
+ em->enabled = CONFIG_BOOLEAN_NO;
+ ret = -1;
+ }
+ }
+#ifdef LIBBPF_MAJOR_VERSION
+ else {
+ bpf_obj = mount_bpf__open();
+ if (!bpf_obj)
+ ret = -1;
+ else
+ ret = ebpf_mount_load_and_attach(bpf_obj, em);
+ }
+#endif
+
+ if (ret)
+ error("%s %s", EBPF_DEFAULT_ERROR_MSG, em->thread_name);
+
+ return ret;
+}
+
/**
* Mount thread
*
@@ -238,8 +466,10 @@ void *ebpf_mount_thread(void *ptr)
if (!em->enabled)
goto endmount;
- probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &objects);
- if (!probe_links) {
+#ifdef LIBBPF_MAJOR_VERSION
+ ebpf_adjust_thread_load(em, default_btf);
+#endif
+ if (ebpf_mount_load_bpf(em)) {
em->enabled = CONFIG_BOOLEAN_NO;
goto endmount;
}
diff --git a/collectors/ebpf.plugin/ebpf_mount.h b/collectors/ebpf.plugin/ebpf_mount.h
index 700bea13b..d4f48efd1 100644
--- a/collectors/ebpf.plugin/ebpf_mount.h
+++ b/collectors/ebpf.plugin/ebpf_mount.h
@@ -30,7 +30,15 @@ enum mount_tables {
NETDATA_KEY_MOUNT_TABLE
};
+enum netdata_mount_syscalls {
+ NETDATA_MOUNT_SYSCALL,
+ NETDATA_UMOUNT_SYSCALL,
+
+ NETDATA_MOUNT_SYSCALLS_END
+};
+
extern struct config mount_config;
extern void *ebpf_mount_thread(void *ptr);
+extern netdata_ebpf_targets_t mount_targets[];
#endif /* NETDATA_EBPF_MOUNT_H */
diff --git a/collectors/ebpf.plugin/ebpf_oomkill.c b/collectors/ebpf.plugin/ebpf_oomkill.c
index 434fc7fd3..f38801875 100644
--- a/collectors/ebpf.plugin/ebpf_oomkill.c
+++ b/collectors/ebpf.plugin/ebpf_oomkill.c
@@ -120,7 +120,7 @@ static void ebpf_create_specific_oomkill_charts(char *type, int update_every)
{
ebpf_create_chart(type, NETDATA_OOMKILL_CHART, "OOM kills. This chart is provided by eBPF plugin.",
EBPF_COMMON_DIMENSION_KILLS, NETDATA_EBPF_MEMORY_GROUP,
- NULL, NETDATA_EBPF_CHART_TYPE_LINE,
+ NETDATA_CGROUP_OOMKILLS_CONTEXT, NETDATA_EBPF_CHART_TYPE_LINE,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5600,
ebpf_create_global_dimension,
&oomkill_publish_aggregated, 1, update_every, NETDATA_EBPF_MODULE_NAME_OOMKILL);
@@ -194,7 +194,7 @@ static void ebpf_obsolete_specific_oomkill_charts(char *type, int update_every)
{
ebpf_write_chart_obsolete(type, NETDATA_OOMKILL_CHART, "OOM kills. This chart is provided by eBPF plugin.",
EBPF_COMMON_DIMENSION_KILLS, NETDATA_EBPF_MEMORY_GROUP,
- NETDATA_EBPF_CHART_TYPE_LINE, NULL,
+ NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_OOMKILLS_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5600, update_every);
}
diff --git a/collectors/ebpf.plugin/ebpf_oomkill.h b/collectors/ebpf.plugin/ebpf_oomkill.h
index 86f9463dd..b5f04c74c 100644
--- a/collectors/ebpf.plugin/ebpf_oomkill.h
+++ b/collectors/ebpf.plugin/ebpf_oomkill.h
@@ -22,6 +22,9 @@ typedef uint8_t oomkill_ebpf_val_t;
#define NETDATA_OOMKILL_CHART "oomkills"
+// Contexts
+#define NETDATA_CGROUP_OOMKILLS_CONTEXT "cgroup.oomkills"
+
extern struct config oomkill_config;
extern void *ebpf_oomkill_thread(void *ptr);
extern void ebpf_oomkill_create_apps_charts(struct ebpf_module *em, void *ptr);
diff --git a/collectors/ebpf.plugin/ebpf_shm.c b/collectors/ebpf.plugin/ebpf_shm.c
index 0cfb3abdc..939741e75 100644
--- a/collectors/ebpf.plugin/ebpf_shm.c
+++ b/collectors/ebpf.plugin/ebpf_shm.c
@@ -41,6 +41,203 @@ static struct bpf_object *objects = NULL;
struct netdata_static_thread shm_threads = {"SHM KERNEL", NULL, NULL, 1,
NULL, NULL, NULL};
+netdata_ebpf_targets_t shm_targets[] = { {.name = "shmget", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "shmat", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "shmdt", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "shmctl", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}};
+
+#ifdef LIBBPF_MAJOR_VERSION
+#include "includes/shm.skel.h"
+
+static struct shm_bpf *bpf_obj = NULL;
+
+/*****************************************************************
+ *
+ * BTF FUNCTIONS
+ *
+ *****************************************************************/
+
+/*
+ * Disable tracepoint
+ *
+ * Disable all tracepoints to use exclusively another method.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static void ebpf_shm_disable_tracepoint(struct shm_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_syscall_shmget, false);
+ bpf_program__set_autoload(obj->progs.netdata_syscall_shmat, false);
+ bpf_program__set_autoload(obj->progs.netdata_syscall_shmdt, false);
+ bpf_program__set_autoload(obj->progs.netdata_syscall_shmctl, false);
+}
+
+/*
+ * Disable probe
+ *
+ * Disable all probes to use exclusively another method.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static void ebpf_disable_probe(struct shm_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_shmget_probe, false);
+ bpf_program__set_autoload(obj->progs.netdata_shmat_probe, false);
+ bpf_program__set_autoload(obj->progs.netdata_shmdt_probe, false);
+ bpf_program__set_autoload(obj->progs.netdata_shmctl_probe, false);
+}
+
+/*
+ * Disable trampoline
+ *
+ * Disable all trampoline to use exclusively another method.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static void ebpf_disable_trampoline(struct shm_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_shmget_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_shmat_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_shmdt_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_shmctl_fentry, false);
+}
+
+/**
+ * Set trampoline target
+ *
+ * Set the targets we will monitor.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static void ebpf_set_trampoline_target(struct shm_bpf *obj)
+{
+ char syscall[NETDATA_EBPF_MAX_SYSCALL_LENGTH + 1];
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ shm_targets[NETDATA_KEY_SHMGET_CALL].name, running_on_kernel);
+
+ bpf_program__set_attach_target(obj->progs.netdata_shmget_fentry, 0,
+ syscall);
+
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ shm_targets[NETDATA_KEY_SHMAT_CALL].name, running_on_kernel);
+ bpf_program__set_attach_target(obj->progs.netdata_shmat_fentry, 0,
+ syscall);
+
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ shm_targets[NETDATA_KEY_SHMDT_CALL].name, running_on_kernel);
+ bpf_program__set_attach_target(obj->progs.netdata_shmdt_fentry, 0,
+ syscall);
+
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ shm_targets[NETDATA_KEY_SHMCTL_CALL].name, running_on_kernel);
+ bpf_program__set_attach_target(obj->progs.netdata_shmctl_fentry, 0,
+ syscall);
+}
+
+/**
+ * SHM Attach Probe
+ *
+ * Attach probes to target
+ *
+ * @param obj is the main structure for bpf objects.
+ *
+ * @return It returns 0 on success and -1 otherwise.
+ */
+static int ebpf_shm_attach_probe(struct shm_bpf *obj)
+{
+ char syscall[NETDATA_EBPF_MAX_SYSCALL_LENGTH + 1];
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ shm_targets[NETDATA_KEY_SHMGET_CALL].name, running_on_kernel);
+
+ obj->links.netdata_shmget_probe = bpf_program__attach_kprobe(obj->progs.netdata_shmget_probe,
+ false, syscall);
+ int ret = (int)libbpf_get_error(obj->links.netdata_shmget_probe);
+ if (ret)
+ return -1;
+
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ shm_targets[NETDATA_KEY_SHMAT_CALL].name, running_on_kernel);
+ obj->links.netdata_shmat_probe = bpf_program__attach_kprobe(obj->progs.netdata_shmat_probe,
+ false, syscall);
+ ret = (int)libbpf_get_error(obj->links.netdata_shmat_probe);
+ if (ret)
+ return -1;
+
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ shm_targets[NETDATA_KEY_SHMDT_CALL].name, running_on_kernel);
+ obj->links.netdata_shmdt_probe = bpf_program__attach_kprobe(obj->progs.netdata_shmdt_probe,
+ false, syscall);
+ ret = (int)libbpf_get_error(obj->links.netdata_shmdt_probe);
+ if (ret)
+ return -1;
+
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH,
+ shm_targets[NETDATA_KEY_SHMCTL_CALL].name, running_on_kernel);
+ obj->links.netdata_shmctl_probe = bpf_program__attach_kprobe(obj->progs.netdata_shmctl_probe,
+ false, syscall);
+ ret = (int)libbpf_get_error(obj->links.netdata_shmctl_probe);
+ if (ret)
+ return -1;
+
+ return 0;
+}
+
+/**
+ * Set hash tables
+ *
+ * Set the values for maps according the value given by kernel.
+ */
+static void ebpf_shm_set_hash_tables(struct shm_bpf *obj)
+{
+ shm_maps[NETDATA_PID_SHM_TABLE].map_fd = bpf_map__fd(obj->maps.tbl_pid_shm);
+ shm_maps[NETDATA_SHM_CONTROLLER].map_fd = bpf_map__fd(obj->maps.shm_ctrl);
+ shm_maps[NETDATA_SHM_GLOBAL_TABLE].map_fd = bpf_map__fd(obj->maps.tbl_shm);
+}
+
+/**
+ * Load and attach
+ *
+ * Load and attach the eBPF code in kernel.
+ *
+ * @param obj is the main structure for bpf objects.
+ * @param em structure with configuration
+ *
+ * @return it returns 0 on succes and -1 otherwise
+ */
+static inline int ebpf_shm_load_and_attach(struct shm_bpf *obj, ebpf_module_t *em)
+{
+ netdata_ebpf_targets_t *shmt = em->targets;
+ netdata_ebpf_program_loaded_t test = shmt[NETDATA_KEY_SHMGET_CALL].mode;
+
+ // We are testing only one, because all will have the same behavior
+ if (test == EBPF_LOAD_TRAMPOLINE ) {
+ ebpf_shm_disable_tracepoint(obj);
+ ebpf_disable_probe(obj);
+
+ ebpf_set_trampoline_target(obj);
+ } else if (test == EBPF_LOAD_PROBE || test == EBPF_LOAD_RETPROBE ) {
+ ebpf_shm_disable_tracepoint(obj);
+ ebpf_disable_trampoline(obj);
+ } else {
+ ebpf_disable_probe(obj);
+ ebpf_disable_trampoline(obj);
+ }
+
+ int ret = shm_bpf__load(obj);
+ if (!ret) {
+ if (test != EBPF_LOAD_PROBE && test != EBPF_LOAD_RETPROBE)
+ shm_bpf__attach(obj);
+ else
+ ret = ebpf_shm_attach_probe(obj);
+
+ if (!ret)
+ ebpf_shm_set_hash_tables(obj);
+ }
+
+ return ret;
+}
+#endif
/*****************************************************************
* FUNCTIONS TO CLOSE THE THREAD
*****************************************************************/
@@ -91,6 +288,10 @@ static void ebpf_shm_cleanup(void *ptr)
}
bpf_object__close(objects);
}
+#ifdef LIBBPF_MAJOR_VERSION
+ else if (bpf_obj)
+ shm_bpf__destroy(bpf_obj);
+#endif
}
/*****************************************************************
@@ -787,7 +988,7 @@ static void ebpf_create_shm_charts(int update_every)
ebpf_create_chart(
NETDATA_EBPF_SYSTEM_GROUP,
NETDATA_SHM_GLOBAL_CHART,
- "Calls to shared memory system calls.",
+ "Calls to shared memory system calls",
EBPF_COMMON_DIMENSION_CALL,
NETDATA_SYSTEM_IPC_SHM_SUBMENU,
NULL,
@@ -802,6 +1003,40 @@ static void ebpf_create_shm_charts(int update_every)
fflush(stdout);
}
+/*
+ * Load BPF
+ *
+ * Load BPF files.
+ *
+ * @param em the structure with configuration
+ */
+static int ebpf_shm_load_bpf(ebpf_module_t *em)
+{
+ int ret = 0;
+ if (em->load == EBPF_LOAD_LEGACY) {
+ probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &objects);
+ if (!probe_links) {
+ em->enabled = CONFIG_BOOLEAN_NO;
+ ret = -1;
+ }
+ }
+#ifdef LIBBPF_MAJOR_VERSION
+ else {
+ bpf_obj = shm_bpf__open();
+ if (!bpf_obj)
+ ret = -1;
+ else
+ ret = ebpf_shm_load_and_attach(bpf_obj, em);
+ }
+#endif
+
+
+ if (ret)
+ error("%s %s", EBPF_DEFAULT_ERROR_MSG, em->thread_name);
+
+ return ret;
+}
+
/**
* Shared memory thread.
*
@@ -821,8 +1056,10 @@ void *ebpf_shm_thread(void *ptr)
goto endshm;
}
- probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &objects);
- if (!probe_links) {
+#ifdef LIBBPF_MAJOR_VERSION
+ ebpf_adjust_thread_load(em, default_btf);
+#endif
+ if (ebpf_shm_load_bpf(em)) {
em->enabled = CONFIG_BOOLEAN_NO;
goto endshm;
}
diff --git a/collectors/ebpf.plugin/ebpf_shm.h b/collectors/ebpf.plugin/ebpf_shm.h
index 4e7e183a7..f0559e431 100644
--- a/collectors/ebpf.plugin/ebpf_shm.h
+++ b/collectors/ebpf.plugin/ebpf_shm.h
@@ -57,6 +57,7 @@ extern netdata_publish_shm_t **shm_pid;
extern void *ebpf_shm_thread(void *ptr);
extern void ebpf_shm_create_apps_charts(struct ebpf_module *em, void *ptr);
extern void clean_shm_pid_structures();
+extern netdata_ebpf_targets_t shm_targets[];
extern struct config shm_config;
diff --git a/collectors/ebpf.plugin/ebpf_socket.c b/collectors/ebpf.plugin/ebpf_socket.c
index b59367f58..da42f0a49 100644
--- a/collectors/ebpf.plugin/ebpf_socket.c
+++ b/collectors/ebpf.plugin/ebpf_socket.c
@@ -12,9 +12,13 @@
*****************************************************************/
static char *socket_dimension_names[NETDATA_MAX_SOCKET_VECTOR] = { "received", "sent", "close",
- "received", "sent", "retransmitted" };
+ "received", "sent", "retransmitted",
+ "connected_V4", "connected_V6", "connected_tcp",
+ "connected_udp"};
static char *socket_id_names[NETDATA_MAX_SOCKET_VECTOR] = { "tcp_cleanup_rbuf", "tcp_sendmsg", "tcp_close",
- "udp_recvmsg", "udp_sendmsg", "tcp_retransmit_skb" };
+ "udp_recvmsg", "udp_sendmsg", "tcp_retransmit_skb",
+ "tcp_connect_v4", "tcp_connect_v6", "inet_csk_accept_tcp",
+ "inet_csk_accept_udp" };
static ebpf_local_maps_t socket_maps[] = {{.name = "tbl_bandwidth",
.internal_input = NETDATA_COMPILED_CONNECTIONS_ALLOWED,
@@ -77,6 +81,349 @@ struct config socket_config = { .first_section = NULL,
.index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
.rwlock = AVL_LOCK_INITIALIZER } };
+netdata_ebpf_targets_t socket_targets[] = { {.name = "inet_csk_accept", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "tcp_retransmit_skb", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "tcp_cleanup_rbuf", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "tcp_close", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "udp_recvmsg", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "tcp_sendmsg", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "udp_sendmsg", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "tcp_v4_connect", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = "tcp_v6_connect", .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}};
+
+#ifdef LIBBPF_MAJOR_VERSION
+#include "includes/socket.skel.h" // BTF code
+
+static struct socket_bpf *bpf_obj = NULL;
+
+/**
+ * Disable Probe
+ *
+ * Disable probes to use trampoline.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static void ebpf_socket_disable_probes(struct socket_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_inet_csk_accept_kretprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_v4_connect_kretprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_v6_connect_kretprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_retransmit_skb_kprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_cleanup_rbuf_kprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_close_kprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_recvmsg_kprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_recvmsg_kretprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_sendmsg_kretprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_sendmsg_kprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_sendmsg_kretprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_sendmsg_kprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_socket_release_task_kprobe, false);
+}
+
+/**
+ * Disable Trampoline
+ *
+ * Disable trampoline to use probes.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static void ebpf_socket_disable_trampoline(struct socket_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_inet_csk_accept_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_v4_connect_fexit, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_v6_connect_fexit, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_retransmit_skb_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_cleanup_rbuf_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_close_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_recvmsg_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_recvmsg_fexit, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_sendmsg_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_tcp_sendmsg_fexit, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_sendmsg_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_sendmsg_fexit, false);
+ bpf_program__set_autoload(obj->progs.netdata_socket_release_task_fentry, false);
+}
+
+/**
+ * Set trampoline target.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static void ebpf_set_trampoline_target(struct socket_bpf *obj)
+{
+ bpf_program__set_attach_target(obj->progs.netdata_inet_csk_accept_fentry, 0,
+ socket_targets[NETDATA_FCNT_INET_CSK_ACCEPT].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_tcp_v4_connect_fexit, 0,
+ socket_targets[NETDATA_FCNT_TCP_V4_CONNECT].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_tcp_v6_connect_fexit, 0,
+ socket_targets[NETDATA_FCNT_TCP_V6_CONNECT].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_tcp_retransmit_skb_fentry, 0,
+ socket_targets[NETDATA_FCNT_TCP_RETRANSMIT].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_tcp_cleanup_rbuf_fentry, 0,
+ socket_targets[NETDATA_FCNT_CLEANUP_RBUF].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_tcp_close_fentry, 0, socket_targets[NETDATA_FCNT_TCP_CLOSE].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_udp_recvmsg_fentry, 0,
+ socket_targets[NETDATA_FCNT_UDP_RECEVMSG].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_udp_recvmsg_fexit, 0,
+ socket_targets[NETDATA_FCNT_UDP_RECEVMSG].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_tcp_sendmsg_fentry, 0,
+ socket_targets[NETDATA_FCNT_TCP_SENDMSG].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_tcp_sendmsg_fexit, 0,
+ socket_targets[NETDATA_FCNT_TCP_SENDMSG].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_udp_sendmsg_fentry, 0,
+ socket_targets[NETDATA_FCNT_UDP_SENDMSG].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_udp_sendmsg_fexit, 0,
+ socket_targets[NETDATA_FCNT_UDP_SENDMSG].name);
+
+ bpf_program__set_attach_target(obj->progs.netdata_socket_release_task_fentry, 0, EBPF_COMMON_FNCT_CLEAN_UP);
+}
+
+
+/**
+ * Disable specific trampoline
+ *
+ * Disable specific trampoline to match user selection.
+ *
+ * @param obj is the main structure for bpf objects.
+ * @param sel option selected by user.
+ */
+static inline void ebpf_socket_disable_specific_trampoline(struct socket_bpf *obj, netdata_run_mode_t sel)
+{
+ if (sel == MODE_RETURN) {
+ bpf_program__set_autoload(obj->progs.netdata_tcp_sendmsg_fentry, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_sendmsg_fentry, false);
+ } else {
+ bpf_program__set_autoload(obj->progs.netdata_tcp_sendmsg_fexit, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_sendmsg_fexit, false);
+ }
+}
+
+/**
+ * Disable specific probe
+ *
+ * Disable specific probe to match user selection.
+ *
+ * @param obj is the main structure for bpf objects.
+ * @param sel option selected by user.
+ */
+static inline void ebpf_socket_disable_specific_probe(struct socket_bpf *obj, netdata_run_mode_t sel)
+{
+ if (sel == MODE_RETURN) {
+ bpf_program__set_autoload(obj->progs.netdata_tcp_sendmsg_kprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_sendmsg_kprobe, false);
+ } else {
+ bpf_program__set_autoload(obj->progs.netdata_tcp_sendmsg_kretprobe, false);
+ bpf_program__set_autoload(obj->progs.netdata_udp_sendmsg_kretprobe, false);
+ }
+}
+
+/**
+ * Attach probes
+ *
+ * Attach probes to targets.
+ *
+ * @param obj is the main structure for bpf objects.
+ * @param sel option selected by user.
+ */
+static int ebpf_socket_attach_probes(struct socket_bpf *obj, netdata_run_mode_t sel)
+{
+ obj->links.netdata_inet_csk_accept_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_inet_csk_accept_kretprobe,
+ true,
+ socket_targets[NETDATA_FCNT_INET_CSK_ACCEPT].name);
+ int ret = libbpf_get_error(obj->links.netdata_inet_csk_accept_kretprobe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_tcp_v4_connect_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_v4_connect_kretprobe,
+ true,
+ socket_targets[NETDATA_FCNT_TCP_V4_CONNECT].name);
+ ret = libbpf_get_error(obj->links.netdata_tcp_v4_connect_kretprobe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_tcp_v6_connect_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_v6_connect_kretprobe,
+ true,
+ socket_targets[NETDATA_FCNT_TCP_V6_CONNECT].name);
+ ret = libbpf_get_error(obj->links.netdata_tcp_v6_connect_kretprobe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_tcp_retransmit_skb_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_retransmit_skb_kprobe,
+ false,
+ socket_targets[NETDATA_FCNT_TCP_RETRANSMIT].name);
+ ret = libbpf_get_error(obj->links.netdata_tcp_retransmit_skb_kprobe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_tcp_cleanup_rbuf_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_cleanup_rbuf_kprobe,
+ false,
+ socket_targets[NETDATA_FCNT_CLEANUP_RBUF].name);
+ ret = libbpf_get_error(obj->links.netdata_tcp_cleanup_rbuf_kprobe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_tcp_close_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_close_kprobe,
+ false,
+ socket_targets[NETDATA_FCNT_TCP_CLOSE].name);
+ ret = libbpf_get_error(obj->links.netdata_tcp_close_kprobe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_udp_recvmsg_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_udp_recvmsg_kprobe,
+ false,
+ socket_targets[NETDATA_FCNT_UDP_RECEVMSG].name);
+ ret = libbpf_get_error(obj->links.netdata_udp_recvmsg_kprobe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_udp_recvmsg_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_udp_recvmsg_kretprobe,
+ true,
+ socket_targets[NETDATA_FCNT_UDP_RECEVMSG].name);
+ ret = libbpf_get_error(obj->links.netdata_udp_recvmsg_kretprobe);
+ if (ret)
+ return -1;
+
+ if (sel == MODE_RETURN) {
+ obj->links.netdata_tcp_sendmsg_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_sendmsg_kretprobe,
+ true,
+ socket_targets[NETDATA_FCNT_TCP_SENDMSG].name);
+ ret = libbpf_get_error(obj->links.netdata_tcp_sendmsg_kretprobe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_udp_sendmsg_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_udp_sendmsg_kretprobe,
+ true,
+ socket_targets[NETDATA_FCNT_UDP_SENDMSG].name);
+ ret = libbpf_get_error(obj->links.netdata_udp_sendmsg_kretprobe);
+ if (ret)
+ return -1;
+ } else {
+ obj->links.netdata_tcp_sendmsg_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_tcp_sendmsg_kprobe,
+ false,
+ socket_targets[NETDATA_FCNT_TCP_SENDMSG].name);
+ ret = libbpf_get_error(obj->links.netdata_tcp_sendmsg_kprobe);
+ if (ret)
+ return -1;
+
+ obj->links.netdata_udp_sendmsg_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_udp_sendmsg_kprobe,
+ false,
+ socket_targets[NETDATA_FCNT_UDP_SENDMSG].name);
+ ret = libbpf_get_error(obj->links.netdata_udp_sendmsg_kprobe);
+ if (ret)
+ return -1;
+ }
+
+ obj->links.netdata_socket_release_task_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_socket_release_task_kprobe,
+ false, EBPF_COMMON_FNCT_CLEAN_UP);
+ ret = libbpf_get_error(obj->links.netdata_socket_release_task_kprobe);
+ if (ret)
+ return -1;
+
+ return 0;
+}
+
+/**
+ * Set hash tables
+ *
+ * Set the values for maps according the value given by kernel.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static void ebpf_socket_set_hash_tables(struct socket_bpf *obj)
+{
+ socket_maps[NETDATA_SOCKET_TABLE_BANDWIDTH].map_fd = bpf_map__fd(obj->maps.tbl_bandwidth);
+ socket_maps[NETDATA_SOCKET_GLOBAL].map_fd = bpf_map__fd(obj->maps.tbl_global_sock);
+ socket_maps[NETDATA_SOCKET_LPORTS].map_fd = bpf_map__fd(obj->maps.tbl_lports);
+ socket_maps[NETDATA_SOCKET_TABLE_IPV4].map_fd = bpf_map__fd(obj->maps.tbl_conn_ipv4);
+ socket_maps[NETDATA_SOCKET_TABLE_IPV6].map_fd = bpf_map__fd(obj->maps.tbl_conn_ipv6);
+ socket_maps[NETDATA_SOCKET_TABLE_UDP].map_fd = bpf_map__fd(obj->maps.tbl_nv_udp);
+ socket_maps[NETDATA_SOCKET_TABLE_CTRL].map_fd = bpf_map__fd(obj->maps.socket_ctrl);
+}
+
+/**
+ * Adjust Map Size
+ *
+ * Resize maps according input from users.
+ *
+ * @param obj is the main structure for bpf objects.
+ * @param em structure with configuration
+ */
+static void ebpf_socket_adjust_map_size(struct socket_bpf *obj, ebpf_module_t *em)
+{
+ ebpf_update_map_size(obj->maps.tbl_bandwidth, &socket_maps[NETDATA_SOCKET_TABLE_BANDWIDTH],
+ em, bpf_map__name(obj->maps.tbl_bandwidth));
+
+ ebpf_update_map_size(obj->maps.tbl_conn_ipv4, &socket_maps[NETDATA_SOCKET_TABLE_IPV4],
+ em, bpf_map__name(obj->maps.tbl_conn_ipv4));
+
+ ebpf_update_map_size(obj->maps.tbl_conn_ipv6, &socket_maps[NETDATA_SOCKET_TABLE_IPV6],
+ em, bpf_map__name(obj->maps.tbl_conn_ipv6));
+
+ ebpf_update_map_size(obj->maps.tbl_nv_udp, &socket_maps[NETDATA_SOCKET_TABLE_UDP],
+ em, bpf_map__name(obj->maps.tbl_nv_udp));
+}
+
+/**
+ * Load and attach
+ *
+ * Load and attach the eBPF code in kernel.
+ *
+ * @param obj is the main structure for bpf objects.
+ * @param em structure with configuration
+ *
+ * @return it returns 0 on succes and -1 otherwise
+ */
+static inline int ebpf_socket_load_and_attach(struct socket_bpf *obj, ebpf_module_t *em)
+{
+ netdata_ebpf_targets_t *mt = em->targets;
+ netdata_ebpf_program_loaded_t test = mt[NETDATA_FCNT_INET_CSK_ACCEPT].mode;
+
+ if (test == EBPF_LOAD_TRAMPOLINE) {
+ ebpf_socket_disable_probes(obj);
+
+ ebpf_set_trampoline_target(obj);
+ ebpf_socket_disable_specific_trampoline(obj, em->mode);
+ } else { // We are not using tracepoints for this thread.
+ ebpf_socket_disable_trampoline(obj);
+
+ ebpf_socket_disable_specific_probe(obj, em->mode);
+ }
+
+ int ret = socket_bpf__load(obj);
+ if (ret) {
+ fprintf(stderr, "failed to load BPF object: %d\n", ret);
+ return ret;
+ }
+
+ ebpf_socket_adjust_map_size(obj, em);
+
+ if (test == EBPF_LOAD_TRAMPOLINE) {
+ ret = socket_bpf__attach(obj);
+ } else {
+ ret = ebpf_socket_attach_probes(obj, em->mode);
+ }
+
+ if (!ret) {
+ ebpf_socket_set_hash_tables(obj);
+
+ ebpf_update_controller(socket_maps[NETDATA_SOCKET_TABLE_CTRL].map_fd, em);
+ }
+
+ return ret;
+}
+#endif
/*****************************************************************
*
* PROCESS DATA AND SEND TO NETDATA
@@ -294,6 +641,31 @@ static void ebpf_socket_send_nv_data(netdata_vector_plot_t *ptr)
}
/**
+ * Send Global Inbound connection
+ *
+ * Send number of connections read per protocol.
+ */
+static void ebpf_socket_send_global_inbound_conn()
+{
+ uint64_t udp_conn = 0;
+ uint64_t tcp_conn = 0;
+ ebpf_network_viewer_port_list_t *move = listen_ports;
+ while (move) {
+ if (move->protocol == IPPROTO_TCP)
+ tcp_conn += move->connections;
+ else
+ udp_conn += move->connections;
+
+ move = move->next;
+ }
+
+ write_begin_chart(NETDATA_EBPF_IP_FAMILY, NETDATA_INBOUND_CONNECTIONS);
+ write_chart_dimension(socket_publish_aggregated[NETDATA_IDX_INCOMING_CONNECTION_TCP].name, (long long) tcp_conn);
+ write_chart_dimension(socket_publish_aggregated[NETDATA_IDX_INCOMING_CONNECTION_UDP].name, (long long) udp_conn);
+ write_end_chart();
+}
+
+/**
* Send data to Netdata calling auxiliary functions.
*
* @param em the structure with thread information
@@ -304,6 +676,10 @@ static void ebpf_socket_send_data(ebpf_module_t *em)
netdata_publish_vfs_common_t common_udp;
ebpf_update_global_publish(socket_publish_aggregated, &common_tcp, &common_udp, socket_aggregated_data);
+ ebpf_socket_send_global_inbound_conn();
+ write_count_chart(NETDATA_TCP_OUTBOUND_CONNECTIONS, NETDATA_EBPF_IP_FAMILY,
+ &socket_publish_aggregated[NETDATA_IDX_TCP_CONNECTION_V4], 2);
+
// We read bytes from function arguments, but bandwidth is given in bits,
// so we need to multiply by 8 to convert for the final value.
write_count_chart(NETDATA_TCP_FUNCTION_COUNT, NETDATA_EBPF_IP_FAMILY, socket_publish_aggregated, 3);
@@ -367,6 +743,26 @@ void ebpf_socket_send_apps_data(ebpf_module_t *em, struct target *root)
struct target *w;
collected_number value;
+ write_begin_chart(NETDATA_APPS_FAMILY, NETDATA_NET_APPS_CONNECTION_TCP_V4);
+ for (w = root; w; w = w->next) {
+ if (unlikely(w->exposed && w->processes)) {
+ value = ebpf_socket_sum_values_for_pids(w->root_pid, offsetof(ebpf_socket_publish_apps_t,
+ call_tcp_v4_connection));
+ write_chart_dimension(w->name, value);
+ }
+ }
+ write_end_chart();
+
+ write_begin_chart(NETDATA_APPS_FAMILY, NETDATA_NET_APPS_CONNECTION_TCP_V6);
+ for (w = root; w; w = w->next) {
+ if (unlikely(w->exposed && w->processes)) {
+ value = ebpf_socket_sum_values_for_pids(w->root_pid, offsetof(ebpf_socket_publish_apps_t,
+ call_tcp_v6_connection));
+ write_chart_dimension(w->name, value);
+ }
+ }
+ write_end_chart();
+
write_begin_chart(NETDATA_APPS_FAMILY, NETDATA_NET_APPS_BANDWIDTH_SENT);
for (w = root; w; w = w->next) {
if (unlikely(w->exposed && w->processes)) {
@@ -456,6 +852,32 @@ void ebpf_socket_send_apps_data(ebpf_module_t *em, struct target *root)
*/
static void ebpf_create_global_charts(ebpf_module_t *em)
{
+ int order = 21070;
+ ebpf_create_chart(NETDATA_EBPF_IP_FAMILY,
+ NETDATA_INBOUND_CONNECTIONS,
+ "Inbound connections.",
+ EBPF_COMMON_DIMENSION_CONNECTIONS,
+ NETDATA_SOCKET_KERNEL_FUNCTIONS,
+ NULL,
+ NETDATA_EBPF_CHART_TYPE_LINE,
+ order++,
+ ebpf_create_global_dimension,
+ &socket_publish_aggregated[NETDATA_IDX_INCOMING_CONNECTION_TCP],
+ 2, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
+
+ ebpf_create_chart(NETDATA_EBPF_IP_FAMILY,
+ NETDATA_TCP_OUTBOUND_CONNECTIONS,
+ "TCP outbound connections.",
+ EBPF_COMMON_DIMENSION_CONNECTIONS,
+ NETDATA_SOCKET_KERNEL_FUNCTIONS,
+ NULL,
+ NETDATA_EBPF_CHART_TYPE_LINE,
+ order++,
+ ebpf_create_global_dimension,
+ &socket_publish_aggregated[NETDATA_IDX_TCP_CONNECTION_V4],
+ 2, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
+
+
ebpf_create_chart(NETDATA_EBPF_IP_FAMILY,
NETDATA_TCP_FUNCTION_COUNT,
"Calls to internal functions",
@@ -463,7 +885,7 @@ static void ebpf_create_global_charts(ebpf_module_t *em)
NETDATA_SOCKET_KERNEL_FUNCTIONS,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
- 21070,
+ order++,
ebpf_create_global_dimension,
socket_publish_aggregated,
3, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -473,7 +895,7 @@ static void ebpf_create_global_charts(ebpf_module_t *em)
NETDATA_SOCKET_KERNEL_FUNCTIONS,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
- 21071,
+ order++,
ebpf_create_global_dimension,
socket_publish_aggregated,
2, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -486,7 +908,7 @@ static void ebpf_create_global_charts(ebpf_module_t *em)
NETDATA_SOCKET_KERNEL_FUNCTIONS,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
- 21072,
+ order++,
ebpf_create_global_dimension,
socket_publish_aggregated,
2, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -499,7 +921,7 @@ static void ebpf_create_global_charts(ebpf_module_t *em)
NETDATA_SOCKET_KERNEL_FUNCTIONS,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
- 21073,
+ order++,
ebpf_create_global_dimension,
&socket_publish_aggregated[NETDATA_IDX_TCP_RETRANSMIT],
1, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -511,7 +933,7 @@ static void ebpf_create_global_charts(ebpf_module_t *em)
NETDATA_SOCKET_KERNEL_FUNCTIONS,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
- 21074,
+ order++,
ebpf_create_global_dimension,
&socket_publish_aggregated[NETDATA_IDX_UDP_RECVBUF],
2, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -521,7 +943,7 @@ static void ebpf_create_global_charts(ebpf_module_t *em)
NETDATA_SOCKET_KERNEL_FUNCTIONS,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
- 21075,
+ order++,
ebpf_create_global_dimension,
&socket_publish_aggregated[NETDATA_IDX_UDP_RECVBUF],
2, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -534,7 +956,7 @@ static void ebpf_create_global_charts(ebpf_module_t *em)
NETDATA_SOCKET_KERNEL_FUNCTIONS,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
- 21076,
+ order++,
ebpf_create_global_dimension,
&socket_publish_aggregated[NETDATA_IDX_UDP_RECVBUF],
2, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -551,12 +973,29 @@ static void ebpf_create_global_charts(ebpf_module_t *em)
*/
void ebpf_socket_create_apps_charts(struct ebpf_module *em, void *ptr)
{
- struct target *root = ptr;;
+ struct target *root = ptr;
+ int order = 20080;
+ ebpf_create_charts_on_apps(NETDATA_NET_APPS_CONNECTION_TCP_V4,
+ "Calls to tcp_v4_connection", EBPF_COMMON_DIMENSION_CONNECTIONS,
+ NETDATA_APPS_NET_GROUP,
+ NETDATA_EBPF_CHART_TYPE_STACKED,
+ order++,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
+ root, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
+
+ ebpf_create_charts_on_apps(NETDATA_NET_APPS_CONNECTION_TCP_V6,
+ "Calls to tcp_v6_connection", EBPF_COMMON_DIMENSION_CONNECTIONS,
+ NETDATA_APPS_NET_GROUP,
+ NETDATA_EBPF_CHART_TYPE_STACKED,
+ order++,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
+ root, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
+
ebpf_create_charts_on_apps(NETDATA_NET_APPS_BANDWIDTH_SENT,
"Bytes sent", EBPF_COMMON_DIMENSION_BITS,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20080,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
root, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -564,7 +1003,7 @@ void ebpf_socket_create_apps_charts(struct ebpf_module *em, void *ptr)
"bytes received", EBPF_COMMON_DIMENSION_BITS,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20081,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
root, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -573,7 +1012,7 @@ void ebpf_socket_create_apps_charts(struct ebpf_module *em, void *ptr)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20082,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
root, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -582,7 +1021,7 @@ void ebpf_socket_create_apps_charts(struct ebpf_module *em, void *ptr)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20083,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
root, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -591,7 +1030,7 @@ void ebpf_socket_create_apps_charts(struct ebpf_module *em, void *ptr)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20084,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
root, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -600,7 +1039,7 @@ void ebpf_socket_create_apps_charts(struct ebpf_module *em, void *ptr)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20085,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
root, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -609,7 +1048,7 @@ void ebpf_socket_create_apps_charts(struct ebpf_module *em, void *ptr)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20086,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
root, em->update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
@@ -1295,11 +1734,10 @@ netdata_vector_plot_t * select_vector_to_store(uint32_t *direction, netdata_sock
*
* @param values the values used to calculate the data.
* @param key the key to store data.
- * @param removesock check if this socket must be removed .
* @param family the connection family
* @param end the values size.
*/
-static void hash_accumulator(netdata_socket_t *values, netdata_socket_idx_t *key, int *removesock, int family, int end)
+static void hash_accumulator(netdata_socket_t *values, netdata_socket_idx_t *key, int family, int end)
{
uint64_t bsent = 0, brecv = 0, psent = 0, precv = 0;
uint16_t retransmit = 0;
@@ -1320,8 +1758,6 @@ static void hash_accumulator(netdata_socket_t *values, netdata_socket_idx_t *key
if (w->ct > ct)
ct = w->ct;
-
- *removesock += (int)w->removeme;
}
values[0].recv_packets += precv;
@@ -1329,7 +1765,6 @@ static void hash_accumulator(netdata_socket_t *values, netdata_socket_idx_t *key
values[0].recv_bytes += brecv;
values[0].sent_bytes += bsent;
values[0].retransmit += retransmit;
- values[0].removeme += (uint8_t)*removesock;
values[0].protocol = (!protocol)?IPPROTO_TCP:protocol;
values[0].ct = ct;
@@ -1357,8 +1792,6 @@ static void read_socket_hash_table(int fd, int family, int network_connection)
netdata_socket_idx_t key = {};
netdata_socket_idx_t next_key = {};
- netdata_socket_idx_t removeme;
- int removesock = 0;
netdata_socket_t *values = socket_values;
size_t length = ebpf_nprocs*sizeof(netdata_socket_t);
@@ -1375,35 +1808,41 @@ static void read_socket_hash_table(int fd, int family, int network_connection)
continue;
}
- if (removesock)
- bpf_map_delete_elem(fd, &removeme);
-
if (network_connection) {
- removesock = 0;
- hash_accumulator(values, &key, &removesock, family, end);
+ hash_accumulator(values, &key, family, end);
}
- if (removesock)
- removeme = key;
-
key = next_key;
}
- if (removesock)
- bpf_map_delete_elem(fd, &removeme);
-
test = bpf_map_lookup_elem(fd, &next_key, values);
if (test < 0) {
return;
}
if (network_connection) {
- removesock = 0;
- hash_accumulator(values, &next_key, &removesock, family, end);
+ hash_accumulator(values, &next_key, family, end);
}
+}
- if (removesock)
- bpf_map_delete_elem(fd, &next_key);
+/**
+ * Fill Network Viewer Port list
+ *
+ * Fill the strcture with values read from /proc or hash table.
+ *
+ * @param out the structure where we will store data.
+ * @param value the ports we are listen to.
+ * @param proto the protocol used for this connection.
+ * @param in the strcuture with values read form different sources.
+ */
+static inline void fill_nv_port_list(ebpf_network_viewer_port_list_t *out, uint16_t value, uint16_t proto,
+ netdata_passive_connection_t *in)
+{
+ out->first = value;
+ out->protocol = proto;
+ out->pid = in->pid;
+ out->tgid = in->tgid;
+ out->connections = in->counter;
}
/**
@@ -1413,31 +1852,33 @@ static void read_socket_hash_table(int fd, int family, int network_connection)
*
* @param value the ports we are listen to.
* @param proto the protocol used with port connection.
+ * @param in the strcuture with values read form different sources.
*/
-void update_listen_table(uint16_t value, uint8_t proto)
+void update_listen_table(uint16_t value, uint16_t proto, netdata_passive_connection_t *in)
{
ebpf_network_viewer_port_list_t *w;
if (likely(listen_ports)) {
ebpf_network_viewer_port_list_t *move = listen_ports, *store = listen_ports;
while (move) {
- if (move->protocol == proto && move->first == value)
+ if (move->protocol == proto && move->first == value) {
+ move->pid = in->pid;
+ move->tgid = in->tgid;
+ move->connections = in->counter;
return;
+ }
store = move;
move = move->next;
}
w = callocz(1, sizeof(ebpf_network_viewer_port_list_t));
- w->first = value;
- w->protocol = proto;
store->next = w;
} else {
w = callocz(1, sizeof(ebpf_network_viewer_port_list_t));
- w->first = value;
- w->protocol = proto;
listen_ports = w;
}
+ fill_nv_port_list(w, value, proto, in);
#ifdef NETDATA_INTERNAL_CHECKS
info("The network viewer is monitoring inbound connections for port %u", ntohs(value));
@@ -1451,11 +1892,11 @@ void update_listen_table(uint16_t value, uint8_t proto)
*/
static void read_listen_table()
{
- uint16_t key = 0;
- uint16_t next_key = 0;
+ netdata_passive_connection_idx_t key = {};
+ netdata_passive_connection_idx_t next_key = {};
int fd = socket_maps[NETDATA_SOCKET_LPORTS].map_fd;
- uint8_t value;
+ netdata_passive_connection_t value = {};
while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
int test = bpf_map_lookup_elem(fd, &key, &value);
if (test < 0) {
@@ -1464,14 +1905,15 @@ static void read_listen_table()
}
// The correct protocol must come from kernel
- update_listen_table(htons(key), (key == 53)?IPPROTO_UDP:IPPROTO_TCP);
+ update_listen_table(key.port, key.protocol, &value);
key = next_key;
+ memset(&value, 0, sizeof(value));
}
- if (next_key) {
+ if (next_key.port && value.pid) {
// The correct protocol must come from kernel
- update_listen_table(htons(next_key), (key == 53)?IPPROTO_UDP:IPPROTO_TCP);
+ update_listen_table(next_key.port, next_key.protocol, &value);
}
}
@@ -1542,11 +1984,15 @@ static void read_hash_global_tables()
socket_aggregated_data[NETDATA_IDX_UDP_RECVBUF].call = res[NETDATA_KEY_CALLS_UDP_RECVMSG];
socket_aggregated_data[NETDATA_IDX_UDP_SENDMSG].call = res[NETDATA_KEY_CALLS_UDP_SENDMSG];
socket_aggregated_data[NETDATA_IDX_TCP_RETRANSMIT].call = res[NETDATA_KEY_TCP_RETRANSMIT];
+ socket_aggregated_data[NETDATA_IDX_TCP_CONNECTION_V4].call = res[NETDATA_KEY_CALLS_TCP_CONNECT_IPV4];
+ socket_aggregated_data[NETDATA_IDX_TCP_CONNECTION_V6].call = res[NETDATA_KEY_CALLS_TCP_CONNECT_IPV6];
socket_aggregated_data[NETDATA_IDX_TCP_SENDMSG].ecall = res[NETDATA_KEY_ERROR_TCP_SENDMSG];
socket_aggregated_data[NETDATA_IDX_TCP_CLEANUP_RBUF].ecall = res[NETDATA_KEY_ERROR_TCP_CLEANUP_RBUF];
socket_aggregated_data[NETDATA_IDX_UDP_RECVBUF].ecall = res[NETDATA_KEY_ERROR_UDP_RECVMSG];
socket_aggregated_data[NETDATA_IDX_UDP_SENDMSG].ecall = res[NETDATA_KEY_ERROR_UDP_SENDMSG];
+ socket_aggregated_data[NETDATA_IDX_TCP_CONNECTION_V4].ecall = res[NETDATA_KEY_ERROR_TCP_CONNECT_IPV4];
+ socket_aggregated_data[NETDATA_IDX_TCP_CONNECTION_V6].ecall = res[NETDATA_KEY_ERROR_TCP_CONNECT_IPV6];
socket_aggregated_data[NETDATA_IDX_TCP_SENDMSG].bytes = res[NETDATA_KEY_BYTES_TCP_SENDMSG];
socket_aggregated_data[NETDATA_IDX_TCP_CLEANUP_RBUF].bytes = res[NETDATA_KEY_BYTES_TCP_CLEANUP_RBUF];
@@ -1575,6 +2021,9 @@ void ebpf_socket_fill_publish_apps(uint32_t current_pid, ebpf_bandwidth_t *eb)
curr->retransmit = eb->retransmit;
curr->call_udp_sent = eb->call_udp_sent;
curr->call_udp_received = eb->call_udp_received;
+ curr->call_close = eb->close;
+ curr->call_tcp_v4_connection = eb->tcp_v4_connection;
+ curr->call_tcp_v6_connection = eb->tcp_v6_connection;
}
/**
@@ -1595,6 +2044,9 @@ void ebpf_socket_bandwidth_accumulator(ebpf_bandwidth_t *out)
total->retransmit += move->retransmit;
total->call_udp_sent += move->call_udp_sent;
total->call_udp_received += move->call_udp_received;
+ total->close += move->close;
+ total->tcp_v4_connection += move->tcp_v4_connection;
+ total->tcp_v6_connection += move->tcp_v6_connection;
}
}
@@ -1652,6 +2104,9 @@ static void ebpf_update_socket_cgroup()
publish->retransmit = in->retransmit;
publish->call_udp_sent = in->call_udp_sent;
publish->call_udp_received = in->call_udp_received;
+ publish->call_close = in->call_close;
+ publish->call_tcp_v4_connection = in->call_tcp_v4_connection;
+ publish->call_tcp_v6_connection = in->call_tcp_v6_connection;
} else {
if (!bpf_map_lookup_elem(fd, &pid, eb)) {
ebpf_socket_bandwidth_accumulator(eb);
@@ -1665,6 +2120,9 @@ static void ebpf_update_socket_cgroup()
publish->retransmit = out->retransmit;
publish->call_udp_sent = out->call_udp_sent;
publish->call_udp_received = out->call_udp_received;
+ publish->call_close = out->close;
+ publish->call_tcp_v4_connection = out->tcp_v4_connection;
+ publish->call_tcp_v6_connection = out->tcp_v6_connection;
}
}
}
@@ -1695,6 +2153,9 @@ static void ebpf_socket_sum_cgroup_pids(ebpf_socket_publish_apps_t *socket, stru
accumulator.retransmit += w->retransmit;
accumulator.call_udp_received += w->call_udp_received;
accumulator.call_udp_sent += w->call_udp_sent;
+ accumulator.call_close += w->close;
+ accumulator.call_tcp_v4_connection += w->tcp_v4_connection;
+ accumulator.call_tcp_v6_connection += w->tcp_v6_connection;
pids = pids->next;
}
@@ -1706,6 +2167,11 @@ static void ebpf_socket_sum_cgroup_pids(ebpf_socket_publish_apps_t *socket, stru
socket->retransmit = (accumulator.retransmit >= socket->retransmit) ? accumulator.retransmit : socket->retransmit;
socket->call_udp_sent = (accumulator.call_udp_sent >= socket->call_udp_sent) ? accumulator.call_udp_sent : socket->call_udp_sent;
socket->call_udp_received = (accumulator.call_udp_received >= socket->call_udp_received) ? accumulator.call_udp_received : socket->call_udp_received;
+ socket->call_close = (accumulator.call_close >= socket->call_close) ? accumulator.call_close : socket->call_close;
+ socket->call_tcp_v4_connection = (accumulator.call_tcp_v4_connection >= socket->call_tcp_v4_connection) ?
+ accumulator.call_tcp_v4_connection : socket->call_tcp_v4_connection;
+ socket->call_tcp_v6_connection = (accumulator.call_tcp_v6_connection >= socket->call_tcp_v6_connection) ?
+ accumulator.call_tcp_v6_connection : socket->call_tcp_v6_connection;
}
/**
@@ -1718,75 +2184,96 @@ static void ebpf_socket_sum_cgroup_pids(ebpf_socket_publish_apps_t *socket, stru
*/
static void ebpf_create_specific_socket_charts(char *type, int update_every)
{
+ int order_basis = 5300;
+ ebpf_create_chart(type, NETDATA_NET_APPS_CONNECTION_TCP_V4,
+ "Calls to tcp_v4_connection",
+ EBPF_COMMON_DIMENSION_CONNECTIONS, NETDATA_CGROUP_NET_GROUP,
+ NETDATA_CGROUP_TCP_V4_CONN_CONTEXT,
+ NETDATA_EBPF_CHART_TYPE_LINE,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++,
+ ebpf_create_global_dimension,
+ &socket_publish_aggregated[NETDATA_IDX_TCP_CONNECTION_V4], 1,
+ update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
+
+ ebpf_create_chart(type, NETDATA_NET_APPS_CONNECTION_TCP_V6,
+ "Calls to tcp_v6_connection",
+ EBPF_COMMON_DIMENSION_CONNECTIONS, NETDATA_CGROUP_NET_GROUP,
+ NETDATA_CGROUP_TCP_V6_CONN_CONTEXT,
+ NETDATA_EBPF_CHART_TYPE_LINE,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++,
+ ebpf_create_global_dimension,
+ &socket_publish_aggregated[NETDATA_IDX_TCP_CONNECTION_V6], 1,
+ update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
+
ebpf_create_chart(type, NETDATA_NET_APPS_BANDWIDTH_RECV,
"Bytes received",
EBPF_COMMON_DIMENSION_CALL, NETDATA_CGROUP_NET_GROUP,
NETDATA_CGROUP_SOCKET_BYTES_RECV_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5300,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++,
ebpf_create_global_dimension,
&socket_publish_aggregated[NETDATA_IDX_TCP_CLEANUP_RBUF], 1,
- update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
+ update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
ebpf_create_chart(type, NETDATA_NET_APPS_BANDWIDTH_SENT,
"Bytes sent",
EBPF_COMMON_DIMENSION_CALL, NETDATA_CGROUP_NET_GROUP,
NETDATA_CGROUP_SOCKET_BYTES_SEND_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5301,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++,
ebpf_create_global_dimension,
socket_publish_aggregated, 1,
- update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
+ update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
ebpf_create_chart(type, NETDATA_NET_APPS_BANDWIDTH_TCP_RECV_CALLS,
"Calls to tcp_cleanup_rbuf.",
EBPF_COMMON_DIMENSION_CALL, NETDATA_CGROUP_NET_GROUP,
NETDATA_CGROUP_SOCKET_TCP_RECV_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5302,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++,
ebpf_create_global_dimension,
&socket_publish_aggregated[NETDATA_IDX_TCP_CLEANUP_RBUF], 1,
- update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
+ update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
ebpf_create_chart(type, NETDATA_NET_APPS_BANDWIDTH_TCP_SEND_CALLS,
"Calls to tcp_sendmsg.",
EBPF_COMMON_DIMENSION_CALL, NETDATA_CGROUP_NET_GROUP,
NETDATA_CGROUP_SOCKET_TCP_SEND_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5303,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++,
ebpf_create_global_dimension,
socket_publish_aggregated, 1,
- update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
+ update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
ebpf_create_chart(type, NETDATA_NET_APPS_BANDWIDTH_TCP_RETRANSMIT,
"Calls to tcp_retransmit.",
EBPF_COMMON_DIMENSION_CALL, NETDATA_CGROUP_NET_GROUP,
NETDATA_CGROUP_SOCKET_TCP_RETRANSMIT_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5304,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++,
ebpf_create_global_dimension,
&socket_publish_aggregated[NETDATA_IDX_TCP_RETRANSMIT], 1,
- update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
+ update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
ebpf_create_chart(type, NETDATA_NET_APPS_BANDWIDTH_UDP_SEND_CALLS,
"Calls to udp_sendmsg",
EBPF_COMMON_DIMENSION_CALL, NETDATA_CGROUP_NET_GROUP,
NETDATA_CGROUP_SOCKET_UDP_SEND_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5305,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++,
ebpf_create_global_dimension,
&socket_publish_aggregated[NETDATA_IDX_UDP_SENDMSG], 1,
- update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
+ update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
ebpf_create_chart(type, NETDATA_NET_APPS_BANDWIDTH_UDP_RECV_CALLS,
"Calls to udp_recvmsg",
EBPF_COMMON_DIMENSION_CALL, NETDATA_CGROUP_NET_GROUP,
NETDATA_CGROUP_SOCKET_UDP_RECV_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5306,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++,
ebpf_create_global_dimension,
&socket_publish_aggregated[NETDATA_IDX_UDP_RECVBUF], 1,
- update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
+ update_every, NETDATA_EBPF_MODULE_NAME_SOCKET);
}
/**
@@ -1799,40 +2286,51 @@ static void ebpf_create_specific_socket_charts(char *type, int update_every)
*/
static void ebpf_obsolete_specific_socket_charts(char *type, int update_every)
{
+ int order_basis = 5300;
+ ebpf_write_chart_obsolete(type, NETDATA_NET_APPS_CONNECTION_TCP_V4, "Calls to tcp_v4_connection",
+ EBPF_COMMON_DIMENSION_CONNECTIONS, NETDATA_APPS_NET_GROUP,
+ NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_SERVICES_SOCKET_TCP_V4_CONN_CONTEXT,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++, update_every);
+
+ ebpf_write_chart_obsolete(type, NETDATA_NET_APPS_CONNECTION_TCP_V6,"Calls to tcp_v6_connection",
+ EBPF_COMMON_DIMENSION_CONNECTIONS, NETDATA_APPS_NET_GROUP,
+ NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_SERVICES_SOCKET_TCP_V6_CONN_CONTEXT,
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++, update_every);
+
ebpf_write_chart_obsolete(type, NETDATA_NET_APPS_BANDWIDTH_RECV, "Bytes received",
EBPF_COMMON_DIMENSION_CALL, NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_SERVICES_SOCKET_BYTES_RECV_CONTEXT,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5300, update_every);
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++, update_every);
ebpf_write_chart_obsolete(type, NETDATA_NET_APPS_BANDWIDTH_SENT,"Bytes sent",
EBPF_COMMON_DIMENSION_CALL, NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_SERVICES_SOCKET_BYTES_SEND_CONTEXT,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5301, update_every);
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++, update_every);
ebpf_write_chart_obsolete(type, NETDATA_NET_APPS_BANDWIDTH_TCP_RECV_CALLS, "Calls to tcp_cleanup_rbuf.",
EBPF_COMMON_DIMENSION_CALL, NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_SERVICES_SOCKET_TCP_RECV_CONTEXT,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5302, update_every);
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++, update_every);
ebpf_write_chart_obsolete(type, NETDATA_NET_APPS_BANDWIDTH_TCP_SEND_CALLS, "Calls to tcp_sendmsg.",
EBPF_COMMON_DIMENSION_CALL, NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_SERVICES_SOCKET_TCP_SEND_CONTEXT,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5303, update_every);
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++, update_every);
ebpf_write_chart_obsolete(type, NETDATA_NET_APPS_BANDWIDTH_TCP_RETRANSMIT, "Calls to tcp_retransmit.",
EBPF_COMMON_DIMENSION_CALL, NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_SERVICES_SOCKET_TCP_RETRANSMIT_CONTEXT,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5304, update_every);
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++, update_every);
ebpf_write_chart_obsolete(type, NETDATA_NET_APPS_BANDWIDTH_UDP_SEND_CALLS, "Calls to udp_sendmsg",
EBPF_COMMON_DIMENSION_CALL, NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_SERVICES_SOCKET_UDP_SEND_CONTEXT,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5305, update_every);
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++, update_every);
ebpf_write_chart_obsolete(type, NETDATA_NET_APPS_BANDWIDTH_UDP_RECV_CALLS, "Calls to udp_recvmsg",
EBPF_COMMON_DIMENSION_CALL, NETDATA_APPS_NET_GROUP, NETDATA_EBPF_CHART_TYPE_LINE,
NETDATA_SERVICES_SOCKET_UDP_RECV_CONTEXT,
- NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5306, update_every);
+ NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + order_basis++, update_every);
}
/*
@@ -1845,6 +2343,16 @@ static void ebpf_obsolete_specific_socket_charts(char *type, int update_every)
*/
static void ebpf_send_specific_socket_data(char *type, ebpf_socket_publish_apps_t *values)
{
+ write_begin_chart(type, NETDATA_NET_APPS_CONNECTION_TCP_V4);
+ write_chart_dimension(socket_publish_aggregated[NETDATA_IDX_TCP_CONNECTION_V4].name,
+ (long long) values->call_tcp_v4_connection);
+ write_end_chart();
+
+ write_begin_chart(type, NETDATA_NET_APPS_CONNECTION_TCP_V6);
+ write_chart_dimension(socket_publish_aggregated[NETDATA_IDX_TCP_CONNECTION_V6].name,
+ (long long) values->call_tcp_v6_connection);
+ write_end_chart();
+
write_begin_chart(type, NETDATA_NET_APPS_BANDWIDTH_SENT);
write_chart_dimension(socket_publish_aggregated[NETDATA_IDX_TCP_SENDMSG].name,
(long long) values->bytes_sent);
@@ -1890,11 +2398,30 @@ static void ebpf_send_specific_socket_data(char *type, ebpf_socket_publish_apps_
**/
static void ebpf_create_systemd_socket_charts(int update_every)
{
+ int order = 20080;
+ ebpf_create_charts_on_systemd(NETDATA_NET_APPS_CONNECTION_TCP_V4,
+ "Calls to tcp_v4_connection", EBPF_COMMON_DIMENSION_CONNECTIONS,
+ NETDATA_APPS_NET_GROUP,
+ NETDATA_EBPF_CHART_TYPE_STACKED,
+ order++,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
+ NETDATA_SERVICES_SOCKET_TCP_V4_CONN_CONTEXT, NETDATA_EBPF_MODULE_NAME_SOCKET,
+ update_every);
+
+ ebpf_create_charts_on_systemd(NETDATA_NET_APPS_CONNECTION_TCP_V6,
+ "Calls to tcp_v6_connection", EBPF_COMMON_DIMENSION_CONNECTIONS,
+ NETDATA_APPS_NET_GROUP,
+ NETDATA_EBPF_CHART_TYPE_STACKED,
+ order++,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
+ NETDATA_SERVICES_SOCKET_TCP_V6_CONN_CONTEXT, NETDATA_EBPF_MODULE_NAME_SOCKET,
+ update_every);
+
ebpf_create_charts_on_systemd(NETDATA_NET_APPS_BANDWIDTH_RECV,
"Bytes received", EBPF_COMMON_DIMENSION_BITS,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20080,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
NETDATA_SERVICES_SOCKET_BYTES_RECV_CONTEXT, NETDATA_EBPF_MODULE_NAME_SOCKET,
update_every);
@@ -1903,7 +2430,7 @@ static void ebpf_create_systemd_socket_charts(int update_every)
"Bytes sent", EBPF_COMMON_DIMENSION_BITS,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20081,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
NETDATA_SERVICES_SOCKET_BYTES_SEND_CONTEXT, NETDATA_EBPF_MODULE_NAME_SOCKET,
update_every);
@@ -1913,7 +2440,7 @@ static void ebpf_create_systemd_socket_charts(int update_every)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20082,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
NETDATA_SERVICES_SOCKET_TCP_RECV_CONTEXT, NETDATA_EBPF_MODULE_NAME_SOCKET,
update_every);
@@ -1923,7 +2450,7 @@ static void ebpf_create_systemd_socket_charts(int update_every)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20083,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
NETDATA_SERVICES_SOCKET_TCP_SEND_CONTEXT, NETDATA_EBPF_MODULE_NAME_SOCKET,
update_every);
@@ -1933,7 +2460,7 @@ static void ebpf_create_systemd_socket_charts(int update_every)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20084,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
NETDATA_SERVICES_SOCKET_TCP_RETRANSMIT_CONTEXT, NETDATA_EBPF_MODULE_NAME_SOCKET,
update_every);
@@ -1943,7 +2470,7 @@ static void ebpf_create_systemd_socket_charts(int update_every)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20085,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
NETDATA_SERVICES_SOCKET_UDP_SEND_CONTEXT, NETDATA_EBPF_MODULE_NAME_SOCKET,
update_every);
@@ -1953,7 +2480,7 @@ static void ebpf_create_systemd_socket_charts(int update_every)
EBPF_COMMON_DIMENSION_CALL,
NETDATA_APPS_NET_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED,
- 20086,
+ order++,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX],
NETDATA_SERVICES_SOCKET_UDP_RECV_CONTEXT, NETDATA_EBPF_MODULE_NAME_SOCKET,
update_every);
@@ -1971,6 +2498,24 @@ static int ebpf_send_systemd_socket_charts()
{
int ret = 1;
ebpf_cgroup_target_t *ect;
+ write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_NET_APPS_CONNECTION_TCP_V4);
+ for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
+ if (unlikely(ect->systemd) && unlikely(ect->updated)) {
+ write_chart_dimension(ect->name, (long long)ect->publish_socket.call_tcp_v4_connection);
+ } else
+ ret = 0;
+ }
+ write_end_chart();
+
+ write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_NET_APPS_CONNECTION_TCP_V6);
+ for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
+ if (unlikely(ect->systemd) && unlikely(ect->updated)) {
+ write_chart_dimension(ect->name, (long long)ect->publish_socket.call_tcp_v6_connection);
+ } else
+ ret = 0;
+ }
+ write_end_chart();
+
write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_NET_APPS_BANDWIDTH_SENT);
for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
if (unlikely(ect->systemd) && unlikely(ect->updated)) {
@@ -3334,6 +3879,40 @@ void parse_table_size_options(struct config *cfg)
EBPF_CONFIG_UDP_SIZE, NETDATA_MAXIMUM_UDP_CONNECTIONS_ALLOWED);
}
+/*
+ * Load BPF
+ *
+ * Load BPF files.
+ *
+ * @param em the structure with configuration
+ */
+static int ebpf_socket_load_bpf(ebpf_module_t *em)
+{
+ int ret = 0;
+
+ if (em->load == EBPF_LOAD_LEGACY) {
+ probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &objects);
+ if (!probe_links) {
+ ret = -1;
+ }
+ }
+#ifdef LIBBPF_MAJOR_VERSION
+ else {
+ bpf_obj = socket_bpf__open();
+ if (!bpf_obj)
+ ret = -1;
+ else
+ ret = ebpf_socket_load_and_attach(bpf_obj, em);
+ }
+#endif
+
+ if (ret) {
+ error("%s %s", EBPF_DEFAULT_ERROR_MSG, em->thread_name);
+ }
+
+ return ret;
+}
+
/**
* Socket thread
*
@@ -3375,8 +3954,10 @@ void *ebpf_socket_thread(void *ptr)
if (running_on_kernel < NETDATA_EBPF_KERNEL_5_0)
em->mode = MODE_ENTRY;
- probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &objects);
- if (!probe_links) {
+#ifdef LIBBPF_MAJOR_VERSION
+ ebpf_adjust_thread_load(em, default_btf);
+#endif
+ if (ebpf_socket_load_bpf(em)) {
em->enabled = CONFIG_BOOLEAN_NO;
pthread_mutex_unlock(&lock);
goto endsocket;
diff --git a/collectors/ebpf.plugin/ebpf_socket.h b/collectors/ebpf.plugin/ebpf_socket.h
index e3c000c76..672001301 100644
--- a/collectors/ebpf.plugin/ebpf_socket.h
+++ b/collectors/ebpf.plugin/ebpf_socket.h
@@ -43,11 +43,27 @@ enum ebpf_socket_publish_index {
NETDATA_IDX_UDP_RECVBUF,
NETDATA_IDX_UDP_SENDMSG,
NETDATA_IDX_TCP_RETRANSMIT,
+ NETDATA_IDX_TCP_CONNECTION_V4,
+ NETDATA_IDX_TCP_CONNECTION_V6,
+ NETDATA_IDX_INCOMING_CONNECTION_TCP,
+ NETDATA_IDX_INCOMING_CONNECTION_UDP,
// Keep this as last and don't skip numbers as it is used as element counter
NETDATA_MAX_SOCKET_VECTOR
};
+enum socket_functions {
+ NETDATA_FCNT_INET_CSK_ACCEPT,
+ NETDATA_FCNT_TCP_RETRANSMIT,
+ NETDATA_FCNT_CLEANUP_RBUF,
+ NETDATA_FCNT_TCP_CLOSE,
+ NETDATA_FCNT_UDP_RECEVMSG,
+ NETDATA_FCNT_TCP_SENDMSG,
+ NETDATA_FCNT_UDP_SENDMSG,
+ NETDATA_FCNT_TCP_V4_CONNECT,
+ NETDATA_FCNT_TCP_V6_CONNECT
+};
+
typedef enum ebpf_socket_idx {
NETDATA_KEY_CALLS_TCP_SENDMSG,
NETDATA_KEY_ERROR_TCP_SENDMSG,
@@ -69,6 +85,12 @@ typedef enum ebpf_socket_idx {
NETDATA_KEY_TCP_RETRANSMIT,
+ NETDATA_KEY_CALLS_TCP_CONNECT_IPV4,
+ NETDATA_KEY_ERROR_TCP_CONNECT_IPV4,
+
+ NETDATA_KEY_CALLS_TCP_CONNECT_IPV6,
+ NETDATA_KEY_ERROR_TCP_CONNECT_IPV6,
+
// Keep this as last and don't skip numbers as it is used as element counter
NETDATA_SOCKET_COUNTER
} ebpf_socket_index_t;
@@ -78,6 +100,8 @@ typedef enum ebpf_socket_idx {
#define NETDATA_CGROUP_NET_GROUP "network (eBPF)"
// Global chart name
+#define NETDATA_TCP_OUTBOUND_CONNECTIONS "tcp_outbound_conn"
+#define NETDATA_INBOUND_CONNECTIONS "inbound_conn"
#define NETDATA_TCP_FUNCTION_COUNT "tcp_functions"
#define NETDATA_TCP_FUNCTION_BITS "total_tcp_bandwidth"
#define NETDATA_TCP_FUNCTION_ERROR "tcp_error"
@@ -87,6 +111,8 @@ typedef enum ebpf_socket_idx {
#define NETDATA_UDP_FUNCTION_ERROR "udp_error"
// Charts created on Apps submenu
+#define NETDATA_NET_APPS_CONNECTION_TCP_V4 "outbound_conn_v4"
+#define NETDATA_NET_APPS_CONNECTION_TCP_V6 "outbound_conn_v6"
#define NETDATA_NET_APPS_BANDWIDTH_SENT "total_bandwidth_sent"
#define NETDATA_NET_APPS_BANDWIDTH_RECV "total_bandwidth_recv"
#define NETDATA_NET_APPS_BANDWIDTH_TCP_SEND_CALLS "bandwidth_tcp_send"
@@ -114,6 +140,8 @@ typedef enum ebpf_socket_idx {
#define NETDATA_MAXIMUM_IPV4_CIDR 32
// Contexts
+#define NETDATA_CGROUP_TCP_V4_CONN_CONTEXT "cgroup.net_conn_ipv4"
+#define NETDATA_CGROUP_TCP_V6_CONN_CONTEXT "cgroup.net_conn_ipv6"
#define NETDATA_CGROUP_SOCKET_BYTES_RECV_CONTEXT "cgroup.net_bytes_recv"
#define NETDATA_CGROUP_SOCKET_BYTES_SEND_CONTEXT "cgroup.net_bytes_send"
#define NETDATA_CGROUP_SOCKET_TCP_RECV_CONTEXT "cgroup.net_tcp_recv"
@@ -122,6 +150,8 @@ typedef enum ebpf_socket_idx {
#define NETDATA_CGROUP_SOCKET_UDP_RECV_CONTEXT "cgroup.net_udp_recv"
#define NETDATA_CGROUP_SOCKET_UDP_SEND_CONTEXT "cgroup.net_udp_send"
+#define NETDATA_SERVICES_SOCKET_TCP_V4_CONN_CONTEXT "services.net_conn_ipv4"
+#define NETDATA_SERVICES_SOCKET_TCP_V6_CONN_CONTEXT "services.net_conn_ipv6"
#define NETDATA_SERVICES_SOCKET_BYTES_RECV_CONTEXT "services.net_bytes_recv"
#define NETDATA_SERVICES_SOCKET_BYTES_SEND_CONTEXT "services.net_bytes_send"
#define NETDATA_SERVICES_SOCKET_TCP_RECV_CONTEXT "services.net_tcp_recv"
@@ -132,22 +162,16 @@ typedef enum ebpf_socket_idx {
typedef struct ebpf_socket_publish_apps {
// Data read
- uint64_t bytes_sent; // Bytes sent
- uint64_t bytes_received; // Bytes received
- uint64_t call_tcp_sent; // Number of times tcp_sendmsg was called
- uint64_t call_tcp_received; // Number of times tcp_cleanup_rbuf was called
- uint64_t retransmit; // Number of times tcp_retransmit was called
- uint64_t call_udp_sent; // Number of times udp_sendmsg was called
- uint64_t call_udp_received; // Number of times udp_recvmsg was called
-
- // Publish information.
- uint64_t publish_sent_bytes;
- uint64_t publish_received_bytes;
- uint64_t publish_tcp_sent;
- uint64_t publish_tcp_received;
- uint64_t publish_retransmit;
- uint64_t publish_udp_sent;
- uint64_t publish_udp_received;
+ uint64_t bytes_sent; // Bytes sent
+ uint64_t bytes_received; // Bytes received
+ uint64_t call_tcp_sent; // Number of times tcp_sendmsg was called
+ uint64_t call_tcp_received; // Number of times tcp_cleanup_rbuf was called
+ uint64_t retransmit; // Number of times tcp_retransmit was called
+ uint64_t call_udp_sent; // Number of times udp_sendmsg was called
+ uint64_t call_udp_received; // Number of times udp_recvmsg was called
+ uint64_t call_close; // Number of times tcp_close was called
+ uint64_t call_tcp_v4_connection;// Number of times tcp_v4_connect was called
+ uint64_t call_tcp_v6_connection;// Number of times tcp_v6_connect was called
} ebpf_socket_publish_apps_t;
typedef struct ebpf_network_viewer_dimension_names {
@@ -169,10 +193,24 @@ typedef struct ebpf_network_viewer_port_list {
uint16_t cmp_first;
uint16_t cmp_last;
- uint8_t protocol;
+ uint16_t protocol;
+ uint32_t pid;
+ uint32_t tgid;
+ uint64_t connections;
struct ebpf_network_viewer_port_list *next;
} ebpf_network_viewer_port_list_t;
+typedef struct netdata_passive_connection {
+ uint32_t tgid;
+ uint32_t pid;
+ uint64_t counter;
+} netdata_passive_connection_t;
+
+typedef struct netdata_passive_connection_idx {
+ uint16_t protocol;
+ uint16_t port;
+} netdata_passive_connection_idx_t;
+
/**
* Union used to store ip addresses
*/
@@ -238,20 +276,18 @@ typedef struct netdata_socket {
uint64_t sent_bytes;
uint64_t first; // First timestamp
uint64_t ct; // Current timestamp
- uint16_t retransmit; // It is never used with UDP
- uint8_t protocol;
- uint8_t removeme;
- uint32_t reserved;
+ uint32_t retransmit; // It is never used with UDP
+ uint16_t protocol;
+ uint16_t reserved;
} netdata_socket_t __attribute__((__aligned__(8)));
-
typedef struct netdata_plot_values {
// Values used in the previous iteration
uint64_t recv_packets;
uint64_t sent_packets;
uint64_t recv_bytes;
uint64_t sent_bytes;
- uint16_t retransmit;
+ uint32_t retransmit;
uint64_t last_time;
@@ -322,7 +358,7 @@ typedef struct netdata_vector_plot {
extern void clean_port_structure(ebpf_network_viewer_port_list_t **clean);
extern ebpf_network_viewer_port_list_t *listen_ports;
-extern void update_listen_table(uint16_t value, uint8_t proto);
+extern void update_listen_table(uint16_t value, uint16_t proto, netdata_passive_connection_t *values);
extern void parse_network_viewer_section(struct config *cfg);
extern void fill_ip_list(ebpf_network_viewer_ip_list_t **out, ebpf_network_viewer_ip_list_t *in, char *table);
extern void parse_service_name_section(struct config *cfg);
@@ -330,5 +366,6 @@ extern void clean_socket_apps_structures();
extern ebpf_socket_publish_apps_t **socket_bandwidth_curr;
extern struct config socket_config;
+extern netdata_ebpf_targets_t socket_targets[];
#endif
diff --git a/collectors/ebpf.plugin/ebpf_swap.c b/collectors/ebpf.plugin/ebpf_swap.c
index 82eb9db88..906c83da5 100644
--- a/collectors/ebpf.plugin/ebpf_swap.c
+++ b/collectors/ebpf.plugin/ebpf_swap.c
@@ -644,7 +644,7 @@ static void ebpf_swap_allocate_global_vectors(int apps)
static void ebpf_create_swap_charts(int update_every)
{
ebpf_create_chart(NETDATA_EBPF_SYSTEM_GROUP, NETDATA_MEM_SWAP_CHART,
- "Calls to internal functions used to access swap.",
+ "Calls to access swap memory",
EBPF_COMMON_DIMENSION_CALL, NETDATA_SYSTEM_SWAP_SUBMENU,
NULL,
NETDATA_EBPF_CHART_TYPE_LINE,
diff --git a/collectors/ebpf.plugin/ebpf_sync.c b/collectors/ebpf.plugin/ebpf_sync.c
index b3f1b6524..233c34a5b 100644
--- a/collectors/ebpf.plugin/ebpf_sync.c
+++ b/collectors/ebpf.plugin/ebpf_sync.c
@@ -44,21 +44,179 @@ struct config sync_config = { .first_section = NULL,
.rwlock = AVL_LOCK_INITIALIZER } };
ebpf_sync_syscalls_t local_syscalls[] = {
- {.syscall = "sync", .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
- {.syscall = "syncfs", .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
- {.syscall = "msync", .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
- {.syscall = "fsync", .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
- {.syscall = "fdatasync", .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
- {.syscall = "sync_file_range", .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
+ {.syscall = NETDATA_SYSCALLS_SYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
+ {.syscall = NETDATA_SYSCALLS_SYNCFS, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
+ {.syscall = NETDATA_SYSCALLS_MSYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
+ {.syscall = NETDATA_SYSCALLS_FSYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
+ {.syscall = NETDATA_SYSCALLS_FDATASYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
+ {.syscall = NETDATA_SYSCALLS_SYNC_FILE_RANGE, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
{.syscall = NULL, .enabled = CONFIG_BOOLEAN_NO, .objects = NULL, .probe_links = NULL}
};
+netdata_ebpf_targets_t sync_targets[] = { {.name = NETDATA_SYSCALLS_SYNC, .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = NETDATA_SYSCALLS_SYNCFS, .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = NETDATA_SYSCALLS_MSYNC, .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = NETDATA_SYSCALLS_FSYNC, .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = NETDATA_SYSCALLS_FDATASYNC, .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = NETDATA_SYSCALLS_SYNC_FILE_RANGE, .mode = EBPF_LOAD_TRAMPOLINE},
+ {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}};
+
+
+#ifdef LIBBPF_MAJOR_VERSION
+/*****************************************************************
+ *
+ * BTF FUNCTIONS
+ *
+ *****************************************************************/
+
+/**
+ * Disable probe
+ *
+ * Disable kprobe to use another method.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static inline void ebpf_sync_disable_probe(struct sync_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_sync_kprobe, false);
+}
+
+/**
+ * Disable tramppoline
+ *
+ * Disable trampoline to use another method.
+ *
+ * @param obj is the main structure for bpf objects.
+ */
+static inline void ebpf_sync_disable_trampoline(struct sync_bpf *obj)
+{
+ bpf_program__set_autoload(obj->progs.netdata_sync_fentry, false);
+}
+
+/**
+ * Disable tracepoint
+ *
+ * Disable tracepoints according information given.
+ *
+ * @param obj object loaded
+ * @param idx Which syscall will not be disabled
+ */
+void ebpf_sync_disable_tracepoints(struct sync_bpf *obj, sync_syscalls_index_t idx)
+{
+ if (idx != NETDATA_SYNC_SYNC_IDX)
+ bpf_program__set_autoload(obj->progs.netdata_sync_entry, false);
+
+ if (idx != NETDATA_SYNC_SYNCFS_IDX)
+ bpf_program__set_autoload(obj->progs.netdata_syncfs_entry, false);
+
+ if (idx != NETDATA_SYNC_MSYNC_IDX)
+ bpf_program__set_autoload(obj->progs.netdata_msync_entry, false);
+
+ if (idx != NETDATA_SYNC_FSYNC_IDX)
+ bpf_program__set_autoload(obj->progs.netdata_fsync_entry, false);
+
+ if (idx != NETDATA_SYNC_FDATASYNC_IDX)
+ bpf_program__set_autoload(obj->progs.netdata_fdatasync_entry, false);
+
+ if (idx != NETDATA_SYNC_SYNC_FILE_RANGE_IDX)
+ bpf_program__set_autoload(obj->progs.netdata_sync_file_range_entry, false);
+}
+
+/**
+ * Set hash tables
+ *
+ * Set the values for maps according the value given by kernel.
+ *
+ * @param obj is the main structure for bpf objects.
+ * @param idx the index for the main structure
+ */
+static void ebpf_sync_set_hash_tables(struct sync_bpf *obj, sync_syscalls_index_t idx)
+{
+ sync_maps[idx].map_fd = bpf_map__fd(obj->maps.tbl_sync);
+}
+
+/**
+ * Load and attach
+ *
+ * Load and attach the eBPF code in kernel.
+ *
+ * @param obj is the main structure for bpf objects.
+ * @param em the structure with configuration
+ * @param target the syscall that we are attaching a tracer.
+ * @param idx the index for the main structure
+ *
+ * @return it returns 0 on succes and -1 otherwise
+ */
+static inline int ebpf_sync_load_and_attach(struct sync_bpf *obj, ebpf_module_t *em, char *target,
+ sync_syscalls_index_t idx)
+{
+ netdata_ebpf_targets_t *synct = em->targets;
+ netdata_ebpf_program_loaded_t test = synct[NETDATA_SYNC_SYNC_IDX].mode;
+
+ if (test == EBPF_LOAD_TRAMPOLINE) {
+ ebpf_sync_disable_probe(obj);
+ ebpf_sync_disable_tracepoints(obj, NETDATA_SYNC_IDX_END);
+
+ bpf_program__set_attach_target(obj->progs.netdata_sync_fentry, 0,
+ target);
+ } else if (test == EBPF_LOAD_PROBE ||
+ test == EBPF_LOAD_RETPROBE) {
+ ebpf_sync_disable_tracepoints(obj, NETDATA_SYNC_IDX_END);
+ ebpf_sync_disable_trampoline(obj);
+ } else {
+ ebpf_sync_disable_probe(obj);
+ ebpf_sync_disable_trampoline(obj);
+
+ ebpf_sync_disable_tracepoints(obj, idx);
+ }
+
+ int ret = sync_bpf__load(obj);
+ if (!ret) {
+ if (test != EBPF_LOAD_PROBE && test != EBPF_LOAD_RETPROBE) {
+ ret = sync_bpf__attach(obj);
+ } else {
+ obj->links.netdata_sync_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_sync_kprobe,
+ false, target);
+ ret = (int)libbpf_get_error(obj->links.netdata_sync_kprobe);
+ }
+
+ if (!ret)
+ ebpf_sync_set_hash_tables(obj, idx);
+ }
+
+ return ret;
+}
+#endif
+
/*****************************************************************
*
* INITIALIZE THREAD
*
*****************************************************************/
+/**
+ * Load Legacy
+ *
+ * Load legacy code.
+ *
+ * @param w is the sync output structure with pointers to objects loaded.
+ * @param em is structure with configuration
+ *
+ * @return 0 on success and -1 otherwise.
+ */
+static int ebpf_sync_load_legacy(ebpf_sync_syscalls_t *w, ebpf_module_t *em)
+{
+ em->thread_name = w->syscall;
+ if (!w->probe_links) {
+ w->probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &w->objects);
+ if (!w->probe_links) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
/*
* Initialize Syscalls
*
@@ -70,15 +228,33 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
{
int i;
const char *saved_name = em->thread_name;
+ sync_syscalls_index_t errors = 0;
for (i = 0; local_syscalls[i].syscall; i++) {
ebpf_sync_syscalls_t *w = &local_syscalls[i];
- if (!w->probe_links && w->enabled) {
- em->thread_name = w->syscall;
- w->probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &w->objects);
- if (!w->probe_links) {
+ if (w->enabled) {
+ if (em->load == EBPF_LOAD_LEGACY) {
+ if (ebpf_sync_load_legacy(w, em))
+ errors++;
+
em->thread_name = saved_name;
- return -1;
}
+#ifdef LIBBPF_MAJOR_VERSION
+ else {
+ char syscall[NETDATA_EBPF_MAX_SYSCALL_LENGTH];
+ ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH, w->syscall, running_on_kernel);
+ w->sync_obj = sync_bpf__open();
+ if (!w->sync_obj) {
+ errors++;
+ } else {
+ if (ebpf_sync_load_and_attach(w->sync_obj, em, syscall, i)) {
+ if (ebpf_sync_load_legacy(w, em))
+ errors++;
+
+ em->thread_name = saved_name;
+ }
+ }
+ }
+#endif
}
}
em->thread_name = saved_name;
@@ -254,6 +430,10 @@ void ebpf_sync_cleanup_objects()
}
bpf_object__close(w->objects);
}
+#ifdef LIBBPF_MAJOR_VERSION
+ else if (w->sync_obj)
+ sync_bpf__destroy(w->sync_obj);
+#endif
}
}
@@ -386,6 +566,9 @@ void *ebpf_sync_thread(void *ptr)
if (!em->enabled)
goto endsync;
+#ifdef LIBBPF_MAJOR_VERSION
+ ebpf_adjust_thread_load(em, default_btf);
+#endif
if (ebpf_sync_initialize_syscall(em)) {
em->enabled = CONFIG_BOOLEAN_NO;
goto endsync;
diff --git a/collectors/ebpf.plugin/ebpf_sync.h b/collectors/ebpf.plugin/ebpf_sync.h
index e40c77a3f..2bc18c544 100644
--- a/collectors/ebpf.plugin/ebpf_sync.h
+++ b/collectors/ebpf.plugin/ebpf_sync.h
@@ -3,6 +3,10 @@
#ifndef NETDATA_EBPF_SYNC_H
#define NETDATA_EBPF_SYNC_H 1
+#ifdef LIBBPF_MAJOR_VERSION
+#include "includes/sync.skel.h"
+#endif
+
// Module name
#define NETDATA_EBPF_MODULE_NAME_SYNC "sync"
@@ -13,13 +17,20 @@
#define NETDATA_EBPF_FILE_SEGMENT_CHART "file_segment"
#define NETDATA_EBPF_SYNC_SUBMENU "synchronization (eBPF)"
+#define NETDATA_SYSCALLS_SYNC "sync"
+#define NETDATA_SYSCALLS_SYNCFS "syncfs"
+#define NETDATA_SYSCALLS_MSYNC "msync"
+#define NETDATA_SYSCALLS_FSYNC "fsync"
+#define NETDATA_SYSCALLS_FDATASYNC "fdatasync"
+#define NETDATA_SYSCALLS_SYNC_FILE_RANGE "sync_file_range"
+
#define NETDATA_EBPF_SYNC_SLEEP_MS 800000ULL
// configuration file
#define NETDATA_SYNC_CONFIG_FILE "sync.conf"
#define NETDATA_SYNC_CONFIG_NAME "syscalls"
-enum sync_syscalls_index {
+typedef enum sync_syscalls_index {
NETDATA_SYNC_SYNC_IDX,
NETDATA_SYNC_SYNCFS_IDX,
NETDATA_SYNC_MSYNC_IDX,
@@ -28,15 +39,23 @@ enum sync_syscalls_index {
NETDATA_SYNC_SYNC_FILE_RANGE_IDX,
NETDATA_SYNC_IDX_END
-};
+} sync_syscalls_index_t;
typedef struct ebpf_sync_syscalls {
char *syscall;
int enabled;
uint32_t flags;
+ // BTF structure
struct bpf_object *objects;
struct bpf_link **probe_links;
+
+ // BPF structure
+#ifdef LIBBPF_MAJOR_VERSION
+ struct sync_bpf *sync_obj;
+#else
+ void *sync_obj;
+#endif
} ebpf_sync_syscalls_t;
enum netdata_sync_charts {
@@ -52,5 +71,6 @@ enum netdata_sync_table {
extern void *ebpf_sync_thread(void *ptr);
extern struct config sync_config;
+extern netdata_ebpf_targets_t sync_targets[];
#endif /* NETDATA_EBPF_SYNC_H */
diff --git a/collectors/ebpf.plugin/ebpf_vfs.c b/collectors/ebpf.plugin/ebpf_vfs.c
index d1c418f85..e14165fb7 100644
--- a/collectors/ebpf.plugin/ebpf_vfs.c
+++ b/collectors/ebpf.plugin/ebpf_vfs.c
@@ -670,42 +670,42 @@ static void ebpf_create_specific_vfs_charts(char *type, ebpf_module_t *em)
1, em->update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
ebpf_create_chart(type, NETDATA_SYSCALL_APPS_VFS_FSYNC, "Calls for <code>vfs_fsync</code>",
- EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NULL,
+ EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NETDATA_CGROUP_VFS_FSYNC_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5507,
ebpf_create_global_dimension, &vfs_publish_aggregated[NETDATA_KEY_PUBLISH_VFS_FSYNC],
1, em->update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
if (em->mode < MODE_ENTRY) {
ebpf_create_chart(type, NETDATA_SYSCALL_APPS_VFS_FSYNC_CALLS_ERROR, "Sync error",
- EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NULL,
+ EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NETDATA_CGROUP_VFS_FSYNC_ERROR_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5508,
ebpf_create_global_dimension, &vfs_publish_aggregated[NETDATA_KEY_PUBLISH_VFS_FSYNC],
1, em->update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
}
ebpf_create_chart(type, NETDATA_SYSCALL_APPS_VFS_OPEN, "Calls for <code>vfs_open</code>",
- EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NULL,
+ EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NETDATA_CGROUP_VFS_OPEN_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5509,
ebpf_create_global_dimension, &vfs_publish_aggregated[NETDATA_KEY_PUBLISH_VFS_OPEN],
1, em->update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
if (em->mode < MODE_ENTRY) {
ebpf_create_chart(type, NETDATA_SYSCALL_APPS_VFS_OPEN_CALLS_ERROR, "Open error",
- EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NULL,
+ EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NETDATA_CGROUP_VFS_OPEN_ERROR_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5510,
ebpf_create_global_dimension, &vfs_publish_aggregated[NETDATA_KEY_PUBLISH_VFS_OPEN],
1, em->update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
}
ebpf_create_chart(type, NETDATA_SYSCALL_APPS_VFS_CREATE, "Calls for <code>vfs_create</code>",
- EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NULL,
+ EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NETDATA_CGROUP_VFS_CREATE_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5511,
ebpf_create_global_dimension, &vfs_publish_aggregated[NETDATA_KEY_PUBLISH_VFS_CREATE],
1, em->update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
if (em->mode < MODE_ENTRY) {
ebpf_create_chart(type, NETDATA_SYSCALL_APPS_VFS_CREATE_CALLS_ERROR, "Create error",
- EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NULL,
+ EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP, NETDATA_CGROUP_VFS_CREATE_ERROR_CONTEXT,
NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5512,
ebpf_create_global_dimension, &vfs_publish_aggregated[NETDATA_KEY_PUBLISH_VFS_CREATE],
1, em->update_every, NETDATA_EBPF_MODULE_NAME_SWAP);
@@ -763,37 +763,37 @@ static void ebpf_obsolete_specific_vfs_charts(char *type, ebpf_module_t *em)
ebpf_write_chart_obsolete(type, NETDATA_SYSCALL_APPS_VFS_FSYNC, "Calls for <code>vfs_fsync</code>",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_GROUP,
- NETDATA_EBPF_CHART_TYPE_LINE, NULL,
+ NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_VFS_FSYNC_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5507, em->update_every);
if (em->mode < MODE_ENTRY) {
ebpf_write_chart_obsolete(type, NETDATA_SYSCALL_APPS_VFS_FSYNC_CALLS_ERROR, "Sync error",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_GROUP,
- NETDATA_EBPF_CHART_TYPE_LINE, NULL,
+ NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_VFS_FSYNC_ERROR_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5508, em->update_every);
}
ebpf_write_chart_obsolete(type, NETDATA_SYSCALL_APPS_VFS_OPEN, "Calls for <code>vfs_open</code>",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_GROUP,
- NETDATA_EBPF_CHART_TYPE_LINE, NULL,
+ NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_VFS_OPEN_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5509, em->update_every);
if (em->mode < MODE_ENTRY) {
ebpf_write_chart_obsolete(type, NETDATA_SYSCALL_APPS_VFS_OPEN_CALLS_ERROR, "Open error",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_GROUP,
- NETDATA_EBPF_CHART_TYPE_LINE, NULL,
+ NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_VFS_OPEN_ERROR_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5510, em->update_every);
}
ebpf_write_chart_obsolete(type, NETDATA_SYSCALL_APPS_VFS_CREATE, "Calls for <code>vfs_create</code>",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_GROUP,
- NETDATA_EBPF_CHART_TYPE_LINE, NULL,
+ NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_VFS_CREATE_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5511, em->update_every);
if (em->mode < MODE_ENTRY) {
ebpf_write_chart_obsolete(type, NETDATA_SYSCALL_APPS_VFS_CREATE_CALLS_ERROR, "Create error",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_GROUP,
- NETDATA_EBPF_CHART_TYPE_LINE, NULL,
+ NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_CGROUP_VFS_CREATE_ERROR_CONTEXT,
NETDATA_CHART_PRIO_CGROUPS_CONTAINERS + 5512, em->update_every);
}
}
@@ -943,41 +943,41 @@ static void ebpf_create_systemd_vfs_charts(ebpf_module_t *em)
ebpf_create_charts_on_systemd(NETDATA_SYSCALL_APPS_VFS_FSYNC, "Calls to <code>vfs_fsync</code>",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED, 20072,
- ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NULL,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NETDATA_SYSTEMD_VFS_FSYNC_CONTEXT,
NETDATA_EBPF_MODULE_NAME_VFS, em->update_every);
if (em->mode < MODE_ENTRY) {
ebpf_create_charts_on_systemd(NETDATA_SYSCALL_APPS_VFS_FSYNC_CALLS_ERROR, "Sync error",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED, 20073,
- ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NULL,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NETDATA_SYSTEMD_VFS_FSYNC_ERROR_CONTEXT,
NETDATA_EBPF_MODULE_NAME_VFS, em->update_every);
}
ebpf_create_charts_on_systemd(NETDATA_SYSCALL_APPS_VFS_OPEN, "Calls to <code>vfs_open</code>",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED, 20074,
- ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NULL,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NETDATA_SYSTEMD_VFS_OPEN_CONTEXT,
NETDATA_EBPF_MODULE_NAME_VFS, em->update_every);
if (em->mode < MODE_ENTRY) {
ebpf_create_charts_on_systemd(NETDATA_SYSCALL_APPS_VFS_OPEN_CALLS_ERROR, "Open error",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED, 20075,
- ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NULL,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NETDATA_SYSTEMD_VFS_OPEN_ERROR_CONTEXT,
NETDATA_EBPF_MODULE_NAME_VFS, em->update_every);
}
ebpf_create_charts_on_systemd(NETDATA_SYSCALL_APPS_VFS_CREATE, "Calls to <code>vfs_create</code>",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED, 20076,
- ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NULL,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NETDATA_SYSTEMD_VFS_CREATE_CONTEXT,
NETDATA_EBPF_MODULE_NAME_VFS, em->update_every);
if (em->mode < MODE_ENTRY) {
ebpf_create_charts_on_systemd(NETDATA_SYSCALL_APPS_VFS_CREATE_CALLS_ERROR, "Create error",
EBPF_COMMON_DIMENSION_CALL, NETDATA_VFS_CGROUP_GROUP,
NETDATA_EBPF_CHART_TYPE_STACKED, 20077,
- ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NULL,
+ ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX], NETDATA_SYSTEMD_VFS_CREATE_ERROR_CONTEXT,
NETDATA_EBPF_MODULE_NAME_VFS, em->update_every);
}
}
diff --git a/collectors/ebpf.plugin/ebpf_vfs.h b/collectors/ebpf.plugin/ebpf_vfs.h
index 0a972c983..67542ad44 100644
--- a/collectors/ebpf.plugin/ebpf_vfs.h
+++ b/collectors/ebpf.plugin/ebpf_vfs.h
@@ -50,6 +50,12 @@
#define NETDATA_CGROUP_VFS_READ_ERROR_CONTEXT "cgroup.vfs_read_error"
#define NETDATA_CGROUP_VFS_WRITE_BYTES_CONTEXT "cgroup.vfs_write_bytes"
#define NETDATA_CGROUP_VFS_READ_BYTES_CONTEXT "cgroup.vfs_read_bytes"
+#define NETDATA_CGROUP_VFS_CREATE_CONTEXT "cgroup.vfs_create"
+#define NETDATA_CGROUP_VFS_CREATE_ERROR_CONTEXT "cgroup.vfs_create_error"
+#define NETDATA_CGROUP_VFS_OPEN_CONTEXT "cgroup.vfs_open"
+#define NETDATA_CGROUP_VFS_OPEN_ERROR_CONTEXT "cgroup.vfs_open_error"
+#define NETDATA_CGROUP_VFS_FSYNC_CONTEXT "cgroup.vfs_fsync"
+#define NETDATA_CGROUP_VFS_FSYNC_ERROR_CONTEXT "cgroup.vfs_fsync_error"
#define NETDATA_SYSTEMD_VFS_UNLINK_CONTEXT "services.vfs_unlink"
#define NETDATA_SYSTEMD_VFS_WRITE_CONTEXT "services.vfs_write"
@@ -58,6 +64,12 @@
#define NETDATA_SYSTEMD_VFS_READ_ERROR_CONTEXT "services.vfs_read_error"
#define NETDATA_SYSTEMD_VFS_WRITE_BYTES_CONTEXT "services.vfs_write_bytes"
#define NETDATA_SYSTEMD_VFS_READ_BYTES_CONTEXT "services.vfs_read_bytes"
+#define NETDATA_SYSTEMD_VFS_CREATE_CONTEXT "services.vfs_create"
+#define NETDATA_SYSTEMD_VFS_CREATE_ERROR_CONTEXT "services.vfs_create_error"
+#define NETDATA_SYSTEMD_VFS_OPEN_CONTEXT "services.vfs_open"
+#define NETDATA_SYSTEMD_VFS_OPEN_ERROR_CONTEXT "services.vfs_open_error"
+#define NETDATA_SYSTEMD_VFS_FSYNC_CONTEXT "services.vfs_fsync"
+#define NETDATA_SYSTEMD_VFS_FSYNC_ERROR_CONTEXT "services.vfs_fsync_error"
typedef struct netdata_publish_vfs {
uint64_t pid_tgid;