Install gnuplot 3.7.1.0, zlib 1.1.4 and libpng 1.0.9.0 (bullfreeware) and use the following example ksh script to produce graphs in .png format.

outdir=/usr/local/output
cmndfile=${etcdir}/cpu-cmnd$$
datafile=${outdir}/saru$$
outfile=sar.${hostname}.out
 
# Create CPU graphs
for file in ls /var/adm/sa/sa[0-9]*
do
 
        name=${file##*/}
        pngfile=${outdir}/cpu.${hostname}.${name}.png
 
        title="${hostname} CPU Stats for ${file}"
        > ${outfile}
 
        sar -uf ${file} >> $outfile
 
        cat $outfile |grep -v AIX|grep -v "usr" | grep -v Average | grep -v '^$' > $datafile
 
        echo "set term png color" > $cmndfile
        echo "set out '$pngfile'" >> $cmndfile
        echo "set title '$title'" >> $cmndfile
        echo "set ylabel 'percent'"  >> $cmndfile
        echo "set xdata time" >> $cmndfile
        echo "set timefmt '%H%M'" >> $cmndfile
        echo "plot '$datafile' using 1:2 smooth bezier title 'usr', \\" >> $cmndfile
        echo "'$datafile' using 1:3 smooth bezier title 'sys', \\"" >> $cmndfile
        echo "'$datafile' using 1:4 smooth bezier title 'wio', \\" >> $cmndfile
        echo "'$datafile' using 1:5 smooth bezier title 'idle'" >> $cmndfile
 
        # create graph using constructed gnuplot command file and data
        # NOTE: the datafile is specified within the command file
        /usr/local/bin/gnuplot $cmndfile
 
        # clean up temp files
        rm $datafile
        rm $cmndfile
done
 
# Create paging graphs
for file in ls /var/adm/sa/sa[0-9]*
do
        name=${file##*/}
        pngfile=${outdir}/page.${hostname}.${name}.png
        title="${hostname} Paging Stats for ${file}"
        > ${outfile}
 
        sar -rf ${file} >> $outfile
 
        cat $outfile |grep -v AIX|grep -v "slots" | grep -v Average | grep -v '^$' > $datafile
 
        echo "set term png color" >> $cmndfile
        echo "set out '$pngfile'" >> $cmndfile
        echo "set title '$title'" >> $cmndfile
        echo "set ylabel 'value/s'" >>; $cmndfile
        echo "set xdata time" >> $cmndfile
        echo "set timefmt '%H%M'" >>; $cmndfile
        echo "plot '$datafile' using 1:3 smooth bezier title 'cycles', \\" >> $cmndfile
        echo "'$datafile' using 1:4 smooth bezier title 'faults', \\" >> $cmndfile
        echo "'$datafile' using 1:5 smooth bezier title 'odio'" >> $cmndfile
 
        # create graph using constructed gnuplot command file and data
        # NOTE: the datafile is specified within the command file
        /usr/local/bin/gnuplot $cmndfile
 
        # clean up temp files
        rm $datafile
        rm $cmndfile
done

About troyski

I'm a freelance UNIX engineer working in the UK. I'm married to Tina and between us we have six children. I'm a bit of an Apple fan boy, and all the Windows machines in the house are a thing of the past now.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Private

Post navigation