28.6. Keeping Historical Measurements
An incident is easier to diagnose if the system's normal behavior was already
recorded. Two complementary mechanisms cover most needs: sysstat keeps
low-overhead local history, and a metrics exporter makes selected counters
available to a central monitoring system.
28.6.1. Collecting System History with sysstat
Installing sysstat asks, through debconf, whether to activate its monitoring;
the default answer is no. Until /etc/default/sysstat contains
ENABLED="true", the collection units stay disabled and no history is
recorded. A system installed with the default answer can be turned on later.
Check the flag:
$ grep ^ENABLED /etc/default/sysstat
ENABLED="false"
Change it with an in-place edit; sed prints nothing:
$ sudo sed -i 's/^ENABLED=.*/ENABLED="true"/' /etc/default/sysstat
Confirm the change:
$ grep ^ENABLED /etc/default/sysstat
ENABLED="true"
Enable the units. sysstat.service records that the counters restarted and,
through its Also= settings, pulls in the collection, rotation, and summary
timers:
$ sudo systemctl enable --now sysstat
Synchronizing state of sysstat.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable sysstat
Created symlink '/etc/systemd/system/multi-user.target.wants/sysstat.service' → '/usr/lib/systemd/system/sysstat.service'.
Created symlink '/etc/systemd/system/sysstat.service.wants/sysstat-collect.timer' → '/usr/lib/systemd/system/sysstat-collect.timer'.
Created symlink '/etc/systemd/system/sysstat.service.wants/sysstat-summary.timer' → '/usr/lib/systemd/system/sysstat-summary.timer'.
Created symlink '/etc/systemd/system/sysstat.service.wants/sysstat-rotate.timer' → '/usr/lib/systemd/system/sysstat-rotate.timer'.
sysstat-collect.timer then runs every ten minutes, and sysstat-rotate.timer
rolls the daily file at midnight. Collect a sample immediately instead of
waiting for the timer; the command produces no output:
$ sudo systemctl start sysstat-collect.service
Confirm the timers and the daily file:
$ systemctl list-timers 'sysstat*' --no-pager
NEXT LEFT LAST PASSED UNIT ACTIVATES
Tue 2026-11-24 00:50:00 UTC 9min Tue 2026-11-24 00:40:00 UTC 22s ago sysstat-collect.timer sysstat-collect.service
Wed 2026-11-25 00:00:00 UTC 23h Tue 2026-11-24 00:00:22 UTC 40min ago sysstat-rotate.timer sysstat-rotate.service
Wed 2026-11-25 00:07:00 UTC 23h Tue 2026-11-24 00:07:02 UTC 33min ago sysstat-summary.timer sysstat-summary.service
3 timers listed.
Pass --all to see loaded but inactive timers, too.
ls /var/log/sysstat shows files named saDD, where DD is the day of the
month. sar reads the current day's file by default. History from the day of
the incident, including the CPU, memory, and network samples:
$ sar -u
Linux 6.12.86+deb13-amd64 (perf1) 11/24/26 _x86_64_ (2 CPU)
00:00:22 CPU %user %nice %system %iowait %steal %idle
00:02:32 all 2.25 0.00 3.10 28.39 0.96 65.31
00:02:37 all 1.61 0.00 0.80 2.51 0.20 94.87
00:10:00 all 1.86 0.00 1.28 11.26 0.33 85.27
00:18:17 all 14.17 0.00 4.37 23.25 0.84 57.36
00:18:22 all 1.70 0.00 0.50 1.60 0.10 96.09
00:20:03 all 1.47 0.00 1.19 5.16 0.35 91.83
00:30:03 all 1.04 0.00 0.77 5.86 0.24 92.09
00:40:00 all 12.47 0.00 4.82 19.71 0.95 62.05
00:40:06 all 1.28 0.00 1.01 5.32 0.28 92.11
Average: all 6.88 0.00 2.77 15.14 0.60 74.60
Selected output is shown; the file also contains samples taken during the chapter's load tests. The 00:18 and 00:40 samples show user CPU and I/O wait from the exercises, and the average includes them. A real baseline should come from a known quiet period, not from a lab that is intentionally generating load.
Memory history answers whether a leak is gradual; selected output is shown:
$ sar -r
Linux 6.12.86+deb13-amd64 (perf1) 11/24/26 _x86_64_ (2 CPU)
00:00:22 kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
00:02:32 1304792 1669436 167116 8.27 11040 471236 574816 28.44 226124 385452 1844
00:10:00 1284800 1709112 129056 6.39 10412 533356 518152 25.64 342208 291328 1592
00:18:17 1295732 1672220 164948 8.16 13044 481932 562676 27.84 209712 409080 848
00:30:03 1141052 1670464 166600 8.24 15052 632460 556152 27.52 352304 409244 520
00:40:00 1178572 1678076 158264 7.83 13312 604052 567220 28.07 291064 447216 2052
Average: 1235601 1675482 161399 7.99 12725 545316 563570 27.89 274888 404081 1570
kbavail is the useful field for "could a new workload start?"; kbcached
shows how much of the memory is reclaimable cache; %commit tracks committed
address space and can exceed 100 percent because it counts overcommit. Network
history comes from sar -n DEV:
$ sar -n DEV 1 2
Linux 6.12.86+deb13-amd64 (perf1) 11/24/26 _x86_64_ (2 CPU)
00:40:14 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
00:40:15 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
00:40:15 eth0 1.00 1.00 0.06 0.16 0.00 0.00 0.00 0.00
00:40:15 eth1 5.00 5.00 15.56 0.61 0.00 0.00 0.00 0.00
00:40:15 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
00:40:16 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
00:40:16 eth0 2.00 1.00 0.12 0.22 0.00 0.00 0.00 0.00
00:40:16 eth1 1.00 0.00 0.05 0.00 0.00 0.00 0.00 0.00
Selected output is shown. %ifutil is the busiest direction's utilization; it
is a coarse indicator and should not replace the error and drop counters from
Section 28.5.1. sadf can export the binary daily files to a delimited text
format for a spreadsheet or a
long-term archive:
$ sadf -d /var/log/sysstat/sa$(date +%d) -- -u | head -5
# hostname;interval;timestamp;CPU;%user;%nice;%system;%iowait;%steal;%idle
perf1;130;2026-11-24 00:02:32 UTC;-1;2.25;0.00;3.10;28.39;0.96;65.31
perf1;5;2026-11-24 00:02:37 UTC;-1;1.61;0.00;0.80;2.51;0.20;94.87
perf1;443;2026-11-24 00:10:00 UTC;-1;1.86;0.00;1.28;11.26;0.33;85.27
perf1;497;2026-11-24 00:18:17 UTC;-1;14.17;0.00;4.37;23.25;0.84;57.36
The header names the columns; each following line is one interval. Sysstat is intentionally local and low-overhead. It does not alert, does not aggregate across hosts, and its ten-minute default can miss a short incident, so it complements rather than replaces a central metrics system.
28.6.2. Exporting Host Metrics with Prometheus Node Exporter
The Prometheus node exporter exposes kernel and host counters over HTTP. Check that it is running and inspect the series the rest of this section uses:
$ curl -s localhost:9100/metrics | grep -E '^node_(cpu_seconds_total|memory_MemAvailable_bytes|filesystem_avail_bytes|pressure_cpu_waiting_seconds_total)' | head -8
node_cpu_seconds_total{cpu="0",mode="idle"} 6788.31
node_cpu_seconds_total{cpu="0",mode="iowait"} 1389.71
node_cpu_seconds_total{cpu="0",mode="irq"} 0
node_cpu_seconds_total{cpu="0",mode="nice"} 0
node_cpu_seconds_total{cpu="0",mode="softirq"} 8.46
node_cpu_seconds_total{cpu="0",mode="steal"} 46.29
node_cpu_seconds_total{cpu="0",mode="system"} 211.68
node_cpu_seconds_total{cpu="0",mode="user"} 724.42
Each CPU and mode is a separate time series. The values are counters; PromQL
turns them into rates. The exporter does not aggregate, alert, or store history;
Prometheus does that. The Debian package's default filesystem collector
excludes /mnt and /media, which is why a capacity test filesystem is mounted
under /srv in Section 28.7. On perf1, the textfile collector is enabled
separately by setting the package's argument file,
/etc/default/prometheus-node-exporter, to:
ARGS="--collector.textfile.directory=/var/lib/prometheus/node-exporter"
Restart the exporter on perf1 after the change; the restart is silent. It then
reads .prom files from that directory, which is how the backup-freshness
metric in Section 28.7 is supplied.
A concise comparison of the local and central approaches:
| Mechanism | Retention and scope | Strengths | Limitations |
|---|---|---|---|
sysstat |
Local daily binary files, default ten-minute samples | Low overhead, no network, includes many kernel counters | No central query, alerting, or cross-host view |
| Node exporter alone | Current values only | Simple HTTP endpoint, broad host coverage | No storage, query language, or alert evaluation |
| Prometheus + exporters | Central time series with configurable retention | Rate queries, recording rules, alerts, cross-host correlation | Another service to secure and operate; scrape interval sets resolution |
28.6.3. Alerting on Service Symptoms and Capacity Trends
An alert should describe a symptom that requires action, not every counter that
crossed a line. The chapter uses four: a scrape target is down, an external HTTP
probe fails, a filesystem is over 90 percent used, and the last successful
backup is more than an hour old. A fifth rule detects that the monitoring data
itself has disappeared. The rule expressions are in
Section 28.7.2; the important design choice is that each alert has a clear
owner, a threshold that reflects a service expectation, and a for duration
that avoids paging on a single missed scrape.
Capacity trends need a longer window than an instantaneous alert. The recording
rule instance:node_filesystem_usage:ratio stores the used fraction; a graph or
a separate slow-burn alert can compare it over days. A one-minute spike above
90 percent may be a temporary file; a steady climb over six hours is a capacity
problem. Keep the raw node_filesystem_avail_bytes series as well, because the
ratio hides the absolute headroom on a very large filesystem.
28.6.4. Measuring the Effect of a Change and Reverting Regressions
The fio scheduler experiment in Section 28.4.5 is a model for any change:
measure a baseline, change one variable, measure again, and restore the previous
state. The restore step is not optional, and the value to restore must be
recorded before the change is made; in that experiment the active scheduler was
the default none, so none was what the revert wrote back. Writing the old
value back is only half of the restore. The bracket in cat's output marks the
active choice, so read the file again and confirm that the bracket moved:
$ cat /sys/block/vdb/queue/scheduler
[none] mq-deadline
The same discipline applies to a kernel tunable, a cgroup limit, a service configuration, or a network queue. If the change made the symptom worse, revert it before investigating the next hypothesis. If it made the symptom better, repeat the measurement and confirm that the improvement is larger than the run-to-run variation shown in Figure 28.5. A change that is within the noise is not evidence of a fix.