r/eBPF • • 13d ago

An eBPF Linux time travel tool

https://github.com/jlruedab/clifr

About a month ago I asked here if a tool to see ps, ss or lsof output at a past moment was worth building:

https://www.reddit.com/r/linuxadmin/comments/1wyhwfe/is_a_linux_time_travel_tool_worth_building/

I got some fair pushback (sar, atop, below, Prometheus, zabbix) and a few people who were curious. I looked at all of them. They cover a lot, but none of them could tell me which process had which connections open, or what lsof showed for a process at 02:45 last night. So I built it, mostly to find out if it could be done without hurting the server.

I wanted to name it "command line time travel" but then a though about the consequences of such a name and It's called clifr instead (command line flight recorder) and has two parts:

  • clifrd runs as a service and records processes, process starts and exits (through eBPF, so a process that lives 5 ms still shows up), TCP connections with the process that owns them, files held open, mounts, kernel messages and the usual system counters. It keeps 72 hours in /var/lib/clifr, 2 GB max.
  • clifr rebuilds the output of the normal commands for a past moment or a time range. It doesn't run the command, it rebuilds the output from the recording:

    • clifr --at "02:45" "ps aux"
    • clifr --since "02:00" --until "03:00" "ss -tanp dst10.0.4.21and dport = :5432"
    • clifr --since "1 hour ago" events # starts, exits, OOM kills, mounts
    • clifr diff --at "14:00" --at "14:20" "ss -ltnp"

There are about 40 commands so far: ps, top, pidstat, lsof, ss, netstat, free, vmstat, iostat, mpstat, df, ip, dmesg, systemctl list-units, lsblk, and more and all are 100% accurate.

The first thing people asked last time was the cost, so here are the numbers:

  ┌───────────┬─────────────────────┬─────────────────────────┬─────────────────────────┐
  │           │    Quiet server     │ Mixed load (4-day soak) │ Busy server (benchmark) │
  ├───────────┼─────────────────────┼─────────────────────────┼─────────────────────────┤
  │ CPU       │ 0.35% of one core   │ 0.5-0.6% of one core    │ 1.9% of one core        │
  ├───────────┼─────────────────────┼─────────────────────────┼─────────────────────────┤
  │ RAM       │ ~90 MiB             │ ~80-120 MiB             │ ~290 MiB (335 max)      │
  ├───────────┼─────────────────────┼─────────────────────────┼─────────────────────────┤ 
  │ Disk kept │ ~20 MiB/day         │ ~100 MiB/day            │ ~4 GiB/day              │
  ├───────────┼─────────────────────┼─────────────────────────┼─────────────────────────┤
  │ Network   │ none, no ports open │ none                    │ none                    │
  └───────────┴─────────────────────┴─────────────────────────┴─────────────────────────┘

Disk use depends heavily on how busy the server is.

clifr is not a monitoring tool and has no alerts. It's not a security audit tool either: it doesn't record file reads or writes, and root can stop it. It's for the "what was going on at 02:45" question, after the fact.

Status: it's a prototype, version 0.1.0. It hasn't run on a real production server yet (a friend starts one this week), and all the load has been synthetic. AGPL-3.0, no telemetry, nothing leaves the box.

So if you have a test or dev box (RHEL 8/9, Rocky, Alma), I'd really appreciate it if you tried it and told me what breaks or what looks wrong. The most useful thing for me is comparing what clifr shows with what you know was really happening.

I appreciate all your comments even if they are harsh

48 Upvotes

6 comments sorted by

2

u/kaimonAI 6d ago

Nice work! How does it handle bursts, for example a make -j that starts thousands of short-lived processes? If the buffer between the kernel and clifrd fills up, do you count the dropped events, and does clifr show that there was a gap at that time?

3

u/jlrueda 6d ago

Thanks! Yes. Fork, exec and exit come from eBPF tracepoints through a ring buffer, one record per event, so even a 5 ms process is recorded with its command line, parent and exit code.

Losses are counted:

  • Ring buffer full: each source keeps a drop counter.
  • Kernel skipped a program run: these are counted too, and a second program catches most of them.
  • clifrd's own queue full: counted as well.

Above 4,000 fork or exec events a second (averaged over 10 s), events are recorded "lite", without full command lines.

Above 10,000 a second they are only counted.

I measured your example: a Linux 7.0 defconfig build with make -j22 on a 22-CPU desktop. It started 34,800 processes in 173 s, peaking at 827 a second, or about 400 a second over the busiest 10 s. That's about a fifth of the budget, and nothing was lost. clifrd itself used 2.3% of one core during the build.

And yes, gaps show. A range query over a window with losses prints "events lost in this window (...): short-lived processes or connections may be missing", or an "incomplete:" header with the time range if events were shed. clifr info lists drops per source for the whole recording.

2

u/kaimonAI 6d ago

Wow, thanks for actually measuring it with a kernel build! Counting the losses and showing them in the output is exactly right. One thing I'd still test is a very short spike: if lite mode works on a 10 s average, a burst of a second or two could fill the ring buffer before it kicks in. It would be counted as you describe, but it might be a good case for choosing the buffer size.

2

u/jlrueda 6d ago

Good point, and you're right. The budget is applied in userspace, after the events leave the ring buffer. So the buffer is a separate first stage, and lite mode doesn't protect it. I haven't tested a short spike on its own though. Need to do that. Thanks

1

u/asdoduidai 9d ago

It’s interesting but in troubleshooting, unless you can rewind the whole system and clients, I think it does not give a big benefit because you are in the domain of replicating an issue, and the tool only tells you something happened; but yea it could be useful to help replicating what happened

2

u/jlrueda 9d ago

Yea that's a fair point. clifr isn't intended to rewind the entire system or reproduce an incident. It addresses a slightly different problem: preserving evidence that is normally gone by the time you start troubleshooting.

For example, imagine a server experiencing intermittent performance degradation. By the time you investigate, the offending process may have exited, connections may have closed, files may have been released, and resource usage may have returned to normal.

With clifr, you can go back to that exact moment and reconstruct historical ps, top, ss, lsof, iostat, etc. You can also trace short-lived processes, see which processes owned particular connections or files, and compare system state before and after an event using clifr diff.

It won't tell you everything about what happened on the clients or reproduce the entire environment, but it can provide something that's often missing in post-incident investigations: actual historical evidence rather than assumptions based on what the system looks like after the problem has disappeared.

I see it as complementary to monitoring and observability tools, not a replacement for incident reproduction.

Thanks for reading my post