SAR command in Linux to monitor system performance
sar: System Activity Report
It can be used to monitor Linux system’s resources like CPU usage, Memory utilization, I/O devices consumption, Network monitoring, Disk usage, process and thread allocation, battery performance, Plug and play devices, Processor performance, file system and more.Linux system Monitoring and analyzing aids understanding system resource usage which can help to improve system performance to handle more requests.
By default SAR command displays result on the output screen, in addition result can also be stored in the file specified by the -o filename option.
Any user can collect information about system performance using system activities flags. The SAR command will show only CPU monitoring activity if any flag is not specified by user.
Note: sar may not be installed by default. We need to install sysstat before using it (For example, in Ubuntu, we can install using sudo apt install sysstat). After installing sysstat, we need to make sure that data collection is enabled. (For example, in Ubuntu, we can enable data collection by marking ENABLED=”true” in /etc/default/sysstat)
Syntax : $ sar -[ options ] time_interval number_of_tines_to_display
Examples :
1. To see help
2. To start SAR Service
start sar service [viyadav@vymac]# systemctl start sysstat.service
3. To verify the sar version :
hduser@mahesh-Inspiron-3543:~$ sar -V sysstat version 11.2.0 (C) Sebastien Godard (sysstat orange.fr)
4. To report CPU details total 5 times with the interval of 2 seconds. If the interval command is set to zero, average statistics from the time system started are presented. If the count is not provided and the interval is given, statistics are provided continuously after every interval.
hduser@mahesh-Inspiron-3543:~$ sar -u 2 5 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:00:20 IST CPU %user %nice %system %iowait %steal %idle 04:00:22 IST all 0.25 0.00 0.00 0.00 0.00 99.75 04:00:24 IST all 0.25 0.00 0.13 0.00 0.00 99.62 04:00:26 IST all 0.88 0.00 0.25 1.13 0.00 97.75 04:00:28 IST all 0.00 0.00 0.25 0.13 0.00 99.62 04:00:30 IST all 0.25 0.00 0.38 0.12 0.00 99.25 Average: all 0.33 0.00 0.20 0.28 0.00 99.20
5. To report about the amount of memory used, amount of memory free, available cache, available buffers total 3 times with the interval of 1 second.
hduser@mahesh-Inspiron-3543:~$ sar -r 1 3 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:05:12 IST kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty 04:05:13 IST 6067308 2017252 24.95 62300 853612 4303644 35.89 1308856 525628 60 04:05:14 IST 6067308 2017252 24.95 62300 853612 4303644 35.89 1308856 525628 60 04:05:15 IST 6067308 2017252 24.95 62300 853612 4303644 35.89 1308856 525628 60 Average: 6067308 2017252 24.95 62300 853612 4303644 35.89 1308856 525628 60
6. To report about file systems mounted on the device total 5 times with the interval of 2 seconds.
hduser@mahesh-Inspiron-3543:~$ sar -F 2 5 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:02:38 IST MBfsfree MBfsused %fsused %ufsused Ifree Iused %Iused FILESYSTEM 04:02:40 IST 78181 18727 19.32 24.43 6066698 249334 3.95 /dev/sda11 04:02:40 IST 441 55 11.04 11.04 0 0 0.00 /dev/sda1 04:02:40 IST 2123 1747 45.13 45.13 0 0 0.00 /dev/sdb1 04:02:40 IST 28846 205214 87.68 87.68 29589586 145270 0.49 /dev/sda8
7. To report about block devices details total 3 times with the interval of 1 second.
hduser@mahesh-Inspiron-3543:~$ sar -d 1 3 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:04:34 IST DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util 04:04:35 IST dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 04:04:35 IST dev8-16 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
8. To report run queue length, number of processes and load average
hduser@mahesh-Inspiron-3543:~$ sar -q 2 5 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:01:54 IST runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked 04:01:56 IST 0 491 0.21 0.16 0.15 0 04:01:58 IST 0 491 0.21 0.16 0.15 0 04:02:00 IST 0 491 0.19 0.16 0.15 0 04:02:02 IST 0 491 0.19 0.16 0.15 0 04:02:04 IST 0 491 0.18 0.16 0.14 0 Average: 0 491 0.20 0.16 0.15 0
9. To report cpu usage for given core :
hduser@mahesh-Inspiron-3543:~$ sar -P 1 1 3 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:16:38 IST CPU %user %nice %system %iowait %steal %idle 04:16:39 IST 1 0.00 0.00 0.00 0.00 0.00 100.00 04:16:40 IST 1 0.99 0.00 0.99 0.00 0.00 98.02 04:16:41 IST 1 1.00 0.00 0.00 0.00 0.00 99.00 Average: 1 0.66 0.00 0.33 0.00 0.00 99.00
10. To report about network interface, network speed, IPV4, TCPV4, ICMPV4 network traffic and errors
hduser@mahesh-Inspiron-3543:~$ sar -n DEV 1 3 | egrep -v lo Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:04:00 IST IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil 04:04:01 IST enp0s29u1u2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 04:04:01 IST enp7s0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
11. To report details about the process, kernel thread, i-node, and the file tables
hduser@mahesh-Inspiron-3543:~$ sar -v 1 3 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:25:26 IST dentunusd file-nr inode-nr pty-nr 04:25:27 IST 43219 7584 46874 17 04:25:28 IST 43219 7584 46873 17 04:25:29 IST 43219 7584 46873 17 Average: 43219 7584 46873 17
12. To report messages, semaphores and processes details for all processors and system-wide.
hduser@mahesh-Inspiron-3543:~$ sar -mu -P ALL
13. To report statistics about swapping
hduser@mahesh-Inspiron-3543:~$ sar -S 1 3 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:08:09 IST kbswpfree kbswpused %swpused kbswpcad %swpcad 04:08:10 IST 3906556 0 0.00 0 0.00 04:08:11 IST 3906556 0 0.00 0 0.00 04:08:12 IST 3906556 0 0.00 0 0.00 Average: 3906556 0 0.00 0 0.00
14. To report details about I/O operations like transaction per second, read per second, write per second
hduser@mahesh-Inspiron-3543:~$ sar -b 1 3 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:08:41 IST tps rtps wtps bread/s bwrtn/s 04:08:42 IST 0.00 0.00 0.00 0.00 0.00 04:08:43 IST 2.00 0.00 2.00 0.00 64.00 04:08:44 IST 0.00 0.00 0.00 0.00 0.00 Average: 0.67 0.00 0.67 0.00 21.33
15. To report statistics about context switching, number of processes created per second, number of swap per second
hduser@mahesh-Inspiron-3543:~$ sar -w 1 3 Linux 4.4.0-31-generic (mahesh-Inspiron-3543) Sunday 18 March 2018 _x86_64_ (4 CPU) 04:09:42 IST proc/s cswch/s 04:09:43 IST 0.00 480.00 04:09:44 IST 0.00 637.00 04:09:45 IST 0.00 859.00 Average: 0.00 658.67
16. To report paging statistics (KBs paged-in/sec, KBs paged-out/sec, pagefault/sec etc.)
hatim.lokhandwala@ET-C02PR06MG8:~$ sar -B 2 5 Linux 3.2.0-4-amd64 (ET-C02PR06MG8) 04/26/2019 _x86_64_ (6 CPU) 11:36:32 PM pgpgin/s pgpgout/s fault/s majflt/s pgfree/s pgscank/s pgscand/s pgsteal/s %vmeff 11:36:34 PM 0.00 14.00 13.50 0.00 24.00 0.00 0.00 0.00 0.00 11:36:36 PM 0.00 291.50 6265.50 0.00 1858.00 0.00 0.00 0.00 0.00 11:36:38 PM 0.00 270.00 8.50 0.00 41.00 0.00 0.00 0.00 0.00 11:36:40 PM 0.00 40.50 8.50 0.00 21.00 0.00 0.00 0.00 0.00 11:36:42 PM 0.00 1796.50 8.50 0.00 28.00 0.00 0.00 0.00 0.00 Average: 0.00 482.50 1260.90 0.00 394.40 0.00 0.00 0.00 0.00
Please Login to comment...