summaryrefslogtreecommitdiffstats
path: root/collectors/ebpf.plugin/README.md
blob: 57934b27aabde01fd51834bda03b7e71a86bb565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
<!--
title: "eBPF monitoring with Netdata"
description: "Use Netdata's extended Berkeley Packet Filter (eBPF) collector to monitor kernel-level metrics about your
complex applications with per-second granularity."
custom_edit_url: https://github.com/netdata/netdata/edit/master/collectors/ebpf.plugin/README.md
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.

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 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.

<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>
</figure>

## Probes and Tracepoints

The following two features from the Linux kernel are used by Netdata to run eBPF programs:

- 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.

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.

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.

## Manually enable the collector on Linux

**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-64.md) for kernels older
than `4.11`, but improved support is in active development.

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.

If your Agent is v1.22 or older, you may to enable the collector yourself. See the [configuration](#configuration)
section for details.

## Charts

The eBPF collector creates charts on different menus, like System Overview, Memory, MD arrays, Disks, Filesystem,
Mount Points, Networking Stack, systemd Services, and Applications.

The collector stores the actual value inside of its process, but charts only show the difference between the values
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
on host. See the [configuration](#configuration) section for details about how to enable them.

#### Processes

Internally, the Linux kernel treats both processes and threads as `tasks`. To create a thread, the kernel offers a few
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`.

#### Process Exit

Ending a task requires two steps. The first is a call to the internal function `do_exit`, which notifies the operating
system that the task is finishing its work. The second step is to release the kernel information with the internal
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.

#### Task error

The functions responsible for ending tasks do not return values, so this chart contains information about failures on
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 ),
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.

#### Soft IRQ

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.

#### 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`

#### IPC shared memory

To monitor shared memory system call counts, the following `kprobes` are used:

- `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 ratio

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.

#### Dirty pages

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

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.

#### Page cache misses

A page cache miss means that a page was not inside memory when the process tried to access it. This chart shows the
result of the difference for calls between functions `add_to_page_cache_lru` and `account_page_dirtied`.

#### File sync

This chart shows calls to synchronization methods, [`fsync(2)`](https://man7.org/linux/man-pages/man2/fdatasync.2.html)
and [`fdatasync(2)`](https://man7.org/linux/man-pages/man2/fdatasync.2.html), to transfer all modified page caches
for the files on disk devices. These calls block until the disk reports that the transfer has been completed. They flush
data for specific file descriptors.

#### Memory map sync

The chart shows calls to [`msync(2)`](https://man7.org/linux/man-pages/man2/msync.2.html) syscalls. This syscall flushes
changes to a file that was mapped into memory using [`mmap(2)`](https://man7.org/linux/man-pages/man2/mmap.2.html).

#### File system sync

This chart monitors calls demonstrating commits from filesystem caches to disk. Netdata attaches `kprobes` 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

This chart shows calls to [`sync_file_range(2)`](https://man7.org/linux/man-pages/man2/sync_file_range.2.html) which
synchronizes file segments with disk.

> Note: This is the most dangerous syscall to synchronize data, according to its manual.

### Multiple Device (MD) arrays

The eBPF plugin shows multi-device flushes happening in real time. This can be used to explain some spikes happening
in [disk latency](#disk) charts.

By default, MD flush is disabled. To enable it, configure your
`/etc/netdata/ebpf.d.conf` file as:

```conf
[global]
    mdflush = yes
```

#### MD flush

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.

### 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:

- [`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.

### 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.

#### ext4

To measure the latency of executing some actions in an
[ext4](https://elixir.bootlin.com/linux/latest/source/fs/ext4) filesystem, the
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.

#### ZFS

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.

#### XFS

To measure the latency of executing some actions in an
[xfs](https://elixir.bootlin.com/linux/latest/source/fs/xfs) filesystem, the
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.

#### NFS

To measure the latency of executing some actions in an
[nfs](https://elixir.bootlin.com/linux/latest/source/fs/nfs) filesystem, the
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.

#### btrfs

To measure the latency of executing some actions in a [btrfs](https://elixir.bootlin.com/linux/latest/source/fs/btrfs/file.c)
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`