#Performance Monitoring

Monitor and analyze system performance to identify bottlenecks and optimize resources.

#📋 Table of Contents


#CPU Monitoring

#top and htop

bash
1# Basic monitoring
2top
3
4# htop for better UI
5htop
6
7# Key metrics:
8# %us - User CPU (application)
9# %sy - System CPU (kernel)
10# %id - Idle
11# %wa - I/O wait
12# Load average: 1min, 5min, 15min

#mpstat

bash
1# Install sysstat package
2sudo apt install sysstat
3
4# CPU stats per core
5mpstat -P ALL 1 5    # All cores, 1 sec interval, 5 times
6
7# Average CPU usage
8mpstat 1 10

#Load Average

bash
1# View load average
2uptime
3cat /proc/loadavg
4
5# Interpretation:
6# Load = 1.0 on 1-core = 100% utilized
7# Load = 4.0 on 4-core = 100% utilized
8# Load > cores = overloaded

#Memory Monitoring

#free Command

bash
1# Human-readable
2free -h
3
4# Output:
5#               total    used    free   shared  buff/cache  available
6# Mem:           16G     4G      2G     500M       10G         11G
7# Swap:          4G      0G      4G
8
9# Key metric: "available" (what can be used)

#vmstat

bash
1# Memory and CPU stats
2vmstat 1 5           # 1 sec interval, 5 times
3
4# Key columns:
5# swpd  - Swap used
6# free  - Free memory
7# buff  - Buffer memory
8# cache - Cache memory
9# si/so - Swap in/out (should be 0)

#Memory Hogs

bash
1# Top memory processes
2ps aux --sort=-%mem | head -10
3
4# Detailed memory per process
5pmap -x PID
6
7# System memory info
8cat /proc/meminfo

#Disk I/O Monitoring

#iostat

bash
1# Disk I/O stats
2iostat -x 1 5
3
4# Key metrics:
5# %util  - Disk utilization (should be < 80%)
6# await  - Average wait time (ms)
7# r/s, w/s - Reads/writes per second

#iotop

bash
1# Real-time I/O per process
2sudo iotop
3
4# Only show active processes
5sudo iotop -o

#df and du

bash
1# Disk space
2df -h
3
4# Directory sizes
5du -sh /var/*
6
7# Find large files
8find / -type f -size +100M -exec ls -lh {} \;

#Network Monitoring

#iftop

bash
# Real-time bandwidth per connection
sudo iftop
sudo iftop -i eth0

#nethogs

bash
# Bandwidth per process
sudo nethogs
sudo nethogs eth0

#ss and netstat

bash
1# Active connections
2ss -tunapl
3
4# Connection summary
5ss -s
6
7# Listening ports
8ss -tuln

#sar (Network)

bash
# Network stats over time
sar -n DEV 1 5

#Comprehensive Tools

#glances

bash
1# Install
2pip install glances
3
4# Run
5glances
6
7# Web mode
8glances -w

#dstat

bash
1# All-in-one monitoring
2dstat
3
4# Custom columns
5dstat -cdnm 1

#nmon

bash
1# Interactive monitoring
2nmon
3
4# Keys: c=CPU, m=Memory, d=Disk, n=Network

#Performance Checklist

MetricWarningCritical
CPU Usage> 70%> 90%
Load Average> cores> 2x cores
Memory Used> 80%> 95%
Swap Used> 0> 50%
Disk Space> 80%> 95%
Disk I/O Wait> 20%> 50%

#Summary

ResourceCommand
CPUtop / htop / mpstat
Memoryfree -h / vmstat
Disk I/Oiostat / iotop
Disk Spacedf -h / du -sh
Networkiftop / nethogs
All-in-oneglances / dstat

[!TIP] Pro Tip: Set up monitoring dashboards with Prometheus + Grafana for long-term performance analysis!