RousselTMLEARNING

Article · Observability with eBPF: from discovery to expertise

Troubleshooting with bpftrace and bcc

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 use args->filename instead of args.filename.

2. The bcc tools #

Ready-to-use diagnostics.

Essential tools #

ToolQuestion
execsnoopWhich processes are started (even very short-lived ones)?
opensnoopWhich files are opened, with which errors?
biolatencyWhat is the disk latency (histogram)?
tcplifeWhich TCP connections, how many bytes, for how long?
tcpretransAre there TCP retransmissions?
runqlatHow long do tasks wait for a CPU?
profileWhere 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-bpfcc
Good 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 | head

Useful for understanding what observability agents actually load into a node's kernel.

📄 Diagnosing with bpftrace and the bcc tools →

My progress

  • ⏱ Estimated time : ≈ 5 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

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

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!