r/linuxadmin • • 13d ago

Follow-up: I built the "Linux time travel" tool I asked about here. Looking for people to try it

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.

curl -LO https://github.com/jlruedab/clifr/releases/download/v0.1.0/clifrd-0.1.0-1.x86_64.rpm

curl -LO https://github.com/jlruedab/clifr/releases/download/v0.1.0/clifr-0.1.0-1.x86_64.rpm

sudo dnf install ./clifrd-0.1.0-1.x86_64.rpm ./clifr-0.1.0-1.x86_64.rpm

sudo systemctl enable --now clifrd

# wait a few minutes, then:
clifr --at "5 minutes ago" "ps aux"

Repo, with an install guide, a user guide with use cases, and all the benchmark numbers:

https://github.com/jlruedab/clifr

And thanks to everyone who commented on the first post, including the harsh ones. It made this better.

5 Upvotes

2 comments sorted by

2

u/xorian 12d ago

This is a pretty interesting idea. A couple of suggestions I might add to the recording : (1) inter-process signals, to be able to answer "what killed that?" and (2) mount/un-mount events to be able to reconstruct the contents of /proc/mounts at a point in time during the record.

Does this do anything to handle separate mount/process namespaces? Like "ps, but inside that Docker container" or "which container's filesystem view did process X open file Y in"?

2

u/jlrueda 12d ago edited 12d ago

Thanks, glad it's interesting. Taking your points in order:

Signals: only partly. Every exit is recorded with its exit code, or the signal that killed it, so clifr life or clifr events will tell you a process died of SIGKILL or SIGTERM and when. OOM kills are recorded separately with the victim, its RSS and its cgroup (clifr oom). What I don't record is who sent the signal. You get "killed by SIGTERM" but not "PID 4321 sent it", and I agree that's the part you usually want. The kernel has a tracepoint for it (signal_generate), and clifrd already hooks it for something else, so I'll look at adding the sender for fatal signals.

Mounts: that one is already there. Mounts, unmounts and remounts are recorded as they happen (clifrd watches mountinfo for changes), plus a full snapshot every hour. So clifr --at "03:10" findmnt (or mount, or df) shows the table as it was then, and clifr mounts lists the changes over a time range. The limitation is that it's only the host's mount namespace, which brings me to your last question.

Containers and namespaces: some of it.

  • Processes are tied to their container through the cgroup. clifr containers lists the containers seen at a moment, with their Docker, Podman or Kubernetes names. A ps --container filter isn't there yet, but it's next on my list. For now clifr --at T --json "ps aux" includes each process's cgroup, so you can filter with jq, or use systemd-cgls. PIDs are always host PIDs.
  • Network namespaces are handled properly: every connection records its namespace, and clifr ss -tanp -N web1 shows a container's sockets as ss inside it would have.
  • Mount namespaces aren't. I record the host's mount table, not each container's, and an open file's path is stored as the host sees it, without the mount namespace it was opened in. So "which container's filesystem view did X open Y in" you can only infer from which container the process was in. Doing it properly would mean keeping a mount table per namespace, and I haven't tried that yet.

One more caveat on files: open files are sampled every 2 minutes and only kept once they've been seen twice, so a file that's opened briefly won't show up.