Open In App

SAR command in Linux to monitor system performance

Last Updated : 31 Jul, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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 in understanding system resource usage which can help to improve system performance to handle more requests. 

By default, the SAR command displays the 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 activity flags. The SAR command will show only CPU monitoring activity if any flag is not specified by the user. 

Installation of `sar` in Linux

`sar` may not be installed by default. We need to install `sysstat` before using it 

To install `sar` in Ubuntu

sudo apt install sysstat

To install `sar` in RedHat Linux (9)

Sudo dnf install sysstat

Syntax of `sar` command in Linux

sar -[ options ] time_interval number_of_tines_to_display

Examples and Options

To start `sar` Service 

Syntax:

systemctl start sysstat.service
Starting sar service

Starting sar service

`–help` option in `sar` command

Syntax:

sar --help
361

sar –help

We need to enter the root password for authentication.

To verify the `sar` version

Syntax:

sar -V
version of sar

version of sar

CPU Usage Details

To report CPU details a total of 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. 

Syntax:

sar -u 2 5

CPU Usage Details

CPU Usage Details


Memory Usage Details

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. 

Syntax:

sar -r 1 3

Memory Usage

Memory Usage

File System Details

To report about file systems mounted on the device total 5 times with the interval of 2 seconds. 

Syntax:

sar -F 2 5

File system

File system

Block Device Details

To report about block devices details total 3 times with the interval of 1 second. 

Syntax:

Blocked Device

Blocked Device


Run Queue Length and Load Average

To report run queue length, number of processes and load average 

Syntax:

sar -q 2 5

Run Queue Length and average

Run Queue Length and average


CPU Usage for a Specific Core

To report cpu usage for given core

sar -P 1 1 3

CUP usage for a specific core

CUP usage for a specific core


Network Interface Details

To report about network interface, network speed, IPV4, TCPV4, ICMPV4 network traffic and errors

Syntax:

 sar -n DEV 1 3 | egrep -v lo

Network Interface

Network Interface


Process, Kernel Thread, I-node, and File Table Details

To report details about the process, kernel thread, i-node, and the file tables 

Syntax:

sar -v 1 3

372


Messages, Semaphores, and Process Details

To report messages, semaphores and processes details for all processors and system-wide. 

sar -mu -P ALL

Swapping Statistics

To report statistics about swapping 

Syntax:

sar -S 1 3

Swapping Statistics

Swapping Statistics


I/O Operation Details

To report details about I/O operations like transaction per second, read per second, write per second.

syntax:

sar -b 1 3

375

I/O Operations Details


Context Switching, Process Creation, and Swap Details

To report statistics about context switching, number of processes created per second, number of swap per second .

sar -w 1 3

374

Paging Statistics

To report paging statistics (KBs paged-in/sec, KBs paged-out/sec, pagefault/sec etc.) 

sar -B 2 5

376

Paging Statics

Conclusion

In this article we discussed The SAR (System Activity Report) command in Linux is a powerful tool for monitoring and analyzing system resources. It provides detailed information on CPU usage, memory utilization, I/O devices, network monitoring, disk usage, and more. SAR helps system administrators and developers understand system performance, identify bottlenecks, and optimize resource allocation for improved efficiency and stability. It is an essential tool for managing and optimizing Linux systems.



Previous Article
Next Article

Similar Reads

How to Monitor System Activity in linux | top Command
top command is used to show the Linux processes. It provides a dynamic real-time view of the running system. Usually, this command shows the summary information of the system and the list of processes or threads which are currently managed by the Linux Kernel. As soon as you will run this command it will open an interactive command mode where the t
5 min read
How to Monitor Processor, Memory, Network Performance using dstat in Linux?
Do you want to run a quick performance test on your Linux machine? You may want to check the dstat command. Dstat is a versatile and efficient command that combines the features of several older tools such as vmstat, netstat, iostat, and ifstat to provide useful insights into Linux system performance. You can analyze virtual memory, network connect
2 min read
How use Nmon and "Java Nmon Analyzer" for Monitor Linux Performance
Nmon or Nigel’s Performance Monitor is a tool that is used for the purpose of monitoring resources on Linux, x86_64, Mainframe, etc. With the help of Nmon, you can monitor CPUs, disks, memory, and a couple of other things. There are two modes of Nmon: Online mode: This is used for the purpose of real-time monitoring. Capture mode: In this, the outp
3 min read
Finding System Boot-up Performance Statistics in Linux Using systemd-analyze Command
If your Linux system is taking so much time to boot, and you want to know which process is taking so much time to boot then you are on the right page. We are going to see how to get a complete overview of system boot-up time and which service is taking more time to initialize. We are going to use the systemd-analyze command and subcommands of syste
2 min read
Progress - Tool to monitor progress of basic command in Linux
Progress is a command-line-based tiny tool which is formerly known as a Coreutils Progress Viewer. This tool is written in the C language. This command looks for the Coreutils basic command like cp, mv, dd, tar, gzip, cat, etc. which are currently running on the system and display the percentage of copied data. This tool can also show the estimated
2 min read
How to Monitor Linux Commands Executed by System Users in Real-time?
If you are a Linux system administrator then you would definitely want to monitor the interactive activity of all system users, like monitoring the Linux commands they execute in real-time. In this brief Linux system security article, we will be going to discuss how to monitor all Linux shell commands executed by system users in real-time. Let's se
1 min read
Installing atop Tool To Monitor the System Process in Linux
atop is an ASCII full-screen interactive performance monitor which is kind of similar to the top command to view the load over a Linux system. The job of the most critical hardware resources (from a performance point of view) at the system level, i.e. CPU, memory, disk, and network can be seen. atop enable us to identify which processes are actuall
7 min read
Sysmon – Graphical System Activity Monitor for Linux
Sysmon is a graphical system monitor for Linux. It shows the information about the CPU, GPU, Memory, HDD/SDD and network connections. It is similar to the Windows task manager. It is completely written into the python programming language. Sysmon shows the all information in the form of Graphical visualization. There are some features of these tool
2 min read
Logcheck Tool - Monitor Kali Linux System Log Activity
Logcheck is a package or tool to check system log files for security violations and unusual activity, it utilizes the program called logtail remembering the last position is read from the log file. Analyzes security or unusual activity from syslog to monitor Apache log files for errors caused by PHP Scripts. Logcheck is used to detect problems auto
4 min read
Using htop to Monitor System Processes on Linux
htop a Linux tool that is used in process-managing and terminal-based system monitoring. It allows real-time monitoring of processes and performs every task to monitor the process in the Linux system. The tool is written in the C programming language by Hisham Muhammad. It displays a complete list of processes running on the system and gives inform
5 min read