How to Monitor Linux system Performance Using Sar Tool

To Monitor Linux system Performance Using sar Tool

sar is part of sysstat package. sar tool is used to monitor performance of various Linux subsystems. It collects performance data and stores them. This tutorial explains how to monitor the Linux system performance using sar tool.

To check the version of sar

Option &ndash v is used to check the version of sar.

[root@linuxhelp Desktop]# sar -V
sysstat version 9.0.4
(C) Sebastien Godard (sysstat  orange.fr)

To display the total no of processes, queue length and load average of your system

Option -q is used with sar to display the total no of processes, queue length and load average of your system, with some time interval and line counts.

[root@linuxhelp Desktop]# sar -q 2 5
Linux 2.6.32-573.18.1.el6.x86_64 (linuxhelp.com)     04/01/2016     _x86_64_    (1 CPU)
09:43:01 PM   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15
09:43:03 PM         0       294      0.17      0.12      0.10
09:43:05 PM         0       294      0.16      0.12      0.10
09:43:07 PM         1       294      0.16      0.12      0.10
09:43:09 PM         0       294      0.15      0.11      0.10
09:43:11 PM         0       294      0.15      0.11      0.10
Average:            0       294      0.16      0.12      0.10

To view your network statistic

View your network statistic by using &ndash n DEV with some time interval and line counts.

[root@linuxhelp Desktop]# sar -n DEV 1 1 | egrep -v eth0
Linux 2.6.32-573.18.1.el6.x86_64 (linuxhelp.com)     04/01/2016     _x86_64_    (1 CPU)

09:46:19 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
09:46:20 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
09:46:20 PM      eth2      1.01      0.00      0.09      0.00      0.00      0.00      0.00

Average:        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
Average:           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:         eth2      1.01      0.00      0.09      0.00      0.00      0.00      0.00

To know your disk statics of your system

If you want know your disk statics of your system with some time delay and line counts, then use option &ndash d with sar command.

[root@linuxhelp Desktop]# sar -d 1 2
Linux 2.6.32-573.18.1.el6.x86_64 (linuxhelp.com)     04/01/2016     _x86_64_    (1 CPU)

09:47:49 PM       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
09:47:50 PM    dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

09:47:50 PM       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
09:47:51 PM    dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

Average:          DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
Average:       dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

To view your memory statics of your system with some delay and line counts

If you want view your memory statics of your system with some delay and line counts, use option &ndash r with sar command.

[root@linuxhelp Desktop]# sar -r 1 3
Linux 2.6.32-573.18.1.el6.x86_64 (linuxhelp.com)     04/01/2016     _x86_64_    (1 CPU)

09:48:45 PM kbmemfree kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit
09:48:46 PM    152280    860168     84.96      8136    215116   1857336     60.69
09:48:47 PM    152296    860152     84.96      8136    215116   1857336     60.69
09:48:48 PM    152296    860152     84.96      8136    215116   1857336     60.69
Average:          152291    860157     84.96      8136    215116   1857336     60.69

To display only CPU statistic of your system

If you want to display only CPU statistic of your system with some time delay and line counts use option &ndash u with sar command.

[root@linuxhelp Desktop]# sar -u 1 3
Linux 2.6.32-573.18.1.el6.x86_64 (linuxhelp.com)     04/01/2016     _x86_64_    (1 CPU)

09:50:23 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
09:50:24 PM     all      2.04      0.00      4.08      0.00      0.00     93.88
09:50:25 PM     all      4.12      0.00      4.12      0.00      0.00     91.75
09:50:26 PM     all      2.06      0.00      4.12      0.00      0.00     93.81
Average:            all      2.74      0.00      4.11      0.00      0.00     93.15

To check the specific CPU usage of your system

If you want check the specific CPU usage of your system, use &ndash P with your processor name. In the below command, ALL option will list all CPU statistic of your system. Suppose in your machine, if you have three CPU core by default then your first system number starts with 0 and 2nd CPU number is 1 and remaining CPU number followed by the series.

