Table of Contents

How to use sar command on Linux

Collect, report, or save system activity information.



sar options

sar -h

# sar -h
Usage: sar [ options ] [ <interval> [ <count> ] ]
Main options and reports:
        -b      I/O and transfer rate statistics
        -B      Paging statistics

        -q      Queue length and load average statistics
        -r      Memory utilization statistics
        -R      Memory statistics
        -S      Swap space utilization statistics
        -W      Swapping statistics

man sar

#man sar

       -h     Display a short help message then exit.

       -B     Report paging statistics.
       -b     Report I/O and transfer rate statistics. 
       -r     Report memory utilization statistics. 
       -q     Report queue length and load averages. 
       -n { keyword [,...] | ALL }
              Report network statistics.
       -W     Report swapping statistics.

       -f [ filename ]
              Extract records from filename 
       -s [ hh:mm:ss ]
              Set the starting time of the data,
       -e [ hh:mm:ss ]
              Set  the ending time of the report.


Example

sar / sar -P ALL (cpu, iowait)

# sar
00:00:01          CPU     %user     %nice   %system   %iowait    %steal     %idle
00:10:01          all      0.03      0.00      0.16      0.02      0.00     99.79
Average:          all      0.03      0.00      0.16      0.02      0.00     99.79

# sar -P ALL
12:50:01          CPU     %user     %nice   %system   %iowait    %steal     %idle
13:00:01          all      0.06      0.00      0.16      1.85      0.00     97.92
13:00:01            0      0.18      0.00      0.23      3.68      0.00     95.92
13:00:01            1      0.03      0.00      0.12      3.72      0.00     96.13
13:00:01            2      0.01      0.00      0.24      0.01      0.00     99.74
13:00:01            3      0.02      0.00      0.07      0.00      0.00     99.91

sar -r (Memory)

-r Report memory and swap space utilization statistics.

#sar -r
00:00:01    kbmemfree kbmemused  %memused kbbuffers  kbcached kbswpfree kbswpused  %swpused  kbswpcad
00:10:01       102260    408284     79.97     22896    311620    514072         0      0.00         0
Average:       102260    408284     79.97     22896    311620    514072         0      0.00         0

sar -q (Loadaverage)

-q Report queue length and load averages.

#sar -q
00:00:01      runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15
00:10:01            1        87      0.00      0.01      0.00
Average:            1        87      0.00      0.01      0.00

sar -n DEV (Network)

#sar -n DEV
00:00:01        IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
00:10:01           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
00:10:01         eth0      0.48      0.35     53.09    114.18      0.00      0.00      0.00
00:10:01         sit0      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:         eth0      0.48      0.35     53.09    114.18      0.00      0.00      0.00
Average:         sit0      0.00      0.00      0.00      0.00      0.00      0.00      0.00

sar -b/-B (I/O)

-b Report I/O and transfer rate statistics.

#sar -b
00:00:01          tps      rtps      wtps   bread/s   bwrtn/s
00:10:01         1.23      0.01      1.22      0.12     16.45
Average:         1.23      0.01      1.22      0.12     16.45



-B Report paging statistics.

#sar -B
00:00:01     pgpgin/s pgpgout/s   fault/s  majflt/s
00:10:01         0.02      2.73     37.11      0.00
Average:         0.02      2.73     37.11      0.00

sar -W (Swap)

-W Report swapping statistics. The following values are displayed:

#sar -W
00:00:01     pswpin/s pswpout/s
00:10:01         0.00      0.00
Average:         0.00      0.00


Tips

Check Date in the past

sar -f /var/log/sa/sa16   <- The 16th

Check Time

sar -s hh:mm:ss -e hh:mm:ss

Example
sar -s 16:20:00 -e 16:50:00

view sar file with Graph

http://ksar.atomique.net/index.html

LANG=C  sar -A -f /var/log/sasa04 > sa04.txt