Want to monitor how fast space is being cleared or used up. The resolution of this script isnt as good as I prefer it to be, I put 60 seconds to get more accurate results. You cant do less then a second, because then the time_diff is below 1, which is 0, because I measure in unix_epoch time which are in seconds, so anything less then 1 is just 0... which leads to division by 0 in the formula SPACE_DIFF/TIME_DIFF

Just alter the DEVICE1 and the INTERVAL=60. This is a copy paste script, so paste it right into your shell and hit enter. Sample output is below

THE SCRIPT
###########

DEVICE1="/dev/sda1"
INTERVAL=60;
while true;
do
clear;
echo -e "`date` - INTERVAL IS $INTERVAL SECONDS"
echo "######################################################";
echo "CURRENT DF (kilobytes):";
df $DEVICE1;
echo "CURRENT DF -H (human readable):";
echo "######################################################";
df -h $DEVICE1;
echo "######################################################";
USEDSPACE1=`df -P $DEVICE1 | tail -1 | awk '{print $3}'`; 
TIME1=`date +%s`;
echo "OLD UNIX EPOCH IN SECONDS / USED SPACE IN KBytes: $TIME2 $USEDSPACE2";
echo "CURRENT UNIX EPOCH IN SECONDS / USED SPACE IN KBytes: $TIME1 $USEDSPACE1";
# one minus two
DIFFSPACE=`echo $USEDSPACE1 $USEDSPACE2 | awk '{x=$1-$2; print x}'`
DIFFTIME=`echo $TIME1 $TIME2 | awk '{x=$1-$2; print x}'`
echo "######################################################";
echo "TIME DIFF IN SECONDS / SPACE DIFF IN KBytes: $DIFFTIME $DIFFSPACE";
echo "######################################################";
SPEED_KB=`echo $DIFFSPACE $DIFFTIME | awk '{x=$1/$2; print x}'`
SPEED_MB=`echo $SPEED_KB | awk '{x=$1/1024; print x}'`
echo "SPEED KBytes/S: $SPEED_KB - if negative freespace is increasing"
echo "SPEED MBytes/S: $SPEED_MB - if negative freespace is increasing"
USEDSPACE2=$USEDSPACE1
TIME2=$TIME1
sleep $INTERVAL;
done;

SAMPLE OUTPUT
###############

Sun Sep 22 17:54:41 PDT 2013 - INTERVAL IS 60 SECONDS
######################################################
CURRENT DF (kilobytes):
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/md127 2925416704 2337008180 488599484 83% /Sally/._snap-Studies/c_2013_09_22__17_00_57
CURRENT DF -H (human readable):
######################################################
Filesystem Size Used Avail Use% Mounted on
/dev/md127 2.8T 2.2T 466G 83% /Sally/._snap-Studies/c_2013_09_22__17_00_57
######################################################
OLD UNIX EPOCH IN SECONDS / USED SPACE IN KBytes: 1379897621 2336975144
CURRENT UNIX EPOCH IN SECONDS / USED SPACE IN KBytes: 1379897681 2337008180
######################################################
TIME DIFF IN SECONDS / SPACE DIFF IN KBytes: 60 33036
######################################################
SPEED KBytes/S: 550.6 - if negative freespace is increasing
SPEED MBytes/S: 0.537695 - if negative freespace is increasing

 

Leave a Reply

Your email address will not be published. Required fields are marked *