#!/bin/sh

# writes

# to do
# make disk grep a little less messy

# check for stats file and fill if necessary
# if we don't have the file, the first set of numbers are going to be less than accurate
if [ ! -e /tmp/vmstat-write.mrtg ] 
	then
		$(vmstat -dp | grep sda | awk '{print $6}' > /tmp/vmstat-write.mrtg)
	fi

# get previous stats from file

prevwrites=$(cat /tmp/vmstat-write.mrtg)

# get current stats

currwrites=$(vmstat -dp | grep sda | awk '{print $6}')

# put current values into file for next time

echo "$currwrites" > /tmp/vmstat-write.mrtg

# calculate how many writes since last time - high number indicates lots of i/o
# currwrites will always be higher or the same as vmstat is NOT an average
# but rather i/o since boot

writediff=$(expr $currwrites - $prevwrites)

# echo it so mrtg access via snmp
echo $writediff
