What is sar?
sar(system activity report) is a command which comes along with the sysstat tool. sar is one of the very useful commands for a system administrator to monitor the server statistics link CPU load average, memory usage, I/O wait, etc.
Install and Configure
Installing sysstat is pretty simple and is in the repositories for most Linux distributions.
#apt-get install sysstat
#yum install sysstat
# cat /etc/sysconfig/sysstat
sysstat-9.0.4 configuration file.
How long to keep log files (in days).
If value is greater than 28, then log files are kept in
multiple directories, one for each month.
In the above output to can the change the values like HISTORY=7, the number of days to keep the log files. Based on your requirement you can change the value, but ensure that you have enough disk space to store the logs for n number of days.
Syntax of sar command
sar [option] [-o filename] [-f filename] [interval] [count]
To the CUP utilization using run the below command. The option ‘u’ is used to get the CPU details. Where 2 denote the output refresh time and 3 denoted the number of times. The below command shows the real-time data.
#sar -u 2 3
# sar -u 2 3
02:48:59 AM CPU %user %nice %system %iowait %steal %idle
02:49:01 AM all 6.33 0.00 0.66 3.89 0.00 89.13
02:49:03 AM all 3.70 0.00 0.67 3.61 0.00 92.02
02:49:05 AM all 4.00 0.00 0.80 4.12 0.00 91.08
Average: all 4.68 0.00 0.71 3.87 0.00 90.74
%user denotes the percentage of CPU utilization that occurred while executing at the user level (application) and %system denotes the percentage of CPU utilization that occurred while executing at the system level (kernel). %idle is the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. If you need to review the past(yesterday) server statics report, user the option ‘f’.
#sar -u -f /var/log/sa/sa06
Find Memory usage -r
#sar -r 2 3
# sar -r 2 3
03:02:42 AM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit
03:02:44 AM 43426984 22429040 34.06 49644 11308956 9895104 7.47
03:02:46 AM 43298784 22557240 34.25 49788 11432940 9895108 7.47
03:02:48 AM 43151052 22704972 34.48 49960 11580772 9895108 7.47
Average: 43292273 22563751 34.26 49797 11440889 9895107 7.47
Kbmemfree shows the amount of free memory available in kilobytes and kbmemused shows the amount of used memory in kilobytes.
Find network statistics using ‘-n DEV‘.
#sar -n DEV 1 3
Find load averages over time ‘-q’
#sar -q 2 3
runq-sz : It showsrRun queue length (number of tasks waiting for run time).
plist-sz : It shows the number of tasks in the task list.
ldavg-1/5/15 : System load average for the last minute/ pst 5 minutes/past 15 minutes.