Monitoring A System With Sysstat On CentOS

by lifeLinux on November 26, 2010

The Sysstat package contains utilities to monitor system performance and usage activity. Sysstat contains the sar, iostat, mpstat,… utilities, common to many commercial Unixes, and tools you can schedule via cron to collect and historize performance and activity data. In this topic, i’ll explain how to monitor a system with sysstat on CentOS.

Installing Sysstat

yum install sysstat

Start sysstat service

/etc/init.d/sysstat start

Set sysstat service to automatically startup

chkconfig sysstat on

sysstat reports activity

By default, sysstat reports activity every 10 minutes everyday. If you’d like to change that interval, edit it here:

vi /etc/cron.d/sysstat
# run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib/sa/sa1 1 1
# generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib/sa/sa2 -A

iostat command

The iostat command displays the average CPU usage since the last reboot. By default, the command without an option displays the average CPU usage and input/output stats of all the drives and their partitions. Type the following command:

[root@server2 sa]# iostat
Linux 2.6.18-194.17.1.el5 (server2)  11/26/2010

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
0.96    0.00    0.26    0.03    0.00   98.75

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               8.77         1.51       275.43    5272719  960252518
sdb               8.79         1.55       275.43    5413063  960252518
dm-0             34.52         3.06       275.43   10684502  960252518
dm-1              0.00         0.00         0.00       1666      11358
dm-2              2.22         0.05        17.75     180478   61885856
dm-3              0.00         0.00         0.00       1460        136
dm-4             32.29         3.01       257.68   10500418  898355168

If you may also wanted to display the CPU stats after every specific interval say, 5 seconds

[root@server2 sa]# iostat -tc 5
Linux 2.6.18-194.17.1.el5 (server2)  11/26/2010

Time: 11:19:56 AM
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
0.96    0.00    0.26    0.03    0.00   98.75

Time: 11:20:01 AM
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
2.17    0.00    0.57    0.03    0.00   97.22

mpstat command

mpstat command is use to display CPU usage of each CPU individually. By default, mpstat command without option shows the extended output of CPU usage. See bellow:

[root@server2 sa]# mpstat
Linux 2.6.18-194.17.1.el5 (server2)  11/26/2010

11:21:31 AM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
11:21:31 AM  all    0.96    0.00    0.16    0.03    0.04    0.06    0.00   98.75   1107.64

sar command

sar command generates the stats for CPU usage, RAM usage and load average of the server and stores them in a file at regular interval. By default, the command without an option displays CPU stats of the current day, type the following command:

[root@server2 sa]# sar
Linux 2.6.18-194.17.1.el5 (server2)  11/26/2010

12:00:01 AM       CPU     %user     %nice   %system   %iowait    %steal     %idle
12:10:01 AM       all      1.80      0.00      0.35      0.04      0.00     97.81
...

Display data stored in output file pass -f option

[root@server2 sa]# sar -f /var/log/sa/sa10 | more
Linux 2.6.18-194.17.1.el5 (server2)  11/10/2010

12:00:01 AM       CPU     %user     %nice   %system   %iowait    %steal     %idl
e
12:10:01 AM       all      1.02      0.00      0.38      0.04      0.00     98.5
6
...

Display the current CPU usage in specific time interval. The following command generates the output every 5 seconds for 2 times.

[root@server2 sa]# sar -u 5 2
Linux 2.6.18-194.17.1.el5 (server2)  11/26/2010

11:26:42 AM       CPU     %user     %nice   %system   %iowait    %steal     %idle
11:26:47 AM       all      1.52      0.00      0.53      0.05      0.00     97.90
11:26:52 AM       all      3.00      0.00      0.60      0.02      0.00     96.38
Average:          all      2.26      0.00      0.56      0.04      0.00     97.14

Watch CPU activity evolve for 10 minutes and save data

sar -o <path_to_file> 60 10

Related Posts:

{ 1 comment… read it below or add one }

Tim Gurske July 18, 2012 at 7:38 am

This helped me a lot. Thank you for writing it!!!

Reply

Previous post:

Next post: