OnCallReadyStart learning

sar: Collect, report, or save system activity information

sar [ -A ] [ -B ] [ -b ] [ -C ] [ -D ] [ -d ] [ -F [ MOUNT ] ] [ -H ] [ -h ] [ -p ] [ -q [ keyword[,...] | ALL ] ] [ -r [ ALL ] ] [ -S ] [ -t ] [ -u [ ALL ] ] [ -V ] [ -v ] [ -W ] [ -w ] [ -y ] [ -z ] [ -I { irq[,...] | ALL } ] [ -P { cpu_list | ALL } ] [ -m { keyword[,...] | ALL } ] [ -n { keyword[,...] | ALL } ] [ -o [ filename ] | -f [ filename ] ] [ -i interval ] [ -s [ hh:mm[:ss] ] ] [ -e [ hh:mm[:ss] ] ] [ interval [ count ] ]

What it does

sar reports almost every system counter, live (with an interval) or from the daily files sadc writes under /var/log/sysstat (saDD) - on Ubuntu the sysstat-collect.timer records every 10 minutes by default. Without an interval it reads today's file.

Options you will use

-u [ ALL ]
CPU utilization (%user %nice %system %iowait %steal %idle).
-q
run queue length and load averages (runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked).
-r
memory (kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit...).
-B
paging (pgpgin/s pgpgout/s fault/s majflt/s...).
-W
swapping (pswpin/s pswpout/s).
-w
task creation and context switches (proc/s cswch/s).
-d
block devices (tps rkB/s wkB/s areq-sz aqu-sz await %util); names are devM-N unless -p.
-p
pretty-print device names (vda, dm-0).
-n DEV
network interfaces: rxpck/s txpck/s rxkB/s txkB/s ... %ifutil.
-f [ filename ]
read a saved file (default today's /var/log/sysstat/saDD).
-s [ hh:mm[:ss] ]
start time of the report (from a file).
-e [ hh:mm[:ss] ]
end time of the report.
-A
all reports.
-V
print version number then exit.
interval [count]
report every INTERVAL seconds, COUNT times (no count = until Ctrl+C). The first report covers the time since boot (iostat: unless -y).

Examples

$ sar -n DEV 1

interface throughput every second

$ sar -n TCP,ETCP 1

TCP connections and retransmits

$ sar -u -s 13:00:00 -e 14:00:00

CPU from today's history, 13:00 to 14:00

$ sar -q -f /var/log/sysstat/sa20

load on the 20th

Gotchas

Taught in

Try sar in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.