sar

System running status statistics tool

Supplementary instructions

sar command is a system running status statistics tool under Linux. It displays the specified operating system status counter to the standard output device. The sar tool will sample the current status of the system, and then express the current operating status of the system by calculating data and proportions. Its characteristic is that it can continuously sample the system and obtain a large amount of sampling data. Sampling data and analysis results can be saved in files, and the system resources consumed when using it are very small.

grammar

sar(option)(parameter)

Options

-A: Display all report information;
-b: Display I/O rate;
-B: Display page change status;
-c: Display process creation activity;
-d: Display the status of each block device;
-e: Set the end time of display report;
-f: Extract the report from the specified file;
-i: Set the interval for refreshing status information;
-n: Report network statistics.
-P: Report the status of each CPU;
-R: Display memory status;
-u: Display CPU utilization;
-v: Display the status of inodes, files and other kernel tables;
-w: Display swap partition status;
-x: Display the status of the given process.
-r: Display output in paging mode, with a maximum of 100 lines per page.
-o: Output option, specify the columns to be displayed. For example, `-o mrk,prt,cvg` will display CPU usage, process identifier, disk usage, and network traffic.
-t: Timestamp option, specifying to add a timestamp to the output.
-s: Statistics option, specifying the type of statistical data to be displayed. For example, `-s us,ms` will display the average of CPU usage over the us and ms time periods.
-c: option is used to specify the command to be sent. For example, `-c ls` will display a list of files and subdirectories in the current directory.

Parameters

Example

Check memory and swap space usage:

sar -r
Linux 2.4.20-8 (www.jsdig.com) 20130503
12:00:01 AM kbmemfree kbmemused %memused
kbmemshrd kbbuffers kbcached
12:10:00 AM 240468 1048252 81.34
0 133724 485772
12:20:00 AM 240508 1048212 81.34
0 134172 485600
…
08:40:00 PM 934132 354588 27.51
0 26080 185364
Average: 324346 964374 74.83
0 96072 467559

The kbmemfree and kbmemused fields display the unused and used space of memory respectively, followed by the percentage of used space (%memused field). The kbbuffers and kbcached fields display the buffer and system-wide data access amounts respectively, in KB.

Observe system components for 10 minutes and sort the data:

sar -o temp 60 10

**Shows memory and network statistics saved in daily data file "sa16". **

sar -r -n DEV -f /var/log/sa/sa16

View CPU usage:

sar -t

View disk usage:

sar -s disk

View network traffic:

sar -s nic

Send command to system service:

sar -c ls

Display the current timestamp of the system:

sar -t +%s

These are just some examples of sar commands, you can choose different options and parameters according to your specific needs.

Note: The output of the sar command may vary depending on system performance. If you want more accurate results, consider monitoring when your system is performing best.