I.T. Security and Linux Administration

Jul 30 2011   9:42PM GMT

vmstat Parser

Eric Hansen Eric Hansen Profile: Eric Hansen

Sharing a script here that I wrote to parse vmstat information. I know this informational program can change its output from system to system, so I can’t gurantee that it will work for you. However, this was written on Ubuntu, so I’m sure it’ll work for at least all of the Debian-based systems. The line is pretty self explanatory, granted a bit long. It basically calls vmstat, gets the last line of the output (the actual data), and outputs it in helpful information.

I wrote this tool as I couldn’t remember what all the different parts of it were for, and looked up all the information I could on the different columns. First, the code:


# vmstat parser script. Serves no real purpose besides making the information easily readable.

# Note that this script is heavily distribution-dependent, and may (read: probably) won't work on other system.

vmstat | tail -n 1 | awk '{printf("%d processes are in wait queue, while %d are resource-blocked.\n%d blocks per second are being written to disk, while %d blocks per second are being read from disk.\nThere is a total of %d interrupts a second, and %d context switches a second.\nCPU usage: %d%% (user), %d%% (system), %d%% (idle), %d%% wait\n",$1,$2,$9,$10,$11,$12,$13,$14,$15,$16)}'

The output of this, when it works right, will look something like this:

2 processes are in wait queue, while 0 are resource-blocked.

3 blocks per second are being written to disk, while 26 blocks per second are being read from disk.

There is a total of 58 interrupts a second, and 17 context switches a second.

CPU usage: 14% (user), 1% (system), 85% (idle), 0% wait

I’m hoping that this will come in handy for someone besides me, especially since the output of vmstat itself tends to be quite vague.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: