- Using sar command
we can get many important stats from the server like CPU usage, memory usage,
swap, IO, disk IO, network, paging etc.
- Not only we can get the current
statistics but also stats for previous date from the sar log files (/var/log/sa/),
remember by default sar stores only latest 7 days data into "/var/log/sa/sa1-31"
files. (1-31 for months dates)
- We can make sar to keep logs for
more days by editing "/etc/sysconfig/sysstat" file and
specifying "HISTORY" attribute.
- I have covered almost all the sar
command options here.
1. Installing sar command
- To install sar command, you need to have "sysstat" package.
# yum install sysstat
# rpm -ivh sysstat-2.3.4
- To configure the sar to retain logs of more than default 7 days.
# vi /etc/sysconfig/sysstat
Change the "HISTORY" parameter
|
2. CPU usage
- To get current CPU usage
# sar 2 10
# sar -p 2 10
# sar -P ALL 2 10
- To get the CPU usage for previous date, consider 14th
# sar -P ALL -f /var/log/sa/sa14
- To get the CPU usage for 10th of month, from 7 AM to 3 PM (i.e. with specifying the time)
# sar -P ALL -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
|
- To get current memory usage
# sar -r 2 10
- To get memory usage for previous date, consider 14th
# sar -r -f /var/log/sa/sa14
- To get memory usage for the 10th of month, from 7 AM to 3 PM (i.e. with specifying the time)
# sar -r -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
|
4. Swap usage
- To get current swap usage
# sar -S 2 10
- To get swap usage for previous date, consider 14th
# sar -S -f /var/log/sa/sa14
- To get swap usage for the 10th of month, from 7 AM to 3 PM
# sar -S -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
kbswpfree - Swap free in KB kbswpused - Swap used in KB %swpused - Percentage of swap used kbswpcad - Amount of cached swap memory in kilobytes %swpcad - Percentage of cached swap memory |
- To get current load average stats
# sar -q 2 10
- To get load average stats for previous date, consider 14th
# sar -q -f /var/log/sa/sa14
- To get load average stats for the 10th of month, from 7 AM to 3 PM
# sar -q -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
runq-sz - number of tasks waiting for run time plist-sz - Number of tasks in the task list ldavg-1 - load average for the last minute ldavg-5 - load average for the last 5 minute ldavg-15 - load average for the last 15 minute |
- To get current paging usage
# sar -B 2 10
- To get paging usage for previous date, consider 14th
# sar -B -f /var/log/sa/sa14
- To get paging usage for the 10th of month, from 7 AM to 3 PM
# sar -B -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
pgpgin/s - Total number of kilobytes the system paged in from disk per second pgpgout/s - Total number of kilobytes the system paged out to disk per second fault/s - Number of page faults majflt/s - Number of major faults the system has made per second pgfree/s - Number of pages placed on the free list by the system per second pgscank/s - Number of pages scanned by the kswapd daemon per second pgscand/s - Number of pages scanned directly per second pgsteal/s - Number of pages the system has reclaimed from cache %vmeff - Efficiency of page reclaim |
- To get current IO usage
# sar -b 2 10
- To get IO usage for previous date, consider 14th
# sar -b -f /var/log/sa/sa14
- To get IO usage for the 10th of month, from 7 AM to 3 PM
# sar -b -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
|
- To get current disk IO usage
# sar -d -p 2 10
- To get disk IO usage for previous date, consider 14th
# sar -d -p -f /var/log/sa/sa14
- To get disk IO usage for the 10th of month, from 7 AM to 3 PM
# sar -d -p -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
rd_sec/s - Number of sectors read from the device wr_sec/s - Number of sectors written to the device avgrq-sz - The average size (in sectors) of the requests that were issued to the device avgqu-sz - The average queue length of the requests that were issued to the device await - The average time (in milliseconds) for I/O requests issued to the device to be served svctm - The average service time (in milliseconds) for I/O requests %util - Percentage of CPU time during which I/O requests |
- To get current network device stats
# sar -n DEV 2 10
- To get network device stats for previous date, consider 14th
# sar -n DEV -f /var/log/sa/sa14
- To get network device stats for the 10th of month, from 7 AM to 3 PM
# sar -n DEV -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
|
- To get current network device stats
# sar -n NFS 2 10
- To get network device stats for previous date, consider 14th
# sar -n NFS -f /var/log/sa/sa14
- To get network device stats for the 10th of month, from 7 AM to 3 PM
# sar -n NFS -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
|
- To get current power management usage
# sar -m 2 10
- To get power management usage for previous date, consider 14th
# sar -m -f /var/log/sa/sa14
- To get power management usage for the 10th of month, from 7 AM to 3 PM
# sar -m ALL -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
|
- To get current memory stats
# sar -R 2 10
- To get memory stats for previous date, consider 14th
# sar -R -f /var/log/sa/sa14
- To get memory stats for the 10th of month, from 7 AM to 3 PM
# sar -R ALL -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
frmpg/s - Number of memory pages freed by the system per second bufpg/s - Number of additional memory pages used as buffers by the system per second campg/s - Number of additional memory pages cached by the system per second |
- sar : It collects and displays ALL system activities statistics.
- sadc : It stands for “system activity data collector”. This is the sar backend tool that does the data collection.
- sa1 : It stores system activities in binaryhttps://images-blogger-this purpose. sa1 runs from cron.
- sa2 : It creates daily summary of the collected statistics. sa2 runs from cron.
- sadf : It can generate sar report in CSV, XML, and various other formats. Use this to integrate sar data with other tools.
- iostat : It generates CPU, I/O statistics
- mpstat : It displays CPU statistics.
- pidstat : It reports statistics based on the process id (PID)
- nfsiostat : It displays NFS I/O statistics.
- cifsiostat : It generates CIFS statistics.
|
|
Very nice and good article....
ReplyDeleteSuper article. very very very great one
ReplyDeleteThanks a lot. Very nice one.
ReplyDeleteThankyou so much its very useful
ReplyDelete