Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
The sar
(System Activity Reporter) command is a versatile performance monitoring tool available in Linux systems. It collects, reports, and saves system activity information, making it easier to identify performance bottlenecks and analyze system behavior over time. In this tutorial, we'll cover the basics of using the sar
command, including installing the required package, gathering data, and generating reports.
The sar
command is part of the sysstat
package, which may not be installed by default on your Linux distribution. To install it, use your package manager:
For Debian/Ubuntu-based systems:
sudo apt-get update sudo apt-get install sysstat
For RHEL/CentOS-based systems:
sudo yum install sysstat
For openSUSE-based systems:
sudo zypper install sysstat
The sar
command relies on the sysstat
service to collect data at regular intervals. Ensure that the service is enabled and running:
For Debian/Ubuntu-based systems, edit the /etc/default/sysstat
file, changing the ENABLED
setting to "true"
:
ENABLED="true"
Then, restart the sysstat
service:
sudo systemctl restart sysstat
For RHEL/CentOS-based systems, the service should be enabled by default. If needed, you can enable and start it manually:
sudo systemctl enable sysstat sudo systemctl start sysstat
CPU usage:
sar -u
This command displays CPU usage statistics, including the percentage of user CPU time (%user
), system CPU time (%system
), and idle CPU time (%idle
).
Memory usage:
sar -r
This command displays memory usage statistics, such as the amount of used and free memory.
Swap usage:
sar -S
This command displays swap usage statistics, including the amount of used and free swap space.
Disk I/O:
sar -b
This command displays disk I/O statistics, including the number of read and write operations per second.
Network activity:
sar -n DEV
This command displays network activity statistics for each network device, such as the number of received and transmitted packets per second.
By default, the sar
command displays the current day's data. To display historical data, use the -f
option followed by the path to a specific system activity data file. These files are usually located in the /var/log/sa
or /var/log/sysstat
directory and named saDD
, where DD
is the day of the month:
sar -u -f /var/log/sa/sa10
To display statistics at a specific interval (in seconds) and for a specific number of times, use the following syntax:
sar -u 5 10
This command will display CPU usage statistics every 5 seconds for a total of 10 times.
In this tutorial, we've covered the basics of the sar
command in Linux, including installation, data collection, and generating various performance reports. The sar
command is a powerful tool for analyzing system performance and troubleshooting issues. For more information and options, consult the man page by running man sar
.
Collecting and interpreting system statistics with sar
:
sar
(System Activity Reporter) is a command-line utility for collecting and reporting system activity. To collect and display CPU utilization, run:
sar
Setting up and scheduling sar
data collection in Linux:
Install sysstat
package and configure sar
by editing /etc/default/sysstat
. Schedule data collection in /etc/cron.d/sysstat
. Example:
sudo apt-get install sysstat sudo nano /etc/default/sysstat # Set ENABLED="true" sudo systemctl enable sysstat
Interpreting CPU utilization reports with sar
:
Analyze CPU utilization using sar
. Example:
sar -u
Analyzing memory and swap usage using sar
in Linux:
View memory and swap usage with sar
. Example:
sar -r
Storage and disk I/O analysis with sar
command:
Monitor disk I/O with sar
. Example:
sar -b
Advanced options and analysis techniques with sar
in Linux:
Explore advanced options like interval and count, and analyze data over specific time periods. Example:
sar -u 2 5 # Collect CPU utilization every 2 seconds, 5 times