sar Command in Linux

Learn via video courses
Topics Covered

Overview

The sar command is a versatile and powerful performance monitoring tool in Linux. It is used to collect, report, and store system activity information to help diagnose performance issues and identify potential bottlenecks. The command provides an overview of various system resources, such as CPU, memory, I/O, and network utilization.

Linux sar Command Syntax

The syntax for the sar command is as follows:

Where:

  • options: The options are the flags that determine which system resources to monitor.
  • interval: The interval specifies the time duration in seconds between successive reports.
  • count: The count determines the number of reports to display.

sar Command Options:

  • -A: Displays all available statistics.
  • -u: Displays CPU usage statistics.
  • -r: Displays memory usage statistics.
  • -b: Displays I/O and transfer rate statistics.
  • -n: Displays network statistics.

Example Usages

  • Monitor CPU usage every 5 seconds for 3 reports.:

    Output:

    Explanation: The command displays CPU usage statistics every 5 seconds for 3 reports.

  • Monitor memory usage every 10 seconds for 2 reports.:

    Output:

    Explanation: The command displays memory usage statistics every 10 seconds for 2 reports.

Tips

  • Use the -A flag to display all available statistics.

  • The sar command can also read data from a file using the -f option.

Advanced Use Cases of sar Command in Linux

  • Monitor network statistics every 15 seconds for 4 reports.:

    Output:

    Explanation: The command displays network statistics every 15 seconds for 4 reports.

  • Monitor I/O and transfer rate statistics every 20 seconds for 3 reports.:

    Output:

    Explanation: The command displays I/O and transfer rate statistics every 20 seconds for 3 reports.

  • Read and display data from a specific file.:

    Output:

    Explanation: The command reads data from the specified file and displays the corresponding statistics.

Conclusion

  • sar command is a powerful tool for monitoring system performance.

  • It can monitor various system resources, including CPU, memory, I/O, and network.

  • sar allows users to customize the monitoring interval and the number of reports displayed.

  • Advanced usages include reading data from a specific file.