| 1 | <!--startmeta |
| 2 | custom_edit_url: "https://github.com/netdata/netdata/edit/master/src/collectors/ebpf.plugin/integrations/ebpf_shm.md" |
| 3 | meta_yaml: "https://github.com/netdata/netdata/edit/master/src/collectors/ebpf.plugin/metadata.yaml" |
| 4 | sidebar_label: "eBPF SHM" |
| 5 | learn_status: "Published" |
| 6 | learn_rel_path: "Collecting Metrics/Collectors/Operating Systems" |
| 7 | keywords: ['syscall', 'shared memory', 'eBPF'] |
| 8 | message: "DO NOT EDIT THIS FILE DIRECTLY, IT IS GENERATED BY THE COLLECTOR'S metadata.yaml FILE" |
| 9 | endmeta--> |
| 10 | |
| 11 | # eBPF SHM |
| 12 | |
| 13 | |
| 14 | <img src="https://netdata.cloud/img/ebpf.jpg" width="150"/> |
| 15 | |
| 16 | |
| 17 | Plugin: ebpf.plugin |
| 18 | Module: shm |
| 19 | |
| 20 | <img src="https://img.shields.io/badge/maintained%20by-Netdata-%2300ab44" /> |
| 21 | |
| 22 | ## Overview |
| 23 | |
| 24 | Monitor syscall responsible to manipulate shared memory. |
| 25 | |
| 26 | Attach tracing (kprobe, trampoline) to internal kernel functions according options used to compile kernel. |
| 27 | |
| 28 | This collector is only supported on the following platforms: |
| 29 | |
| 30 | - Linux |
| 31 | |
| 32 | This collector supports collecting metrics from multiple instances of this integration, including remote instances. |
| 33 | |
| 34 | The plugin needs setuid because it loads data inside kernel. Netada sets necessary permission during installation time. |
| 35 | |
| 36 | eBPF SHM can be monitored further using the following other integrations: |
| 37 | |
| 38 | - [Applications](/src/collectors/apps.plugin/integrations/applications.md) |
| 39 | - [Containers](/src/collectors/cgroups.plugin/integrations/containers.md) |
| 40 | |
| 41 | ### Default Behavior |
| 42 | |
| 43 | #### Auto-Detection |
| 44 | |
| 45 | The plugin checks kernel compilation flags (CONFIG_KPROBES, CONFIG_BPF, CONFIG_BPF_SYSCALL, CONFIG_BPF_JIT) and presence of BTF files to decide which eBPF program will be attached. |
| 46 | |
| 47 | #### Limits |
| 48 | |
| 49 | The default configuration for this integration does not impose any limits on data collection. |
| 50 | |
| 51 | #### Performance Impact |
| 52 | |
| 53 | This thread will add overhead every time that an internal kernel function monitored by this thread is called. The estimated additional period of time is between 90-200ns per call on kernels that do not have BTF technology. |
| 54 | |
| 55 | ## Setup |
| 56 | |
| 57 | |
| 58 | ### Prerequisites |
| 59 | |
| 60 | #### Compile kernel |
| 61 | |
| 62 | Check if your kernel was compiled with necessary options (CONFIG_KPROBES, CONFIG_BPF, CONFIG_BPF_SYSCALL, CONFIG_BPF_JIT) in `/proc/config.gz` or inside /boot/config file. Some cited names can be different accoring preferences of Linux distributions. |
| 63 | When you do not have options set, it is necessary to get the kernel source code from https://kernel.org or a kernel package from your distribution, this last is preferred. The kernel compilation has a well definedd pattern, but distributions can deliver their configuration files |
| 64 | with different names. |
| 65 | |
| 66 | Now follow steps: |
| 67 | 1. Copy the configuration file to /usr/src/linux/.config. |
| 68 | 2. Select the necessary options: make oldconfig |
| 69 | 3. Compile your kernel image: make bzImage |
| 70 | 4. Compile your modules: make modules |
| 71 | 5. Copy your new kernel image for boot loader directory |
| 72 | 6. Install the new modules: make modules_install |
| 73 | 7. Generate an initial ramdisk image (`initrd`) if it is necessary. |
| 74 | 8. Update your boot loader |
| 75 | |
| 76 | |
| 77 | #### Debug Filesystem |
| 78 | |
| 79 | This thread needs to attach a tracepoint to monitor when a process schedule an exit event. To allow this specific feaure, it is necessary to mount `debugfs` (`mount -t debugfs none /sys/kernel/debug/`).` |
| 80 | |
| 81 | |
| 82 | |
| 83 | ### Configuration |
| 84 | |
| 85 | #### Options |
| 86 | |
| 87 | This configuration file have two different sections. The `[global]` overwrites all default options, while `[syscalls]` allow user to select the syscall to monitor. |
| 88 | |
| 89 | |
| 90 | <details open><summary>Config options</summary> |
| 91 | |
| 92 | |
| 93 | |
| 94 | | Option | Description | Default | Required | |
| 95 | |:-----|:------------|:--------|:---------:| |
| 96 | | update every | Data collection frequency. | 10 | no | |
| 97 | | ebpf load mode | Define whether plugin will monitor the call (`entry`) for the functions or it will also monitor the return (`return`). | entry | no | |
| 98 | | apps | Enable or disable integration with apps.plugin | no | no | |
| 99 | | cgroups | Enable or disable integration with cgroup.plugin | no | no | |
| 100 | | pid table size | Number of elements stored inside hash tables used to monitor calls per PID. | 32768 | no | |
| 101 | | ebpf type format | Define the file type to load an eBPF program. Three options are available: `legacy` (Attach only `kprobe`), `co-re` (Plugin tries to use `trampoline` when available), and `auto` (plugin check OS configuration before to load). | auto | no | |
| 102 | | ebpf co-re tracing | Select the attach method used by plugin when `co-re` is defined in previous option. Two options are available: `trampoline` (Option with lowest overhead), and `probe` (the same of legacy code). | trampoline | no | |
| 103 | | maps per core | Define how plugin will load their hash maps. When enabled (`yes`) plugin will load one hash table per core, instead to have centralized information. | yes | no | |
| 104 | | lifetime | Set default lifetime for thread when enabled by cloud. | 300 | no | |
| 105 | | shmget | Enable or disable monitoring for syscall `shmget` | yes | no | |
| 106 | | shmat | Enable or disable monitoring for syscall `shmat` | yes | no | |
| 107 | | shmdt | Enable or disable monitoring for syscall `shmdt` | yes | no | |
| 108 | | shmctl | Enable or disable monitoring for syscall `shmctl` | yes | no | |
| 109 | |
| 110 | |
| 111 | </details> |
| 112 | |
| 113 | |
| 114 | |
| 115 | #### via File |
| 116 | |
| 117 | The configuration file name for this integration is `ebpf.d/shm.conf`. |
| 118 | |
| 119 | The file format is a modified INI syntax. The general structure is: |
| 120 | |
| 121 | ```ini |
| 122 | [section1] |
| 123 | option1 = some value |
| 124 | option2 = some other value |
| 125 | |
| 126 | [section2] |
| 127 | option3 = some third value |
| 128 | ``` |
| 129 | You can edit the configuration file using the [`edit-config`](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#edit-configuration-files) script from the |
| 130 | Netdata [config directory](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#locate-your-config-directory). |
| 131 | |
| 132 | ```bash |
| 133 | cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata |
| 134 | sudo ./edit-config ebpf.d/shm.conf |
| 135 | ``` |
| 136 | |
| 137 | ##### Examples |
| 138 | There are no configuration examples. |
| 139 | |
| 140 | |
| 141 | |
| 142 | ## Alerts |
| 143 | |
| 144 | There are no alerts configured by default for this integration. |
| 145 | |
| 146 | |
| 147 | ## Metrics |
| 148 | |
| 149 | Metrics grouped by *scope*. |
| 150 | |
| 151 | The scope defines the instance that the metric belongs to. An instance is uniquely identified by a set of labels. |
| 152 | |
| 153 | |
| 154 | |
| 155 | ### Per cgroup |
| 156 | |
| 157 | These Metrics show grouped information per cgroup/service. |
| 158 | |
| 159 | This scope has no labels. |
| 160 | |
| 161 | Metrics: |
| 162 | |
| 163 | | Metric | Dimensions | Unit | |
| 164 | |:------|:----------|:----| |
| 165 | | cgroup.shmget | get | calls/s | |
| 166 | | cgroup.shmat | at | calls/s | |
| 167 | | cgroup.shmdt | dt | calls/s | |
| 168 | | cgroup.shmctl | ctl | calls/s | |
| 169 | | services.shmget | a dimension per systemd service | calls/s | |
| 170 | | services.shmat | a dimension per systemd service | calls/s | |
| 171 | | services.shmdt | a dimension per systemd service | calls/s | |
| 172 | | services.shmctl | a dimension per systemd service | calls/s | |
| 173 | |
| 174 | ### Per apps |
| 175 | |
| 176 | These Metrics show grouped information per apps group. |
| 177 | |
| 178 | Labels: |
| 179 | |
| 180 | | Label | Description | |
| 181 | |:-----------|:----------------| |
| 182 | | app_group | The name of the group defined in the configuration. | |
| 183 | |
| 184 | Metrics: |
| 185 | |
| 186 | | Metric | Dimensions | Unit | |
| 187 | |:------|:----------|:----| |
| 188 | | app.ebpf_shmget_call | calls | calls/s | |
| 189 | | app.ebpf_shmat_call | calls | calls/s | |
| 190 | | app.ebpf_shmdt_call | calls | calls/s | |
| 191 | | app.ebpf_shmctl_call | calls | calls/s | |
| 192 | |
| 193 | ### Per eBPF SHM instance |
| 194 | |
| 195 | These Metrics show number of calls for specified syscall. |
| 196 | |
| 197 | This scope has no labels. |
| 198 | |
| 199 | Metrics: |
| 200 | |
| 201 | | Metric | Dimensions | Unit | |
| 202 | |:------|:----------|:----| |
| 203 | | system.shared_memory_calls | get, at, dt, ctl | calls/s | |
| 204 | |
| 205 |