Linux – How to obtain counters for swap-in/swap-out on Linux

linuxmemoryperformanceprocswap

I'm trying to obtain counters for swap-in/swap-out activity on CentOS 6. The intention is to feed raw data into RRDtool to generate graphs, and use it to generate alerts. I've had a look at common tools (vmstat, smem, and dstat), but these all seem aimed at interactive use, ie "from this point on" rather than providing raw access to counters.

sar is running on the system, and can generate historical reports, but doesn't seem like it tracks counters of swap-in/swap-out activity.

The /proc manpage seems to indicate raw counters are available via /proc/stat:

page 5741 1808
    The number of pages the system paged in and the number
    that were paged out (from disk).

But that line is not present in the contents of /proc/stat on this system (kernel 2.6.32). I'd prefer raw counters to avoid running/looping background processes like vmstat. Looking at the contents of free isn't ideal, as it only shows percent used at a single point in time, not total activity since the last reading.

Any tips?

Best Answer

It is not clear if you search for page in/out caused by paging or by swapping. The difference is explained at several places here (https://superuser.com/questions/785447). The number of pages swapped and paged from /proc/vmstat.

Pages paged in / out

$ cat /proc/vmstat|grep pgpg
pgpgin 6920262
pgpgout 345654122

Pages swapped in / out

$ cat /proc/vmstat|grep pswp
pswpin 0
pswpout 0