[root@linuxhelp Desktop]# sar -P ALL 1 1
Linux 2.6.32-573.18.1.el6.x86_64 (linuxhelp.com)     04/01/2016     _x86_64_    (1 CPU)

09:52:22 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
09:52:23 PM     all      3.06      0.00      4.08      0.00      0.00     92.86
09:52:23 PM       0      3.06      0.00      4.08      0.00      0.00     92.86

Average:        CPU     %user     %nice   %system   %iowait    %steal     %idle
Average:        all      3.06      0.00      4.08      0.00      0.00     92.86
Average:          0      3.06      0.00      4.08      0.00      0.00     92.86

To check specific CPU statistic

In this command &ndash P stands for device name 1 stands for your CPU number. ‘ 2’ is this time interval and another ‘ 2’ is the time count.

[root@linuxhelp Desktop]#sar -P 1 2 2

To know your swap memory statistic report

If you want know your swap memory statistic report then use option &ndash S it swap memory statistic, suppose in your output “ kbswpfree” and “ swpused” in 0 state means your system is not booting.

[root@linuxhelp Desktop]# sar -S 1 1
Linux 2.6.32-573.18.1.el6.x86_64 (linuxhelp.com)     04/01/2016     _x86_64_    (1 CPU)

09:53:53 PM kbswpfree kbswpused  %swpused  kbswpcad   %swpcad
09:53:54 PM   1917388    130608      6.38     30568     23.40
Average:          1917388    130608      6.38     30568     23.40

To know the input and output statistic of your CPU

If you want to know the input and output statistic of your CPU with some time delay and no of counts, then use option &ndash b.

[root@linuxhelp Desktop]# sar -b 1 2
Linux 2.6.32-573.18.1.el6.x86_64 (linuxhelp.com)     04/01/2016     _x86_64_    (1 CPU)

09:54:58 PM       tps      rtps      wtps   bread/s   bwrtn/s
09:54:59 PM      2.04      0.00      2.04      0.00     89.80
09:55:00 PM      0.00      0.00      0.00      0.00      0.00
Average:            1.02      0.00      1.02      0.00     44.90

Explanation of following field :

tps &ndash Transactions per second (this includes both read and write)
rtps &ndash Read transactions per second
wtps &ndash Write transactions per second
bread/s &ndash Bytes read per second
bwrtn/s &ndash Bytes written per second

To reports the total number of processes created per second

Using -w reports the total number of processes created per second, and total number of context switches per second, with some time delay and line counts.

[root@linuxhelp Desktop]# sar -w 1 3
Linux 2.6.32-573.18.1.el6.x86_64 (linuxhelp.com)     04/01/2016     _x86_64_    (1 CPU)

09:57:57 PM    proc/s   cswch/s
09:57:58 PM      0.00   1313.40
09:57:59 PM      0.00   1471.88
09:58:00 PM      0.00   1424.74
Average:         0.00   1403.10
FAQ
Q
How can I get the "swap" memory usage report using the "sar" command in Linux?
A
You can use the option of "-S" with " sar" command to get the "swap" memory usage report using the "sar" command in Linux. For syntax: "sar -S".
Q
How to display the current date for CPU using the "sar" command in Linux?
A
You can use the option of "-u" with "sar" command to display the current date for CPU using the "sar" command in Linux. For syntax: "sar -u".
Q
How to print the RAM usage report using the "sar" command in Linux?
A
Use the option of "-r" with "sar" command to print the RAM usage report using the "sar" command in Linux. For syntax: "sar -r".
Q
Can you give me the link to get "SAR" package for OpenSUSE?
A
Use the following link to get SAR" package for OpenSUSE as "https://software.opensuse.org/package/sysstat".
Q
How to install "SAR" command in Ubuntu?
A
You can use the command to install "SAR" command in Ubuntu. For syntax: "apt-get install sysstat".