I am gathering statistics data using iostat and vmstat and am running each one for 10 seconds regularly. However, I don't want to print out the whole output. For iostat I want to only show the number of reads and writes and display them as a column. With vmstat, I just want to show the free, cache and buffer columns. How can I do this? Any filters I use just return this result. The systems are ubuntu 12.04 on both desktop terminal and server only version. they are run using vmware player.
ms total merged
0 0 0
0 0 0
0 0 0
0 0 0
758118 836340 1892
0 0 0
0 0 0
Assuming the output formats are as follows:
> iostat -dx sda
Linux 3.13.0-45-generic (hostname obscured) 03/22/2015 _x86_64_ (8 CPU)
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sda 7.02 30.64 4.48 8.32 174.81 789.29 150.64 0.86 67.48 10.76 98.01 1.06 1.36
> vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 3728772 969952 614416 29911568 3 13 22 99 1 4 48 5 47 0 0
You can do the following for iostat
(every 10 seconds if you'd like to):
device_name=sda # or whatever device name you want
iostat -dx ${device_name} | awk 'NR==4 { print $4 " " $5 }'
Example output (r/s w/s
):
4.48 8.32
If you need a count greater than 1, do this:
iostat -dx ${device_name} ${interval} ${count} | awk 'NR==1 || /^$/ || /^Device:/ {next}; { print $4 " " $5 }'
Example output (for device_name=sda; interval=1; count=5
):
10.24 8.88
0.00 0.00
0.00 2.00
0.00 0.00
0.00 0.00
And you can do the following for vmstat
(every 10 seconds if you'd like to):
vmstat | awk 'NR==3 {print $4 " " $5 " " $6}'
Example output (free buff cache
):
969952 614416 29911568