1. bpftrace #
A scripting language for eBPF.
Running bpftrace #
# Paquet de la distribution
sudo apt install bpftrace
# ou conteneur privilégié
docker run -ti --rm --privileged --pid=host \
-v /sys:/sys:ro -v /lib/modules:/lib/modules:ro \
quay.io/iovisor/bpftrace:latest bpftrace -l 'tracepoint:syscalls:*open*'A bpftrace script combines a probe, an optional filter and an action: probe /filter/ { action }.
Useful one-liners #
# Quels fichiers sont ouverts, et par qui ?
bpftrace -e 'tracepoint:syscalls:sys_enter_openat { printf("%s %s\n", comm, str(args.filename)); }'
# Appels système par processus (Ctrl+C pour afficher)
bpftrace -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); }'
# Histogramme de la taille des lectures
bpftrace -e 'tracepoint:syscalls:sys_exit_read /args.ret > 0/ { @bytes = hist(args.ret); }'
# Latence de vfs_read par processus
bpftrace -e 'kprobe:vfs_read { @s[tid] = nsecs; }
kretprobe:vfs_read /@s[tid]/ { @us[comm] = hist((nsecs - @s[tid]) / 1000); delete(@s[tid]); }'
# Nouveaux processus lancés
bpftrace -e 'tracepoint:sched:sched_process_exec { printf("%d %s\n", pid, str(args.filename)); }'Good to know: Older versions of bpftrace useargs->filenameinstead ofargs.filename.
2. The bcc tools #
Ready-to-use diagnostics.
Essential tools #
| Tool | Question |
|---|---|
execsnoop | Which processes are started (even very short-lived ones)? |
opensnoop | Which files are opened, with which errors? |
biolatency | What is the disk latency (histogram)? |
tcplife | Which TCP connections, how many bytes, for how long? |
tcpretrans | Are there TCP retransmissions? |
runqlat | How long do tasks wait for a CPU? |
profile | Where did CPU time go (call stacks)? |
sudo apt install bpfcc-tools # outils suffixés -bpfcc sur Debian/Ubuntu
sudo execsnoop-bpfcc
sudo biolatency-bpfcc -m 10 1 # histogramme en ms, 1 fois, 10 s
sudo tcplife-bpfccGood practice: The USE method (Utilization, Saturation, Errors) applied with these tools lets you qualify a performance problem on a server in a few minutes.
3. bpftool #
Inspecting what is running.
Commands #
sudo bpftool prog list # programmes eBPF chargés (par Cilium, Beyla, systemd...)
sudo bpftool map list # maps
sudo bpftool prog show id 42 --pretty
sudo bpftool feature probe kernel | headUseful for understanding what observability agents actually load into a node's kernel.
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...
eBPF best practices for observability
Checklist for adopting eBPF in observability: choosing tools, gradual rollout, agent security, co...
Observing the Kubernetes network with Cilium Hubble
Make a Kubernetes cluster's network flows visible with Cilium Hubble: architecture, the hubble ob...
Zero-code instrumentation with Grafana Beyla (OpenTelemetry eBPF Instrumentation)
Get RED metrics and HTTP/gRPC traces from any application without changing it: Grafana Beyla and ...
eBPF in production: security, prerequisites and limits
What to know before deploying eBPF agents: privileges and capabilities, kernel versions, managed ...
Continuous profiling with eBPF: Parca, Pyroscope and the OpenTelemetry profiler
Continuously profile every process on a host with eBPF: principle, Parca and parca-agent, Pyrosco...
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...
Instrumenting applications for Pyroscope: SDKs, Alloy and eBPF
Send profiles to Pyroscope from Go, Java, Python and Node.js with the SDKs, collect pprof endpoin...