Chapter 28. Monitoring and Performance Diagnosis

Performance work begins with a disagreement between what a service is expected to do and what it is doing. The disagreement may be visible as a slow login, a queue that grows every afternoon, a full filesystem, or a graph that turns red at 03:00. Diagnosis is the discipline of turning that complaint into a measurement, placing the measurement beside a baseline, and following the evidence down through the application, the kernel, and the hardware until one layer accounts for the gap. Monitoring is the discipline of keeping enough history that the baseline exists before the complaint arrives.

This chapter builds both. It starts with the shape of an investigation and the statistics that make a measurement honest. It then works down the stack: CPU and scheduling, memory, storage, and network, with application tracing between them. The last two sections keep the resulting numbers: first with the long-established sysstat tools, then with Prometheus and Alertmanager, which turn a host metric into a notification that someone can act on.

The examples run on two Debian 13 systems:

Role Host eth1 (isolated link) Resources and services
Monitoring host, web backend, CPU, memory, and storage tests perf1 192.168.228.10/24 2 vCPUs, 2 GiB RAM, 2 GiB /dev/vdb test disk, nginx, Prometheus, Alertmanager, blackbox exporter
Network peer, second scrape target, probe target perf2 192.168.228.20/24 1 vCPU, 1 GiB RAM, nginx, node exporter, iperf3 server

Both guests also keep eth0 on the management network 192.168.121.0/24, which carries SSH and package downloads; the exercises use eth1 on the isolated link. The addresses are examples. Sections 28.1 through 28.6 need perf1; Section 28.5 uses perf2 for network paths, and Section 28.7 scrapes both hosts. Building the guests themselves is covered in Chapter 24, and attaching an isolated network in Section 24.3.3.

Chapter 28 monitoring topology

Figure 28.1. The chapter 28 practice hosts. Prometheus, Alertmanager, and the blackbox exporter run on perf1; both hosts export node metrics, and perf2 provides the HTTP probe target and the far end of the network tests. The management network remains separate from every monitored path.

The exercises use these Debian 13 package versions:

$ dpkg-query -W -f='${Package} ${Version}\n' sysstat stress-ng fio linux-perf prometheus prometheus-alertmanager prometheus-node-exporter prometheus-blackbox-exporter nginx-light iperf3
fio 3.39-1
iperf3 3.18-2+deb13u2
linux-perf 6.12.118-1
nginx-light 1.26.3-3+deb13u11
prometheus 2.53.3+ds1-2
prometheus-alertmanager 0.28.1+ds-1
prometheus-blackbox-exporter 0.26.0-1
prometheus-node-exporter 1.9.0-1+b4
stress-ng 0.19.02-1
sysstat 12.7.5-2

Commands entered in john's ordinary shell begin with $; commands entered in a root shell begin with #; the prompt marker is not typed. A single elevated command from john's shell is written $ sudo command. John's account and sudo access are established as described in Chapter 5; when a procedure says "in the root shell", enter sudo -i from john's shell and leave it with exit. Example files belong to john under ~/debian-handbook/performance and ~/debian-handbook/monitoring; the tilde expands to /home/john only in john's own shell, so privileged commands spell the path out. Each console block shows one command followed by its own output. Where output is shortened, the text labels it "selected output."

These are virtual machines on a shared host. Host scheduling appears as steal time, and host I/O and page cache influence storage and network numbers. The measurements below are real observations from that environment, not device benchmarks; the chapter treats them as evidence to be compared against a baseline, which is what a monitoring system does in production. Repeated runs of the same command produce different numbers, especially on a shared host; use the shape of the result and the comparison, not a remembered decimal.

Chapter 3 covers the shell, streams, and exit status; Chapter 8 covers systemd units and the journal; Chapter 9 covers process inspection, cgroups, and the mechanics of the scheduler, memory, and block layer; Chapter 10 covers timers; Chapter 11 through Chapter 13 cover block devices, filesystems, LVM, and encryption; Chapter 17 covers interfaces and routes; Chapter 18 covers nftables; and Chapter 23 covers nginx and TLS. This chapter uses those mechanisms without repeating them.

Create the two workspaces once:

$ mkdir -p ~/debian-handbook/performance ~/debian-handbook/monitoring

The command produces no output when the directories already exist. Install the tools used throughout; on a prepared system apt confirms the versions rather than downloading them.

$ sudo apt install sysstat stress-ng fio linux-perf prometheus prometheus-alertmanager prometheus-node-exporter prometheus-blackbox-exporter nginx-light iperf3 strace dnsmasq bind9-dnsutils curl jq openssl
Reading package lists...
Building dependency tree...
Reading state information...
sysstat is already the newest version (12.7.5-2).
stress-ng is already the newest version (0.19.02-1).
fio is already the newest version (3.39-1).
linux-perf is already the newest version (6.12.118-1).
prometheus is already the newest version (2.53.3+ds1-2).
prometheus-alertmanager is already the newest version (0.28.1+ds-1).
prometheus-node-exporter is already the newest version (1.9.0-1+b4).
prometheus-blackbox-exporter is already the newest version (0.26.0-1).
nginx-light is already the newest version (1.26.3-3+deb13u11).
iperf3 is already the newest version (3.18-2+deb13u2).
strace is already the newest version (6.13+ds-1).
dnsmasq is already the newest version (2.91-1+deb13u2).
bind9-dnsutils is already the newest version (1:9.20.30-1~deb13u1).
curl is already the newest version (8.14.1-2+deb13u7).
jq is already the newest version (1.7.1-6+deb13u4).
openssl is already the newest version (3.5.9-1~deb13u1).
Summary:
  Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 60

apt prints a warning on standard error that its command line is intended for people rather than scripts; the block shows standard output.

In this section