Hack 96. Sar Command Examples

    Sar commands comes with the sysstat package. Make sure sysstat is installed. If you don’t have sar installed on your system, get it from Sysstat project.Sar is an excellent monitoring tool that displays performance data of pretty much every resource of the system including CPU, memory, IO, paging, networking, interrupts etc.,Sar Collects, Reports (displays) and Saves the performance data. Let us look at all the three aspects separately

    Sa1 shell-script

    /usr/lib/sa1 in-turn calls the /usr/lib/sadcs. sa1 is invoked from the crontab as shown below. Run this every 5 minutes or 15 minutes depending on your need. I prefer to schedule it for every 5 minutes in the cron tab as shown below.

    1. # 59 23 * * * root /usr/lib/sa/sa2 –A

    Note: /etc/cron.d/sysstat files comes with the sysstat package that includes some default value for the sa1 and sa2, which you can change accordingly.

    Display CPU Statistics using Sar Command

    1. # sar -u -P ALL

    Display networking Statistics using sar command

    1.  
    2. Linux 2.6.9-42.ELsmp (dev-db) 01/01/2009
    3. 12:00:01 AM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/
    4. s rxmcst/s
    5. 12:05:01 AM lo 0.17 0.16 25.31 23.33 0.00 0.0
    6. 0 0.00
    7. 12:10:01 AM eth0 52.92 53.64 10169.74 12178.57 0.00 0.0
    8. 0 0.00
    9.  
    10. # sar -n SOCK |more
    11.  
    12. Linux 2.6.9-42.ELsmp (dev-db) 01/01/2009
    13. 12:00:01 AM totsck tcpsck udpsck rawsck ip-frag
    14. 12:05:01 AM 50 13 3 0 0
    15. 12:10:01 AM 50 13 4 0 0
    16. 12:15:01 AM 53 13 5 0 0