The Wayback Machine - https://web.archive.org/web/20240922021955/https://www.geeksforgeeks.org/sar-command-linux-monitor-system-performance/
Open In App

SAR command in Linux to monitor system performance

Last Updated : 19 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

SAR command in Linux to monitor system performance – FAQs

What is the SAR command used for in Linux?

The sar (System Activity Report) command in Linux is used for collecting, reporting, and saving system activity information. It is a part of the sysstat package, which provides a set of utilities for performance monitoring. sar is capable of reporting various system loads, such as CPU activity, memory/paging statistics, network, I/O, and more. It’s an invaluable tool for system administrators for historical data tracking or performance analysis, helping to identify bottlenecks and optimizing system performance over time.

How to install the SAR command on my system?

SAR is not installed by default on most Linux systems but can be easily installed as part of the sysstat package. Here’s how you can install it:

On Debian/Ubuntu and derivatives:

sudo apt-get update
sudo apt-get install sysstat

On Red Hat/CentOS and derivatives:

sudo yum install sysstat

On Fedora:

sudo dnf install sysstat

After installation, you may need to enable data collecting for sar by editing its configuration file, usually found at /etc/default/sysstat or /etc/sysconfig/sysstat, and ensure that data collection is enabled (e.g., ENABLED="true").

How to use SAR to monitor CPU usage?

To monitor CPU usage using sar, you can use the following command:

sar -u 1 5

This command tells sar to display CPU usage statistics at 1-second intervals for a total of 5 times. Here’s a breakdown of the options:

  • -u: Reports CPU utilization.
  • The first number after the option (1) specifies the interval in seconds between two measurements.
  • The second number (5) specifies how many results to show.

Each report line shows the CPU usage percentages for user, system, idle, and I/O wait time.

Can SAR be used to check memory usage?

Yes, sar can be used to check memory usage. Use the -r option to display memory utilization statistics:

sar -r 1 5

This command displays memory stats (like kilobytes of used and free memory) every 1 second, repeating 5 times. This is helpful for monitoring how memory usage changes over time, particularly under different load conditions.

What are some common options for the SAR command?

