
#/bin/sh
# File	: log_filer_status.sh
# By	: Maarten.deBoer@AtosOrigin.com, 100928 (orig from Richard.Loos@AtosOrigin.com)
# Subject : Collecting filer status data (in 10 sec's) & put into log-file for later analyze
#set -x

PGM="`basename $0|cut -d\. -f1`"
DATE="`date '+%Y-%m-%d'`"
LOG="${HOME}/log/${PGM}.log"
SSH="/usr/bin/ssh"
DATADIR="${HOME}/data/stats"

FILERS="hwnaf01 nlnaf02 nlnaf03 nlnaf04 hwnaf05 hwnaf06 nlnaf07 nlnaf08 nlnaf09 nlnaf10 nlnaf11 nlnaf12"

# Test id DATADIR excists. IF not create
if [ ! -d ${DATADIR} ]; then
  echo "Creating ${DATADIR} ..."
  mkdir -p ${DATADIR}
fi

for FILER in ${FILERS} 
do
  LOG="${DATADIR}/${FILER}_${DATE}.stats"
  echo "= `date '+%Y-%m-%d %H:%M'`"|tee -a ${LOG}
  ${SSH} -n ${FILER} vfiler status|grep running|grep -v vfiler0|awk '{print $1}'|while read VFILER
  do
    echo "`date` ${FILER}/${VFILER} ..." 
    ${SSH} -n ${FILER} stats start -I ${VFILER} vfiler:${VFILER}

  done
  ${SSH} -n ${FILER} stats start -I NFS nfsv3
  ${SSH} -n ${FILER} stats start -I CIFS cifs
done

echo "Sleeping for 30 sec's ..."
sleep 30

for FILER in ${FILERS}
do
  LOG="${DATADIR}/${FILER}_${DATE}.stats"
  ${SSH} -n ${FILER} vfiler status|grep running|grep -v vfiler0|awk '{print $1}'|while read VFILER
  do
    echo "${FILER}/${VFILER} ..."
    ${SSH} -n ${FILER} stats stop -I ${VFILER}|tee -a ${LOG}

  done
  ${SSH} -n ${FILER} stats stop -I NFS|tee -a ${LOG}
  ${SSH} -n ${FILER} stats stop -I CIFS|tee -a ${LOG}
done


exit

