Configure Linux system monitoring with iostat and disk performance analysis

Beginner 25 min Apr 17, 2026 17 views
Ubuntu 24.04 Ubuntu 22.04 Debian 12 AlmaLinux 9 Rocky Linux 9 Fedora 41

Learn to monitor disk I/O performance with iostat from the sysstat package. Set up real-time monitoring, identify bottlenecks, and automate disk performance analysis with systemd timers.

Prerequisites

  • Root or sudo access
  • Basic command line knowledge

What this solves

The iostat command helps you monitor disk I/O performance and identify storage bottlenecks on Linux systems. This tutorial shows you how to install the sysstat package, understand iostat output, and set up automated disk monitoring to catch performance issues before they affect your applications.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions of system monitoring tools.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install sysstat package

The sysstat package contains iostat and other system performance tools. It also includes the sar daemon for historical data collection.

sudo apt install -y sysstat
sudo dnf install -y sysstat

Enable sysstat data collection

Enable the sysstat service to collect historical performance data automatically. This runs the sadc (system activity data collector) every 10 minutes by default.

sudo systemctl enable --now sysstat
sudo sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
sudo systemctl enable --now sysstat

Understanding iostat output and key metrics

Run basic iostat command

Start with a simple iostat command to see current disk activity. This shows average statistics since system boot.

iostat

The output includes CPU utilization and device statistics. Focus on the device section showing disk I/O metrics.

Analyze key iostat metrics

Understanding these metrics helps identify disk bottlenecks and performance issues.

MetricDescriptionGood Values
%utilDevice utilization percentage< 80% for good performance
awaitAverage wait time for I/O requests (ms)< 10ms for SSD, < 20ms for HDD
r/s, w/sRead and write requests per secondDepends on workload and hardware
rkB/s, wkB/sData read/written per second (KB)Monitor against disk specifications
avgrq-szAverage request size in sectorsLarger is generally more efficient
avgqu-szAverage queue length< 2 for most workloads

View extended statistics

Use the -x flag to see extended disk statistics including service time and queue metrics.

iostat -x 1 5

This shows extended stats every 1 second for 5 intervals. Watch for high %util values and long await times.

Monitor disk performance in real-time

Monitor specific devices

Monitor only the devices you care about to reduce noise in the output.

iostat -x 2 sda sdb

This monitors only /dev/sda and /dev/sdb with 2-second intervals. Replace with your actual device names.

Monitor with human-readable output

Use the -h flag to display sizes in human-readable format (K, M, G).

iostat -xh 5

This makes it easier to spot large data transfers and identify which devices are handling the most traffic.

Monitor partition-level statistics

Use the -p flag to see statistics for individual partitions instead of whole devices.

iostat -xp ALL 3

This shows detailed statistics for all partitions, helping identify which specific partitions are experiencing high I/O.

Identify I/O bottlenecks and high disk usage

Identify saturated disks

Look for disks with consistently high utilization that may be causing performance issues.

iostat -x 1 10 | grep -E "Device|%util.*[8-9][0-9]"

This shows devices with utilization above 80%. High %util combined with high await times indicates disk saturation.

Monitor I/O wait times

High I/O wait times indicate processes are waiting for disk operations to complete.

iostat -c 1 5

Watch the %iowait column in CPU statistics. Values consistently above 10% suggest disk I/O is impacting performance.

Analyze top I/O processes

Combine iostat with other tools to identify which processes are generating high disk I/O.

sudo iotop -o -d 1

If iotop isn't installed, you can also use the process monitoring tools covered in our Linux process monitoring tutorial.

Set up automated disk monitoring with systemd timers

Create monitoring script

Create a script that logs disk performance statistics and alerts on high utilization.

#!/bin/bash

Disk monitoring script

LOG_FILE="/var/log/disk-monitor.log" ALERT_THRESHOLD=85 EMAIL="admin@example.com"

Get current disk statistics

DATE=$(date '+%Y-%m-%d %H:%M:%S') STATS=$(iostat -x 1 2 | tail -n +4 | awk 'NF > 0 && !/^avg-cpu/ && !/^$/')

Log all statistics

echo "[$DATE] Disk Statistics:" >> "$LOG_FILE" echo "$STATS" >> "$LOG_FILE" echo "" >> "$LOG_FILE"

Check for high utilization

