Which Files Grow The Fastest, Take 2
By expanding from my previous blog, I am able to find out what percentage of each of these files contributed to the file system growth. All I have to do is to keep track of the
df -k $dir in the two snapshots within the interval.
Here is the script
#! /bin/ksh
#
# Find out the fastest growth of files within a certain interval
trap 'rm -f $tmpfile-*; exit 0' 0 1 2 3 5 9 15
PATH=/usr/bin:/bin:/usr/sbin
LD_LIBRARY_PATH=/usr/lib:/lib
if [ $# -ne 2 ]; then
echo "Usage: $0 "
exit 1
fi
dir=$1
interval=$2
if [ ! -d $dir ]; then
echo "Error. $dir does not exist"
exit 2
fi
tmpfile="/tmp/${0##*/}.$$"
touch $tmpfile-0
# first snapshot
sleep $interval
used1=`df -kl $dir | awk 'NR==2{print $3}'`
find $dir -type f -newer $tmpfile-0 -mount -ls | awk '{print "t1", $7, $11}' > $tmpfile-1
# second snapshot
sleep $interval
used2=`df -kl $dir | awk 'NR==2{print $3}'`
find $dir -type f -newer $tmpfile-0 -mount -ls | awk '{print "t2", $7, $11}' > $tmpfile-2
cat $tmpfile-1 $tmpfile-2 | nawk -v interval=$interval -v used1=$used1 -v used2=$used2 '
BEGIN {
# convert kilobyte to byte
diffused=1024*(used2-used1)
}
$1=="t1" { t1[$3]=$2 }
$1=="t2" { t2[$3]=$2 }
END {
for (i in t1) {
d=t2[i]-t1[i]
percent=100*d/diffused
printf("%d Bps (%.2lf %%) %s\n", d/interval, percent, i)
}
}' | sort -n -k 1
And the corresponding output:
474 Bps (0.70 %) /opt/app/App/logs/current/poll20100219.out 504 Bps (0.74 %) /opt/app/App/logs/current/app.log20100219.log 818 Bps (1.20 %) /opt/app/App/logs/current/notify20100219.log 2165 Bps (3.18 %) /opt/app/bea/user_projects/domains/appDomain/servers/recorder.log 39638 Bps (58.28 %) /opt/app/App/logs/current/xml.log
Now we can clearly identified /opt/app/App/logs/current/xml.log contributed 58% of the file system growth.
Labels: performance, Solaris

0 Comments:
Post a Comment
<< Home