Wäre es nicht fantastisch, wenn es ein Tool gäbe, dass wie tcpdump auf System-Ebene arbeitet? Vielleicht noch gemischt mit lsof. Und strace. Und das ganze vielleicht auch so dass man im Nachhinein filtern kann!

Das gibt es. Es nennt sich „sysdig“ und ist OpenSource: http://www.sysdig.org/ bzw. https://github.com/draios/sysdig/

Die Installation auf einem Ubuntu 14.04 sollte eigentlich so funktionieren:

curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bash

Das hat leider nicht ganz geklappt:

curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bash
[sudo] password for tkruse:
* Detecting operating system
* Installing Draios public key
OK
* Installing Draios repository
* Installing kernel headers
E: Package 'linux-headers-3.11.0-12-generic' has no installation candidate
Unable to find kernel development files for the current kernel version 3.11.0-12-generic
This usually means that your system is not up-to-date or you installed a custom kernel version.
The installation will continue but you'll need to install these yourself in order to use sysdig.
Please write to the mailing list at https://groups.google.com/forum/#!forum/sysdig
if you need further assistance.
* Installing Sysdig
Selecting previously unselected package sysdig.
(Reading database ... 207643 files and directories currently installed.)
Preparing to unpack .../sysdig_0.1.82_amd64.deb ...
Unpacking sysdig (0.1.82) ...
Processing triggers for man-db (2.6.7.1-1) ...
Setting up sysdig (0.1.82) ...
Loading new sysdig-0.1.82 DKMS files...
First Installation: checking all kernels...
Building only for 3.11.0-12-generic
Module build for the currently running kernel was skipped since the
kernel source for this kernel does not seem to be installed.

Offenbar war mein Kernel nicht beim Update auf Ubuntu 14.04 mitgezogen worden:

uname -a
Linux charix 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Dafuer gab es keine Kernel-Header mehr, so dass die sysdig Module nicht kompiliert und installiert werden konnten.
Das ist schnell zu beheben, neuer Kernel und neue Header:

sudo apt-get install linux-image-3.13.0-24-generic
sudo dpkg-reconfigure sysdig
Removing old sysdig-0.1.82 DKMS files...

-------- Uninstall Beginning --------
Module: sysdig
Version: 0.1.82
Kernel: 3.13.0-24-generic (x86_64)
-------------------------------------

Status: Before uninstall, this module version was ACTIVE on this kernel.

sysdig-probe.ko:
- Uninstallation
- Deleting from: /lib/modules/3.13.0-24-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.

depmod....

DKMS: uninstall completed.

------------------------------
Deleting module version: 0.1.82
completely from the DKMS tree.
------------------------------
Done.
Loading new sysdig-0.1.82 DKMS files...
Building for 3.11.0-12-generic and 3.13.0-24-generic
Module build for the currently running kernel was skipped since the
kernel source for this kernel does not seem to be installed.
Building initial module for 3.13.0-24-generic
Done.

sysdig-probe:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.13.0-24-generic/updates/dkms/

depmod....

DKMS: install completed.

Danach kann dann sysdig auch schon benutzt werden.
Hier ein Beispiel: „Zeige alle Prozesse, die auf Dateien in /etc zugreifen“

sudo sysdig evt.type=open and fd.name contains /etc

Die Ausgabe sieht z.B. dann so aus:

208208 13:10:12.791863631 0 DNS (4278) < open fd=73(/etc/hosts) name=/etc/hosts flags=1(O_RDONLY) mode=0 
208307 13:10:12.792037164 3 DNS (4283) < open fd=74(/etc/hosts) name=/etc/hosts flags=1(O_RDONLY) mode=0 
444807 13:10:27.793785895 0 DNS (5019) < open fd=72(/etc/hosts) name=/etc/hosts flags=1(O_RDONLY) mode=0 
470806 13:10:32.317263671 1 gnome-settings- (3411) < open fd=19(/etc/fstab) name=/etc/fstab flags=1(O_RDONLY) mode=0 
546476 13:10:42.794281200 2 DNS (4278) < open fd=72(/etc/hosts) name=/etc/hosts flags=1(O_RDONLY) mode=0 

Auch kann man mal eben schnell schauen wer am meisten Netzwerkbandbreite braucht:

sudo sysdig -c topprocs_net

Beispielausgabe:

Bytes     Process   
------------------------------
23.82KB   Socket
546B      dnsmasq
239B      pidgin
215B      DNS

(Socket ist hier der Firefox, der eine Webseite lädt.)

Das ist extrem praktische für diverse Diagnosen. Ein interessantes Beispiel für den Einsatz liefert der Blog-Post der Entwickler, die dabei im Nachhinein analysieren, was bei einem Einbruch in einen Honeypot-Server passierte: http://draios.com/fishing-for-hackers/

Viele weitere Beispiele (IO, CPU, Security…) finden sich auf dieser Seite: https://github.com/draios/sysdig/wiki/Sysdig%20Examples