HIGH_UTIL=$(echo "$STATS" | awk -v threshold="$ALERT_THRESHOLD" '$NF > threshold {print $1 ": " $NF "%"}') if [ -n "$HIGH_UTIL" ]; then echo "[$DATE] ALERT: High disk utilization detected:" >> "$LOG_FILE" echo "$HIGH_UTIL" >> "$LOG_FILE" # Send email alert (requires mail command) if command -v mail >/dev/null 2>&1; then echo "High disk utilization detected on $(hostname) at $DATE: $HIGH_UTIL" | mail -s "Disk Alert - $(hostname)" "$EMAIL" fi fi

Make script executable

Set proper permissions for the monitoring script and create the log directory.

sudo chmod 755 /usr/local/bin/disk-monitor.sh
sudo mkdir -p /var/log
sudo touch /var/log/disk-monitor.log

Create systemd service

Create a systemd service file for the disk monitoring script.

[Unit]
Description=Disk Performance Monitor
Wants=disk-monitor.timer

[Service]
Type=oneshot
ExecStart=/usr/local/bin/disk-monitor.sh
User=root

[Install]
WantedBy=multi-user.target

Create systemd timer

Create a timer to run the disk monitoring every 5 minutes.

[Unit]
Description=Run disk monitor every 5 minutes
Requires=disk-monitor.service

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
Unit=disk-monitor.service

[Install]
WantedBy=timers.target

Enable and start the monitoring

Enable the systemd timer to start disk monitoring automatically.

sudo systemctl daemon-reload
sudo systemctl enable --now disk-monitor.timer
sudo systemctl status disk-monitor.timer

Analyze disk performance patterns and trends

View historical data with sar

Use sar (part of sysstat) to analyze historical disk performance data.

# View yesterday's disk activity
sar -d -f /var/log/sysstat/saXX

View specific time range

sar -d -s 09:00:00 -e 17:00:00

Replace XX with yesterday's date (day of month). This shows patterns in disk usage throughout the day.

Generate performance reports

Create a script to generate daily disk performance summaries.

#!/bin/bash

Generate disk performance report

REPORT_DATE=$(date -d yesterday '+%d') REPORT_FILE="/var/log/disk-report-$(date '+%Y-%m-%d').txt" echo "Disk Performance Report for $(date -d yesterday '+%Y-%m-%d')" > "$REPORT_FILE" echo "=========================================" >> "$REPORT_FILE" echo "" >> "$REPORT_FILE"

Peak utilization times

echo "Peak Disk Utilization:" >> "$REPORT_FILE" sar -d -f /var/log/sysstat/sa$REPORT_DATE | grep -v "^$" | \ awk 'NR>3 && $NF>80 {print $1 " " $2 ": " $(NF-1) " (" $NF "% util)"}' | \ head -10 >> "$REPORT_FILE" echo "" >> "$REPORT_FILE"

Average daily statistics

echo "Average Daily Statistics:" >> "$REPORT_FILE" sar -d -f /var/log/sysstat/sa$REPORT_DATE | grep "Average" >> "$REPORT_FILE" echo "Report generated: $REPORT_FILE"

Set up log rotation

Configure logrotate to manage disk monitoring logs and prevent them from filling up your disk.

/var/log/disk-monitor.log {
    daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
    create 644 root root
    postrotate
        /usr/bin/systemctl reload-or-restart rsyslog > /dev/null 2>&1 || true
    endscript
}

/var/log/disk-report-*.txt {
    weekly
    rotate 12
    compress
    delaycompress
    missingok
    notifempty
}

Verify your setup

Test your disk monitoring configuration to ensure everything is working correctly.

# Check iostat is working
iostat -x 1 2

Verify sysstat service

sudo systemctl status sysstat

Check monitoring timer

sudo systemctl list-timers disk-monitor.timer

Test monitoring script manually

sudo /usr/local/bin/disk-monitor.sh tail -20 /var/log/disk-monitor.log

View historical data

sar -d | head -20

Common issues

SymptomCauseFix
No historical data in sarsysstat not enabled or runningsudo systemctl enable --now sysstat
iostat command not foundsysstat package not installedInstall sysstat package for your distribution
Monitoring script not runningTimer not enabled or service failedCheck sudo systemctl status disk-monitor.timer
High %iowait but low disk %utilNetwork I/O or swap activityCheck network stats and swap usage
Permission denied on log filesIncorrect file ownership or permissionssudo chown root:root /var/log/disk-monitor.log
Email alerts not workingMail command not installedInstall mailx or postfix package
Performance Impact: Running iostat continuously with very short intervals (1 second or less) can impact system performance on busy systems. Use 5-second intervals or longer for production monitoring.

Next steps

Running this in production?

Want this handled for you? Setting this up once is straightforward. Keeping it patched, monitored, backed up and performant across environments is the harder part. See how we run infrastructure like this for European teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed cloud infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.