Tuesday, October 31, 2006

Linux : Virtual Memory Statistics

vmstat command shows Virtual Memory Statistics.

Sample outputs of the command are shown below.

$ vmstat

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd    free    buff    cache   si   so    bi   bo     in  cs        us  sy  id   wa
 0  0 507912  6016  5216  61768   0     0     1    5      3    3         1   0   98    0

With -s option (this prints the vm table)

$ vmstat -s

       515420  total memory
       510060  used memory
       340984  active memory
        18404  inactive memory
         5360  free memory
         5580  buffer memory
        62024  swap cache
      1024088  total swap
       507896  used swap
       516192  free swap
      5159612 non-nice user cpu ticks
       284811 nice user cpu ticks
      1343974 system cpu ticks
    441240715 idle cpu ticks
      1061329 IO-wait cpu ticks
       266848 IRQ cpu ticks
       130451 softirq cpu ticks
    135296968 pages paged in
     21489954 pages paged out
       402670 pages swapped in
       414068 pages swapped out
    402061903 interrupts
    401831289 CPU context switches
   1157798489 boot time
       185206 forks


To get just one number say that of free memory, you have to pipe this command to a awk (or perl or some other) that does filtering.

$ vmstat -s | awk '/free memory/{print $1}'
5360

awk is sometimes handier than grep :-)

No comments: