SAR (System Activity Reporter) is a Linux command-line tool that is used to collect, report, and archive system activity information. It is part of the sysstat package, which also includes other tools like mpstat
, iostat
, and pidstat
for monitoring different aspects of a Linux system.
SAR can collect data on various system metrics such as CPU usage, memory usage, network activity, and disk I/O. The data can be collected at regular intervals and can be used to identify performance bottlenecks, track system usage over time, and troubleshoot issues.
SAR uses the data collected by the kernel’s performance counters and the /proc filesystem, and it can be used to generate reports in real-time or for a specific time period in the past. The reports can be displayed on the terminal or saved to a file for later analysis.
Here are some examples of using SAR
- To install SAR utility in server, use the below command
yum install sysstat -y
apt-get install sysstat -y
- To start sysstat service use below command
systemctl start sysstat
systemctl status sysstat
- To get the CPU Utilization of server, RUN below command, by using below command we get CPU utilization for 10 records with an interval of 3 seconds.
sar -u 3 10
- To get the Memory utilization of server, RUN below command, by using below command we get memory utilization for 10 records with an interval of 3 seconds.
sar -r 3 10
- To get the block device read, writes per second and tps, RUN below command, by using below command we get the details of 4 records with an interval of 3 seconds.
sar -d 3 4
- To get the swap utilization, RUN below command, by using below command we get the details of 4 records with an interval of 3 seconds.
sar -S 3 4
- To get context switches and number of processes per second, RUN below command, by using below command we get the details of 4 records with an interval of 3 seconds.
sar -w 3 4
- To get paging statistics, RUN below command, by using below command we get the details of 4 records with an interval of 3 seconds.
sar -B 3 4
- To get process, inode, file, pty statistics, RUN below command, by using below command we get the details of 4 records with an interval of 3 seconds.
sar -v 3 4
file-nr: The number of allocated file handles
pty-nr: The number of currently used pty sessions
dentunused: Number of unused cache entries in the directory cache
- To get the run queue length and load average, RUN below command, by using below command, we get the details of 4 records with an interval of 3 seconds.
sar -q 3 4
- To get the network device statistics, RUN below command, by using below command, we can get the details of 4 records with an interval of 3 seconds.
sar -n DEV 3 4
Note: DEV means Device and you can grep the particular device as per requirement
- To get the statistics of particular CPU core, RUN below commands, by using below command we can get the details of 4 records with an interval of 3 seconds for CPU core 0.
sar -P 0 3 4
sar -P 1 3 4
Note: The second command is for CPU core 1
- To get reads, writes, transactions per second, RUN below command, by using below command we get the details of 4 records with an interval of 3 seconds.
sar -b 3 4
In order to use SAR, the sysstat package must be installed on the system and the sysstat service must be running.