The sar command collect, report, or save UNIX / Linux system activity information. It will save selected counters in the operating system to the /var/log/sa/sadd file. From the collected data, you get lots of information about your server:
sar output can be used for identifying server bottlenecks. However, analyzing information provided by sar can be difficult, so use kSar, which can take sar output and plot a nice easy to understand graph over period of time.
The sar, sa1, and sa2 commands are part of sysstat package:
Type the following command:
# yum install sysstat
Sample outputs:
Loaded plugins: downloadonly, fastestmirror, priorities, : protectbase, security Loading mirror speeds from cached hostfile * addons: mirror.cs.vt.edu * base: mirror.ash.fastserv.com * epel: serverbeach1.fedoraproject.org * extras: mirror.cogentco.com * updates: centos.mirror.nac.net 0 packages excluded due to repository protections Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package sysstat.x86_64 0:7.0.2-3.el5 set to be updated --> Finished Dependency Resolution Dependencies Resolved ==================================================================== Package Arch Version Repository Size ==================================================================== Installing: sysstat x86_64 7.0.2-3.el5 base 173 k Transaction Summary ==================================================================== Install 1 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 173 k Is this ok [y/N]: y Downloading Packages: sysstat-7.0.2-3.el5.x86_64.rpm | 173 kB 00:00 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : sysstat 1/1 Installed: sysstat.x86_64 0:7.0.2-3.el5 Complete!
Edit /etc/sysconfig/sysstat file specify how long to keep log files in days, maximum is a month:
# vi /etc/sysconfig/sysstat
Sample outputs:
# keep log for 28 days # the default is 7 HISTORY=28
Save and close the file.
The default cron job is located at /etc/cron.d/sysstat:
# cat /etc/cron.d/sysstat
Sample outputs:
# run system activity accounting tool every 10 minutes */10 * * * * root /usr/lib64/sa/sa1 1 1 # generate a daily summary of process accounting at 23:53 53 23 * * * root /usr/lib64/sa/sa2 -A
Edit /etc/cron.d/sysstat, enter:
# vi /etc/cron.d/sysstat
Update it as follows to log all disk stats (the -d option force to log stats for each block device and the -I option force report statistics for all system interrupts)
# run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib64/sa/sa1 -I -d 1 1
# generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib64/sa/sa2 -A
Save and close the file. Turn on the service, enter:
# chkconfig sysstat on
# service sysstat start
Sample outputs:
Calling the system activity data collector (sadc):
Use the sar command to display output the contents of selected cumulative activity counters in the operating system. In this example, sar is run to get real-time reporting from the command line about CPU utilization:
# sar -u 3 10
Sample outputs:
Linux 2.6.18-164.2.1.el5 (www-03.nixcraft.in) 12/14/2009 09:49:47 PM CPU %user %nice %system %iowait %steal %idle 09:49:50 PM all 5.66 0.00 1.22 0.04 0.00 93.08 09:49:53 PM all 12.29 0.00 1.93 0.04 0.00 85.74 09:49:56 PM all 9.30 0.00 1.61 0.00 0.00 89.10 09:49:59 PM all 10.86 0.00 1.51 0.04 0.00 87.58 09:50:02 PM all 14.21 0.00 3.27 0.04 0.00 82.47 09:50:05 PM all 13.98 0.00 4.04 0.04 0.00 81.93 09:50:08 PM all 6.60 6.89 1.26 0.00 0.00 85.25 09:50:11 PM all 7.25 0.00 1.55 0.04 0.00 91.15 09:50:14 PM all 6.61 0.00 1.09 0.00 0.00 92.31 09:50:17 PM all 5.71 0.00 0.96 0.00 0.00 93.33 Average: all 9.24 0.69 1.84 0.03 0.00 88.20
Where,
To view process creation statistics, enter:
# sar -c 3 10
To view I/O and transfer rate statistics, enter:
# sar -b 3 10
To view paging statistics, enter:
# sar -B 3 10
To view block device statistics, enter:
# sar -d 3 10
To view statistics for all interrupt statistics, enter:
# sar -I XALL 3 10
To view device specific network statistics, enter:
# sar -n DEV 3 10
# sar -n EDEV 3 10
To view CPU specific statistics, enter:
# sar -P ALL
# Only 1st CPU stats
# sar -P 1 3 10
To view queue length and load averages statistics, enter:
# sar -q 3 10
To view memory and swap space utilization statistics, enter:
# sar -r 3 10
# sar -R 3 10
To view status of inode, file and other kernel tables statistics, enter:
# sar -v 3 10
To view system switching activity statistics, enter:
# sar -w 3 10
To view swapping statistics, enter:
# sar -W 3 10
To view statistics for a given process called Apache with PID # 3256, enter:
# sar -x 3256 3 10
sar and sadf provides CLI based output. The output may confuse all new users / sys admin. So you need to use kSar which is a java application that graph your sar data. It also permit to export data to PDF/JPG/PNG/CSV. You can load data from three method : local file, local command execution, and remote command execution via SSH. kSar supports the sar output of the following OS:
Visit the official website and grab the latest source code. Use wget to download the source code, enter:
$ wget http://ksar.atomique.net/kSar/kSar-5.0.6.zip
Use unzip command to extract files, enter:
$ unzip kSar-5.0.6.zip
Make sure JAVA jdk is installed and working correctly. Type the following command to start kSar, run:
$ cd kSar-5.0.6/
$ sh run.sh
Fig.01: kSar welcome screen
Next you will see main kSar window, and menus with two panels.
Fig.02: kSar - the main window
The left one will have a list of graphs available depending on the data kSar has parsed. The right window will show you the graph you have selected.
First, you need to grab sar command statistics. Type the following command to get stats, enter (type it on your server):
[server1 ]# LC_ALL=C sar -A > /tmp/sar.data.txt
# copy file to local desktop
[desktop ]$ scp [email protected]:/tmp/sar.data.txt /tmp
Click on Data > Load data from text file > Select sar.data.txt > Open button.
Now, the graph type tree is deployed in left pane and a graph has been selected:
Fig.03: Processes for server1
Fig.04: Disk stats (blok device) stats for server1
Fig.05: Memory stats for server1
Using the move, you can interactively zoom onto up a part of a graph. To select a zone to zoom, click on the upper left conner and while still holding the mouse but on move to the lower-right of the zone you want to zoom. To come back to unzoomed view click and drag the mouse to any corner location except a lower-right one. You can also right click and select zoom options
I strongly recommend reading sar and sadf command man page:
$ man sar
$ man sadf
kSar graphs can be understood from the sar command man page or by reading its official documentation.
With sar and kSar you get detailed snapshot of memory, CPU and other subsystems. For example, if CPU utilization is more than 80% for a long period of time, a CPU bottleneck is most likely occurring. Using sar -x ALL you can find out CPU eating process. The output of mpstat command (part of sysstat package itself) will also help you understand the cpu utilization. You can easily analyzing this information with kSar.
Performance tuning options for the CPU are as follows:
The isag command graphically displays the system activity data stored in a binary data file by a previous sar run. The isag command invokes sar to extract the data to be plotted. isag has limited set of options as compare to kSar.
Fig.06: isag CPU utilization graphs