Home > Package & System Management > sar

sar: System Activity Reporter

The sar (System Activity Reporter) command is used to collect and report various system activity information in real-time, including CPU, memory, disk I/O, and network. It is an essential tool for system performance analysis and troubleshooting.

Overview

sar monitors and records a wide range of performance metrics, such as CPU utilization, memory usage, disk activity, and network traffic. This allows for the identification of system bottlenecks and the analysis of performance trends.

Key Features

  • Real-time system activity monitoring
  • Recording and analysis of historical data
  • Support for various system metrics (CPU, memory, disk, network, etc.)
  • Performance issue diagnosis and capacity planning

Key Options

The sar command provides numerous options for monitoring various system metrics.

Monitoring Metrics

Time and Repetition

Generated command:

Try combining the commands.

Description:

`sar` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Examples of monitoring various system metrics using the sar command.

Monitor CPU Utilization

sar -u 2 5

Reports CPU utilization every 2 seconds, 5 times.

Memory and Swap Usage

sar -r 3 4

Reports memory and swap usage every 3 seconds, 4 times.

Disk I/O Statistics

sar -b 5 3

Reports disk I/O statistics every 5 seconds, 3 times.

Network Device Statistics

sar -n DEV 2 5

Reports network device statistics every 2 seconds, 5 times.

All CPU Cores Utilization

sar -P ALL 1 10

Reports utilization for all CPU cores every 1 second, 10 times.

All System Activity Report for Today

sar -A

Reports all system activity data collected today.

Installation

sar is part of the sysstat package. It may not be installed by default on most Linux distributions, so you need to install it using the following commands.

Debian/Ubuntu

sudo apt update && sudo apt install sysstat

Installs the sysstat package on Debian or Ubuntu-based systems.

CentOS/RHEL/Fedora

sudo yum install sysstat
sudo dnf install sysstat

Installs the sysstat package on CentOS, RHEL, or Fedora-based systems.

After installation, you can enable the sysstat service to allow sar to collect data periodically. (e.g., `sudo systemctl enable sysstat && sudo systemctl start sysstat`)

Tips & Notes

Tips and notes for effectively using sar.

Useful Tips

  • By default, sar stores daily data in the `/var/log/sa/` directory. You can view historical data using the command `sar -f /var/log/sa/saDD` (where DD is the day).
  • sar is very useful not only for real-time monitoring but also for analyzing long-term performance trends by setting it up to collect data periodically via cron.
  • It is important to accurately understand the units and meanings of the output values. For example, `%idle` for CPU represents idle time.

Notes

  • You cannot use the sar command if the sysstat package is not installed.
  • On some systems, sar data collection may be disabled by default. You might need to edit `/etc/default/sysstat` or `/etc/sysconfig/sysstat` to enable it.

Same category commands