[CentOS] System Resources Graphing

Mon Apr 26 16:43:32 UTC 2010
Alan McKay <alan.mckay at gmail.com>

On Mon, Apr 26, 2010 at 12:13 PM, Brian Mathis <brian.mathis at gmail.com> wrote:
> Take a look at the "sysstat" package which will collect data over
> time.  There's a java-based desktop app called "kSar" that can use
> this data to generate graphs.

I use kSar as well as Munin.   Munin's only problem is that it has a
hard coded 5 minute granularity - which is perfectly fine for 99% or
more of what you need.   I run this script on my systems which keeps
sar logs with finer granularity that I can check into with kSar if I
need to.  But I almost never need to.

Run this every hour from cron to keep sar files for each hour

01 * * * * /root/sadc.sh

You may choose to only turn this on at times when you need that kind
of granularity - below is pretty extreme with 10 second granularity.
But even at that I do not find it impacts performance in any noticable
fashion.

#!/bin/bash

# DATEFORMAT="%Y.%m.%d %H:%M:%S"
HOSTNAME=`hostname | awk -F. '{print $1}'`
DATEFORMAT="%Y.%m.%d %H:%M:%S"
# SAINTERVAL x SACOUNT = 3600
SAINTERVAL=10           # seconds
SACOUNT=360             # iterations
TIMESTAMP=`date +"${DATEFORMAT}"`
LOGFILEMAX=80                           # max number of files to store
((LOGFILEMAXMINUTES=60*LOGFILEMAX))
LOGDIR="/var/log/sa/sadc"
mkdir -p $LOGDIR
if [ ! -d $LOGDIR ]
then
        echo "ERROR: $LOGDIR does not exist"
        exit 1
fi
LOGFILE=`echo "${LOGDIR}/sadc_${HOSTNAME}_${TIMESTAMP}" | sed "s/ /_/g" `

# are we 32 or 64 bit?

BASEARCH=`uname -i`
case $BASEARCH in
        i386)
                SADC="/usr/lib/sa/sadc"
                ;;
        x86_64)
                SADC="/usr/lib64/sa/sadc"
                ;;
        *)
                echo "ERROR: unknown architecture [$BASEARCH]"
                exit 2
esac

$SADC -d -I -F $SAINTERVAL $SACOUNT $LOGFILE

# get the date from LOGFILEMAXMINUTES minutes ago and then touch
# a file so it has that date.  We'll then use this file
# in the "find" command to find all files older than
# it, so we can remove them

MAXFILESTAMP=`date  -d "$LOGFILEMAXMINUTES minutes ago"`
MAXFILENAME=syscheckmaxfile
MAXFILE="${LOGDIR}/${MAXFILENAME}"
touch -d "${MAXFILESTAMP}" $MAXFILE

pushd $LOGDIR
RMFILES=`find . ! -name $MAXFILENAME -type f ! -newer $MAXFILE`
for afile in $RMFILES
do
        rm -f $afile
done
popd
:

-- 
“Don't eat anything you've ever seen advertised on TV”
         - Michael Pollan, author of "In Defense of Food"