SAR offers a multitude of options that can be tailored for various monitoring purposes. Some common options include:

  • -b: Reports I/O and transfer rate statistics.
  • -n DEV: Provides network statistics. You can specify further with DEV to get detailed reports on specific network devices.
  • -d: Reports activity for each block device, useful for monitoring disk I/O.
  • -p: Makes the device names more readable (pretty).
  • -P ALL: Reports statistics for each processor individually in a multi-core system.
  • -f: Specifies a file from which to retrieve the data. Useful for analyzing historical data, as sar can save data to a file periodically.


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
10 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
How to Monitor System Usage, Outages and Troubleshoot Linux Servers
As we know that Linux is very reliable and a great system administrator should always know the system's behavior and its utilization at every moment of time. So if an administrator or a user wants to monitor its complete system then they have to do the following Storage Space Utilization Linux provides two commands which are used to inspect storage
5 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
Iperf Command to Test Speed, Performance and Bandwidth of Network in Linux
There is a great degree of flex in how the packets are delivered and overall bit rate and packet payload size can be controlled. iperf is a tool that is used to perform network performance measurement and tuning. iperf is an open-source software which is written in C language. Jperf is a GUI version for doing the same job. The core concept work beh
2 min read
Linux Sysstat Utilities For Monitoring System Performance
Sysstat is a useful utility that includes a number of programs for monitoring system resources, performance, and use. The sysstat package contains a number of programs that we all use on a daily basis. It also includes a program that can be used to collect all performance and activity data. Installing Sysstat The Sysstat package is available in the
1 min read
Guider a System Wide Linux Performance Analyzer
Guider is an open-source integrated performance analyzer tool written mostly in Python for Linux operating systems. Most of the functions required for measuring, analyzing, testing, and verifying Linux system performance are provided in Guider. Guider provides most of the features like Monitoring, Profiling, Visualization, control, Logging, Test. I
3 min read
How to use Linux Cockpit to manage system performance
Cockpit is a web-based graphical management tool for Linux machines on your computer. Having Cockpit on your server allows you to manage events on the user interface of a browser. Our typical admin tasks include setting up your firewall, changing your network settings, managing storage, creating accounts, installing containers, updating software, a
5 min read
saidar Utility - Monitor the Linux Box
Saidar is a curses-based (Curses-based software is software whose user interface is implemented through the curses library) tool for viewing system statistics and monitors the Linux system. It is a command-line based tool as it is run on a terminal. To install saidar on Debian based Linux system run the following command on the terminal: sudo apt-g
3 min read
Monitor and Find Statistics for Linux Processes Using pidstat Tool
Pidstat is a command-line tool and part of sysstat suite to monitor the Linux system. It is used to monitor every individual task currently being managed by the Linux kernel on the Linux system. Features of pistat: It can monitor every task running on the systemIt can also monitor the child's task of any task.It shows the total CPU usage by every t
4 min read
Monitor Linux Daemon, Filesystem, CPU, Network and Files Using Monit
Monit is a utility tool for monitoring & managing processes, files, directories, and filesystems on a Unix System. A superpower or a super ability to start a process if it's not running, restart a process if it isn't responding, and stop a process if it uses high resources, that's what Monit(or) does in layman's terms. Monitoring is basically t
3 min read
How to Install and Use bmon Real Time Bandwidth Monitor in Linux?
Bmon Stands is an open source tool for the bandwidth monitoring tool. bmon is a powerful CLI based network bandwidth monitoring and debugging tool for Unix / Linux systems to capture networking related statistics & present them visually on the command line in a human-friendly way. It captures the traffic usage over all the network interfaces on
4 min read
How to Install and Use Scout_Realtime to Monitor Server and Process Metrics in Linux?
There are numerous free tools on Linux that are used to monitor the Linux system including hardware and software. We all may have already come across some command-line Linux performance monitoring tools such as top, htop, atop, etc. Alike that we come across another tool called Scout Realtime tool which is used for server monitoring, that you can s
2 min read
How to Monitor CPU and GPU temperature in Linux
This article will discuss How to Monitor CPU and GPU temperature in Linux. There are several ways to do this here in this article we will discuss a few of them. The utilization of currently running programs or applications has no bearing on the CPU or GPU temperature. Operating sensitive computer parts, such as CPUs, at temperatures over a predeter
4 min read
How to Monitor Linux Server Security with Osquery
An operating system is transformed into a massive database with tables that you may query using SQL-like commands using the open-source security application osquery. With the help of these queries, you can do security audits of the target server, monitor file integrity, and more. You can also examine the firewall's status and settings. It is a cros
3 min read
How to Monitor Access Point Signal Strength with wifi-linux
In today's interconnected world, Wi-Fi has become indispensable for both personal and professional connectivity. However, ensuring a stable and secure Wi-Fi connection requires diligent monitoring of access point signal strength. In this comprehensive guide, we'll explore why monitoring access point signal strength is crucial on Linux systems and h
6 min read
How to Use Glances to Monitor Remote Linux in Web Server Mode?
Glances is a system monitoring tool for Linux machines, it is used to monitor system resources in web server mode or through the web browser. It is an alternative to top and htop monitoring tools. This tool has various features and also provides bits of information on a single screen. Glances is a cross-platform, free and open-source tool for monit
3 min read
Check and Monitor Active GPU in Linux
Monitoring the GPU(Graphics Processing Unit) on a Linux operating system is essential for performance testing, debugging, and ensuring usage. There are many tools for checking and monitoring the GPU activity of various GPUs like Nvidia, AMD, or Intel GPU. This article will teach us about multiple methods to check GPU monitors in the Linux Operating
4 min read
How to Put WiFi Interface into Monitor Mode in Linux?
Before looking into Monitor mode and how to switch your WiFi mode from Managed to Monitor, it’s important to understand how a basic WiFi connection is established. When your system connects to WiFi, it sends packets to the WiFi network, which in turn acknowledges these packets, establishing a connection. Once connected, data packets can be sent to
4 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
How to Mount File System in Linux | mount Command
All files in a Linux filesystem are arranged in form of a big tree rooted at '/'.These files can be spread out on various devices based on your partition table, initially your parent directory is mounted(i.e attached) to this tree at '/', others can be mounted manually using GUI interface(if available) or using mount command. mount command is used
6 min read
How to Manage System Services in Linux | systemctl Command
Linux operating systems are known for their robustness and versatility, and managing system services is a crucial aspect of maintaining a well-functioning system. With the advent of systemd, a system and service manager for Linux operating systems, the systemctl command has become an essential tool for managing services. In this article, we will ex
8 min read