Operations 9 min read

Master Linux Performance Monitoring with sar: A Complete Guide

This article explains how to use the sar (System Activity Reporter) tool on Linux to collect and analyze performance data, covering past and real‑time statistics, CPU, memory, I/O and swap metrics, installation steps, and a full list of command‑line options.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux Performance Monitoring with sar: A Complete Guide

What Is sar?

sar (System Activity Reporter) samples the current state of a Linux system and reports it as calculated data and ratios. It can continuously sample, store results in files, and has a low overhead, making it one of the most comprehensive performance analysis tools on Linux.

sar can report on 14 major aspects, including file I/O, system calls, serial ports, CPU efficiency, memory usage, process activity, and IPC activity.

Two Main Usage Modes

Retrieve past statistics (default).

Periodically view current data.

Diagnosing Bottlenecks

Combine sar options to pinpoint issues:

CPU bottlenecks: sar -u, sar -q Memory bottlenecks: sar -B, sar -r, sar -W I/O bottlenecks: sar -b, sar -u,

sar -d

Retrieving Past Statistics

By default, sar shows data from 00:00 of the current day. To view older reports, read the saved logs under /var/log/sysstat/ (files named saXX).

Example commands:

sar -f /var/log/sysstat/sa28 | head
sar -r -f /var/log/sysstat/sa28

Viewing CPU Usage

Run: sar -u 1 5 The output columns are: %user – CPU time spent in user mode. %nice – CPU time for processes with a nice value. %system – CPU time spent in kernel mode. %iowait – Time waiting for I/O. %steal – Time stolen by virtual machines. %idle – Idle CPU time.

Viewing Average Load

Run: sar -q This shows the run queue size, process list size, and load averages for 1, 5, and 15 minutes.

runq-sz

– Number of processes waiting to run. plist-sz – Number of processes and threads. ldavg-1 – 1‑minute load average. ldavg-5 – 5‑minute load average. ldavg-15 – 15‑minute load average.

Viewing Memory Usage

Run: sar -r Key fields: kbmemfree – Free memory (similar to free command). kbmemused – Used memory, including buffers and cache. %memused – Physical memory usage percentage. kbbuffers and kbcached – Buffer and cache sizes. kbcommit – Memory needed to avoid overflow (RAM + swap). %commit – Commit ratio relative to total memory (including swap).

Viewing Swap Activity

Run: sar -W Important metrics: pswpin/s – Pages swapped in per second. pswpout/s – Pages swapped out per second.

Installation and Enabling

On some Linux distributions, install the package with: apt-get install sysstat Enable data collection by editing /etc/default/sysstat and setting: ENABLED="true" Start the service:

/etc/init.d/sysstat start

sar Command Options

-A

– Summarize all reports. -a – Report file read/write activity. -B – Report additional cache usage. -b – Report buffer usage. -c – Report system call usage. -d – Report disk usage. -g – Report serial port usage. -h – Report buffer statistics. -m – Report IPC message queues and semaphores. -n – Report network cache usage. -p – Report paging activity. -q – Report run queue and swap queue lengths. -R – Report process activity. -r – Report memory usage. -u – Report CPU utilization. -v – Report process, inode, file, and lock table status. -w – Report system swap activity. -y – Report TTY device activity.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

system-monitoringsysstatMemory UsageCPU usagesarLinux performance
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.