sar command (Part II) : CPU, Memory reporting

In last post of sar command we have seen its datafile structure, how to extract data from it and time formats to be used with this command.  In this post lets see how to get CPU, memory utilization reports from datafiles or real time using sar command.

sar command follows below format :
# sar [ options ] [ <interval> [ <count> ] ]
We have already seen what is interval and count in last post. Now we will see different options which can be used to get different system resource utilization stats. Also, we have seen how to get historic data from sar datafiles, I will be using only real time commands (i.e. without -f option) for all below examples.
Before we start with resource reporting here is a quick tip about start and end time of reports when you are extracting data from datafiles. Below two options can be used with sar command (in conjunction with -f) so that specific time window data can be extracted.
  • -s hh:mm:ss Start time of report. Sar starts output records tagged to this time or very next available time tagged record. Default start time is 08:00:00
  • -e hh:mm:ss End time of report. Default end time is 18:00:00

CPU utilization reporting using sar
For CPU statistics, sar command has -u option. Executing sar command with -u gives us below utilization matrices (highlighted values are more commonly observed for performance monitoring) :
  • %user : CPU % used by user processes
  • %nice : CPU % used by user processes with nice priority
  • %system :  CPU % used by system processes
  • %iowait : % of time when CPU was idle (since processes were busy in IO)
  • %steal : % of time wait by virtual CPU while hypervisor servicing another CPU (virtualization aspect)
  • %idle : CPU % idle.
See above example to get values of parameters explained above. The output starts with line which has OS kernel version details, hostname in brackets, date, architecture and total number of CPUs. Followed by a data with interval (2 sec) and count (3) specified in command. Finally, it also gives us average value for all parameters. Column CPU denoting value all indicates these are averaged out values of all 16 CPU for the given time instance.
If you are interested in seeing values for each processor then -P option (per processor reporting) can be used with CPU number of your choice or ‘ALL’. When ALL is specified each processor’s data is shown or only specified CPU’s data is processed.
See above example where I mentioned ALL with -P option and got each processor’s utilization report. In below example only CPU number 2 data is extracted.
Another small stats regarding processor is power stats. Here sar shows you processor clock frequency at given instance of time. This helps in calculating power being used by CPU. -m option gives this data and it can be used per -processor reporting option too.

Memory utilization reporting using sar
Memory stats can be extracted with -r option. When sar runs with -r option, it presents below parameters (highlighted values are more commonly observed for performance monitoring) :
  • kbmemfree : Free memory available in kilobytes.
  • kbmemused : Memory used (excluding kernel usage)
  • %memused : Percentage of memory used
  • kbbuffers :  memory used as buffers by the kernel in kilobytes
  • kbcached : memory used to cache data by the kernel in kilobytes
  • kbcommit : memory  in  kilobytes  needed for current workload. (commitment!)
  • %commit : % of memory needed for current workload in relation to the total memory (RAM+swap)
Output above shows parameter values. It sections same as explained above (CPU report example); first line details, last avg row etc. Note that, %commit can be 100%+ too since kernel always over commit to avoid out of memory situation.
Paging statistics can be obtained using -B option. Normally, parameters shown in this option’s output are not observed by sysadmin. But if in-depth troubleshooting or monitoring is required then only this option is used. It shows below parameters:
  • pgpgin/s :  Number of kilobytes the system paged in from disk per second.
  • pgpgout/s : Number of kilobytes the system paged out to disk per second.
  • fault/s : Number of page faults per second.
  • majflt/s : Number of major page faults 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 per second.
  • %vmeff : This is a metric of the efficiency of page reclaim.
Swap statistics can be obtained with -S option. Swap is another aspect of memory hence its utilization monitoring is as important as memory. Swap utilization reports are shown with -S option. It shows below parameters (highlighted values are more commonly observed for performance monitoring) :
  • kbswpfree : Free swap in kilobytes
  • kbswpused : Used swap in kilobytes
  • %swpused : % of swap used
  • kbswpcad : Amount of cached swap memory in kilobytes
  • %swpcad : % of cached swap memory in relation to used swap.
In above example you can see total of 8GB swap avaibale on server and nothing of it used. Swap will get hits only if memory gets completely utilized.

SHARE

sangeethakumar

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment