sysstat es una colección de herramientas de monitoreo de rendimiento para Linux que incluye sar, iostat, mpstat, pidstat y cifsiostat. Estas herramientas recopilan, informan y archivan datos de actividad del sistema para análisis en tiempo real y revisión histórica del rendimiento.
Instalación
Linux/Ubuntu
# Ubuntu/Debian
sudo apt install sysstat
# Enable automatic data collection
sudo systemctl enable sysstat
sudo systemctl start sysstat
# Fedora/RHEL
sudo dnf install sysstat
sudo systemctl enable --now sysstat
# Arch Linux
sudo pacman -S sysstat
# Verify installation
sar -V
Habilitar recopilación de datos
# Edit sysstat config to enable collection
sudo vi /etc/default/sysstat
# Set ENABLED="true"
# Configure collection interval (default: every 10 minutes)
# Collection is handled by /etc/cron.d/sysstat or systemd timers
# Data is stored in /var/log/sysstat/ (or /var/log/sa/)
# Manually trigger a data collection
sudo /usr/lib/sysstat/sa1 1 1
sar — Reportero de actividad del sistema
Uso de CPU
# Current CPU usage (1 second interval, 5 samples)
sar -u 1 5
# CPU usage with ALL fields
sar -u ALL 1 5
# Per-CPU breakdown
sar -P ALL 1 5
# Specific CPU core
sar -P 0 1 5
# CPU usage from today's historical data
sar -u
# CPU usage from a specific day's archive
sar -u -f /var/log/sysstat/sa21
# CPU usage between specific times
sar -u -s 09:00:00 -e 17:00:00
# CPU usage from a specific date file
sar -u -f /var/log/sysstat/sa15 -s 14:00:00 -e 15:00:00
Uso de memoria
# Memory utilization
sar -r 1 5
# Memory with ALL fields
sar -r ALL 1 5
# Swap usage
sar -S 1 5
# Huge pages usage
sar -H 1 5
# Historical memory data
sar -r -f /var/log/sysstat/sa21
E/S de disco
# Disk I/O activity
sar -d 1 5
# Disk I/O with device names (not dev major/minor)
sar -d -p 1 5
# Block device utilization
sar -b 1 5
# Specific device only
sar -d --dev=sda 1 5
# Historical disk data
sar -d -p -f /var/log/sysstat/sa21
Red
# Network interface statistics
sar -n DEV 1 5
# Network errors
sar -n EDEV 1 5
# TCP statistics
sar -n TCP 1 5
# TCP errors
sar -n ETCP 1 5
# Socket statistics
sar -n SOCK 1 5
# All network stats combined
sar -n ALL 1 5
# NFS client statistics
sar -n NFS 1 5
# NFS server statistics
sar -n NFSD 1 5
# IP-level statistics
sar -n IP 1 5
# ICMP statistics
sar -n ICMP 1 5
Otras métricas
# Context switches and interrupts
sar -w 1 5
# Run queue and load average
sar -q 1 5
# Process creation rate
sar -c 1 5
# Paging statistics
sar -B 1 5
# I/O transfer rates
sar -b 1 5
# File systems utilization
sar -F 1 5
# TTY device activity
sar -y 1 5
# Power management
sar -m CPU 1 5
iostat — Estadísticas de E/S
# Basic I/O stats
iostat
# Extended statistics with human-readable units
iostat -xh 1 5
# Extended statistics for all devices
iostat -x 1 5
# Show only specific device
iostat -x sda 1 5
# Include NFS mount statistics
iostat -n
# Show megabytes instead of kilobytes
iostat -m 1 5
# Show partition statistics
iostat -p sda 1 5
# Continuous monitoring every 2 seconds
iostat -x 2
# JSON output
iostat -x -o JSON 1 5
# Omit first (since boot) report
iostat -x -y 1 5
Columnas clave de iostat
# r/s — Read requests per second
# w/s — Write requests per second
# rMB/s — Megabytes read per second
# wMB/s — Megabytes written per second
# rrqm/s — Read requests merged per second
# wrqm/s — Write requests merged per second
# r_await — Average read request latency (ms)
# w_await — Average write request latency (ms)
# aqu-sz — Average queue size
# rareq-sz — Average read request size (KB)
# wareq-sz — Average write request size (KB)
# %util — Percentage of time device was busy
mpstat — Estadísticas multiprocesador
# All CPUs summary
mpstat 1 5
# Per-CPU breakdown
mpstat -P ALL 1 5
# Specific CPU cores
mpstat -P 0,1,2,3 1 5
# Include interrupt statistics
mpstat -I ALL 1 5
# Show only specific interrupt types
mpstat -I CPU 1 5
mpstat -I SCPU 1 5
mpstat -I SUM 1 5
# JSON output
mpstat -P ALL -o JSON 1 5
# Node-level stats (NUMA)
mpstat -N ALL 1 5
pidstat — Estadísticas de procesos
# CPU usage per process
pidstat 1 5
# Memory usage per process
pidstat -r 1 5
# Disk I/O per process
pidstat -d 1 5
# Context switches per process
pidstat -w 1 5
# Threads (show individual threads)
pidstat -t 1 5
# Specific PID
pidstat -p 1234 1 5
# All stats for a specific process
pidstat -u -r -d -w -p 1234 1 5
# Filter by process name
pidstat -C "nginx" 1 5
# Show child process statistics
pidstat -l 1 5
# Stack usage per process
pidstat -s 1 5
# Combined CPU + Memory + I/O for a process
pidstat -urd -p 1234 1 5
cifsiostat — Estadísticas de E/S CIFS
# CIFS filesystem I/O stats
cifsiostat 1 5
# Show in megabytes
cifsiostat -m 1 5
# Include timestamps
cifsiostat -t 1 5
# Skip first (since-boot) report
cifsiostat -y 1 5
Recopilación de datos (sadc/sa1/sa2)
# sadc — System Activity Data Collector (backend)
# Typically called by cron or systemd timers
# Manual data collection (1 sample per second, 10 samples)
sudo /usr/lib/sysstat/sadc 1 10 /var/log/sysstat/sa$(date +%d)
# sa1 — Wrapper for sadc, used in cron
# Collects 1 sample:
sudo /usr/lib/sysstat/sa1 1 1
# sa2 — Generate daily summary report
# Creates sar files from binary data:
sudo /usr/lib/sysstat/sa2 -A
# Typical cron entries (/etc/cron.d/sysstat):
# Collect data every 10 minutes
# */10 * * * * root /usr/lib/sysstat/sa1 1 1
# Generate daily summary at 23:53
# 53 23 * * * root /usr/lib/sysstat/sa2 -A
Análisis histórico
# List available data files
ls -la /var/log/sysstat/
# Read data from a specific day (e.g., the 15th)
sar -u -f /var/log/sysstat/sa15
# Read data for a specific time window
sar -u -f /var/log/sysstat/sa15 -s 08:00:00 -e 12:00:00
# Export historical data as CSV
sadf -d /var/log/sysstat/sa15 -- -u > cpu_history.csv
# Export as JSON
sadf -j /var/log/sysstat/sa15 -- -u > cpu_history.json
# Export as SVG graph
sadf -g /var/log/sysstat/sa15 -- -u > cpu_graph.svg
# Compare data across days
for day in 15 16 17 18 19; do
echo "=== Day $day ==="
sar -u -f /var/log/sysstat/sa$day | tail -1
done
Referencia rápida
| Herramienta | Propósito |
|---|
sar | Reportero de actividad del sistema (CPU, memoria, disco, red) |
iostat | Estadísticas de E/S de disco |
mpstat | Estadísticas por CPU |
pidstat | Estadísticas por proceso |
cifsiostat | E/S del sistema de archivos CIFS |
sadc | Recolector de datos de actividad del sistema (backend) |
sa1 | Wrapper de cron para sadc |
sa2 | Generador de informes diarios |
sadf | Conversor de formato de datos (CSV, JSON, SVG) |
| sar Flag | Métrica |
|---|
-u | Utilización de CPU |
-r | Utilización de memoria |
-S | Utilización de swap |
-d | E/S de disco |
-n DEV | Interfaces de red |
-n TCP | Estadísticas TCP |
-w | Cambios de contexto |
-q | Cola de ejecución / carga promedio |
-B | Estadísticas de paginación |
-b | Tasas de transferencia de E/S |
-F | Utilización del sistema de archivos |