This episode optimizes and monitors Samba: tuning aio read size, use sendfile, and NIC bonding for throughput, then monitoring with smbstatus, Prometheus metrics via node_exporter, and log analysis. You learn to measure before tuning and to build a dashboard that tells the file server's health story.

In episode 8 you met the SMB3 performance parameters; episode 20 is its comprehensive production version: measured tuning and continuous monitoring. Two principles govern this episode: measure first, then tune (tuning without measurement is just guessing — we touched on this in episode 8), and monitoring is an extension of debugging (a problem that isn't monitored is never detected early).
Let's continue the large-transfer tuning from episode 8 with full context:
[global]
aio read size = 16384
aio write size = 16384
use sendfile = yes
min receivefile size = 131072
write cache size = 262144
socket options = TCP_NODELAYaio read size/aio write size: the threshold (bytes) at which I/O operations become asynchronous — multiple clients don't block each other on large writes.min receivefile size: files above the threshold are passed through the kernel zero-copy (splice) — the server CPU is barely touched for large transfers.write cache size: per-connection write buffer — helps workloads with many small writes, but RAM consumption rises per connection.use sendfile = yes: send data directly from the page cache to the socket.Why these sizes? The parameters above interact with the filesystem and network. The "right" values depend on your workload — so do A/B benchmarks before and after changing them (episode 8: the dd/fio + iperf3 methodology).
On the network side, two high-impact improvements:
sudo nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=802.3ad,miimon=100"
sudo nmcli connection add type ethernet con-name bond0-p1 ifname eno1 master bond0
sudo nmcli connection up bond0sudo sysctl -w net.core.rmem_max=16777216
sudo sysctl -w net.core.wmem_max=16777216
sudo sysctl -w net.ipv4.tcp_rmem="4096 87380 16777216"
sudo sysctl -w net.ipv4.tcp_wmem="4096 65536 16777216"net.ipv4.tcp_rmem/wmem determine the TCP window — for high RTT (VPN, WAN), large buffers increase throughput. Make sure they're persisted in /etc/sysctl.conf if the results are positive.
Warning
Don't copy all tuning at once and then "pray". Every parameter has side effects: aio adds threads, write cache adds RAM per connection, sendfile sometimes misbehaves on certain filesystems (episode 8). Change one at a time, measure, keep what helps, revert what hurts. Document every decision — undocumented tuning is technical debt.
smbstatus remains the best daily tool for seeing "what's happening right now":
smbstatus -b | head -30
smbstatus -LTo see trends (not snapshots), record to a file and gather statistics:
*/5 * * * * smbstatus -b | awk '/user/ {print $1, $2}' >> /var/log/samba/active-users.logThe logs built in episodes 14-16 give analysis material:
sudo grep -i "NT_STATUS" /var/log/samba/*.log | sort | uniq -c | sort -rn | head
sudo journalctl -u smbd --since today | grep -iE "slow|timeout|denied" | tail -20uniq -c | sort -rn turns raw logs into an error ranking — you immediately see the most frequent errors, not just the most recent.
Prometheus needs an exporter. node_exporter provides host metrics (CPU, RAM, disk, network) with minimal setup:
services:
node-exporter:
image: prom/node-exporter:latest
network_mode: host
restart: unless-stoppedIn Prometheus, the target is auto-discovered via SD files (file_sd_configs) or static_config. Metrics relevant to Samba: node_disk_read_bytes_total, node_network_receive_bytes_total, node_filesystem_avail_bytes — all appear without extra configuration.
For real Samba metrics (session count, active shares), two approaches:
smbstatus periodically, write the output to node_exporter's textfile collector, scraped via node_exporter --collector.textfile:*/5 * * * * smbstatus -b | awk '/^[0-9]+ / {print "samba_active_sessions " $1}' \
> /var/lib/node_exporter/textfile_collector/samba.promaeriscloud/samba_exporter or similar expose metrics over HTTP — make sure to evaluate them before production use.With metrics in Prometheus, build a Grafana dashboard with key panels:
samba_active_sessions) — usage trends.node_disk_read_bytes_total per interval) — spikes indicate load or an attack.node_filesystem_avail_bytes) — alert before it fills (relevant for episode 12's snapshot/retention).log rate via loki/promtail if you use an observability stack).Alerts worth setting: disk < 20%, sessions spiking > 2x baseline, rising auth failures, and smbd down.
Tip
Don't start with 50 alerts — start with the 3 most painful: server down, disk full, and auth failure spikes (episode 15: ransomware signals). Add alerts as you gain experience. Many noisy alerts get ignored; few precise alerts get loved by the team.
write cache size too large: RAM per connection skyrockets; with 500 connections, a 1 MB cache = 500 MB RAM.Key takeaways:
aio, sendfile, write cache, socket options) must be measured with A/B benchmarks.smbstatus for real-time; log analysis (uniq -c | sort -rn) for patterns.smbstatus into the metrics.In episode 21 next, we'll cover roadmap & community — the development direction of AD DC and SMB3, the annual SambaXP conference, and the samba.org ecosystem, mailing lists, wiki, and Software Freedom Conservancy. You'll see Samba's future and how to take part in it!