The correction is integrated into the TP (See the green boxes)
What you will learn in this TP
- Run bpftrace
- Write one-liners
- Use the bcc tools
All steps and instructions are shown. Recommended for this lab: guided
Introduction #
Context. A server “crawls” from time to time and the usual metrics do not explain why. You use eBPF to observe in detail what is going on.
Prerequisites: Linux host (VM or physical machine, kernel 5.8+), root access · Estimated time: 40 min
Your first eBPF diagnostics.Hands-on #
Guided steps, with their solutions.
1. Check the kernel
Why? eBPF depends on kernel features: check them first before looking for a problem elsewhere.
Display the kernel version and check that BTF is available.See the correction
uname -r ls -l /sys/kernel/btf/vmlinux2. Run bpftrace
Why? The container avoids installing packages on a production server.
Run bpftrace in a privileged container and list the tracepoints related toopenat.See the correction
alias bt='docker run -ti --rm --privileged --pid=host -v /sys:/sys:ro -v /lib/modules:/lib/modules:ro quay.io/iovisor/bpftrace:latest bpftrace' bt -l 'tracepoint:syscalls:*openat*'3. Who opens which files?
Why? Seeing which files are opened often reveals a configuration file re-read in a loop or a missing file.
Display opened files live, then keep only those of a single process (for examplesshdornginx).See the correction
bt -e 'tracepoint:syscalls:sys_enter_openat { printf("%-16s %s\n", comm, str(args.filename)); }' bt -e 'tracepoint:syscalls:sys_enter_openat /comm == "sshd"/ { printf("%s\n", str(args.filename)); }'4. Count and measure
Why? In-kernel aggregations give a statistical view without flooding the terminal.
Count system calls per process for 10 s, then plot the latency histogram ofvfs_read.See the correction
bt -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); } interval:s:10 { exit(); }' bt -e 'kprobe:vfs_read { @s[tid] = nsecs; } kretprobe:vfs_read /@s[tid]/ { @us = hist((nsecs - @s[tid]) / 1000); delete(@s[tid]); } interval:s:10 { exit(); }'5. The bcc tools
Why? These tools answer the most common questions in a single command.
Installbpfcc-tools, runexecsnoopin one terminal and executefor i in $(seq 5); do date; donein another. Then runbiolatencyduring a file copy.See the correction
sudo apt install -y bpfcc-tools sudo execsnoop-bpfcc sudo biolatency-bpfcc -m 10 1 & dd if=/dev/zero of=/tmp/test bs=1M count=500 oflag=directexecsnoopshows all fivedateruns even though they last only a few milliseconds;biolatencydisplays the distribution of disk write latencies.
Validate your work
Check that each goal above is reached and that you get the result described in the introduction.
Difficulty level : ●●○○○ (2/5)
My progress
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Recommended Articles
eBPF explained: programs in the Linux kernel to observe without instrumenting
What eBPF is, how a program is verified and then run in the kernel, hook points (kprobes, uprobes...
Diagnosing with bpftrace and the bcc tools
Everyday eBPF diagnostic tools: bpftrace one-liners (system calls, files, latencies), bcc tools (...
Processes, memory and performance: monitoring and troubleshooting a Linux server
Understand and control Linux processes (ps, top, signals, nice, jobs), interpret load, memory and...
Backup, monitoring and troubleshooting of a Linux server
Operate a Linux server day to day: 3-2-1 backup strategy with rsync, tar, LVM snapshots and resti...
Linux server security and hardening
Harden a Linux server: least privilege, updates, secure SSH, firewall, fail2ban, SELinux and AppA...
Linux vs Unix: the complete guide to commands and distributions
Understand the differences between Linux and Unix, explore distributions (server, desktop, lightw...
Linux administration best practices
Checklist for administering Linux servers: accounts and sudo, SSH, updates, systemd services, sto...
Linux system architecture: kernel, boot and directory tree
Understand how a Linux server works: kernel and user space, the UEFI, GRUB, initramfs and systemd...
Networking on Linux: configuration, diagnosis, firewall and SSH
Configure and troubleshoot Linux networking: ip, ss, netplan and NetworkManager, DNS, layered dia...