Check the LDAPBuild Process to see the current file.

This was as of 2005-07-28

#!/bin/bash
#:ndsperf.sh
#

# Read eDirectory installation variables and subroutines
if [ -f /var/nds/.ndsenv ]; then
  . /var/nds/.ndsenv_functions
  . /var/nds/.ndsenv
else
  printf "\nMissing /var/nds/.ndsenv -- cannot run!\n"
  exit 1
fi

# This routine parses the disk provided by df -k to find the corresponding
# device name in the form of c?t?d?, which is how iostat identifies disks.
# If slice is part of the name, it is truncated.
f_parsedev ()
# Arg_1=file system name from 'df -k'
{
	# Initialize local variables
	veritas=0
	unset vxgroup
	unset part
	while [ $# -ge 1 ]
	do
		case $1 in
		dev|md|dsk)	;;
		vx)		veritas=1
				;;
		*)		if [ $veritas -eq 1 ]
				then
					if [ -z "$vxgroup" ]
					then
						vxgroup=$1
					else
						part=$1
					fi
				else
					part=$1
				fi
				;;
		esac
		shift
	done
	if [ $veritas -eq 1 ]
	then
		DEV=`/usr/sbin/vxprint -g $vxgroup | grep "sd.*${part}-" | cut -d" " -f2 | cut -d"-" -f1`
	else
		# Drop the slice number from the result, if present
		DEV=${part%s*}
	fi
	#printf "vxgroup=$vxgroup part=$part DEV=$DEV\n"
	#exit 0
}

### Main #######################################################
# Logging headers:
# year,month,day,hour,minute,us,sy,wt,id,r/s,w/s,kr/s,kw/s,wait,actv,wsvc_t,asvc_t,%w,%b,device,searchStatus,searchTime
################################################################

# Define the ID and valid result to use for synthetic search
uidCheck="E017122"
snResult="sn: JOHNSON JR"
# Define maintenance window (start/end time); ndsperf.sh will not process
# during this window.  In the form of "hhmmss".
sMaintTime=000000
eMaintTime=050000

# Abort if current time is during maintenance hours, or if ndsd isn't running
if [[ ${DATE:8}00 > ${sMaintTime} && ${DATE:8}00 < ${eMaintTime} ]]; then
  exit 0
fi
if [ -z "`pgrep ndsd`" ]; then
  exit 0
fi


# Initialize variables
PATH=$PATH:/usr/local/bin
USER=ndsuser
USERhomedir=`grep ndsuser /etc/passwd|awk -F":" '{print $6}'`
data_file=/var/nds/ndsperf.csv
archPath=$USERhomedir
archFile=

# Check current time; if Sunday 23:59 prepare to generate gzip'd tar archive of ndsperf.csv data
# WARNING -- assumes crontab is running the script on 1 minute cylces from 07:00am until 11:59pm, eg:
# * 07-23 * * * $HOME/bin/ndsperf.sh>/dev/null 2>&1
# Be sure to change text below to match last run of each day if crontab is set differently
if [ "`date +%a%H%M`" = "Sun2359" ]; then
  archFile=ndsperf.weekly`date +%Y%m%d`-$HOSTNAME.csv
fi

# Build header if the data file doesn't already exist
if [ ! -f $data_file ]; then
  echo "year,month,day,hour,minute,us,sy,wt,id,r/s,w/s,kr/s,kw/s,wait,actv,wsvc_t,asvc_t,%w,%b,device,searchStatus,searchTime" > $data_file
  chown $USER:$ndsGROUP $data_file
  chmod 640 $data_file
fi

## Set notification flags
#NOTIFY="NO"
#if test -f $ndsperfAlertFile; then
#  eval `grep "URGENT=" $ndsperfAlertFile`
#  eval `grep "RECURRENT=" $ndsperfAlertFile`
#fi
#URGENT=${URGENT:="NO"}
#RECURRENT=${RECURRENT:="NO"}
#
#if test -f $ndsperfCountFile; then
#  STATUS_COUNT=`cat $ndsperfCountFile`
#fi
#let "STATUS_COUNT = $STATUS_COUNT + 1"

DEV=`/usr/xpg4/bin/df -k /var/nds | tail -1 | awk '{print $1}' | sed -e 's/\// /g'`
f_parsedev $DEV
record=`date +%Y,%m,%d,%H,%M`
cpuiostat=`iostat -cr 1 2 | tail -1`
record=$record,$cpuiostat
record=$record,`iostat -xnCr 1 2 | grep ",${DEV}$" | tail -1`
searchresult=`(time -p $LDAPSEARCH -LLL -l40 -h$HOSTNAME -e$USERhomedir/bin/$TREENAME.der -D"cn=ndsperf,ou=Administration,$BaseDN" -wp3rftestp9ss uid=$uidCheck sn > /tmp/searchresult.$$ 2>&1) 2>&1`
realseconds=`echo $searchresult | awk '{print $2}'`
uscpu=`echo $cpuiostat | awk '{print $1}'`

if [ "`tail -2 /tmp/searchresult.$$ | head -n 1`" = "$snResult" ]; then
  record=$record,OK,$realseconds
else
  record=$record,"`cat /tmp/searchresult.$$`",$realseconds
fi

# Write the data to the log
echo $record >> $data_file

# Cleanup temp file
if [ -f /tmp/searchresult.$$ ]; then
  rm /tmp/searchresult.$$
fi

if [ ! -z "$archFile" ]; then
  # Backup the file, and move it out of the way for archive
  cp -p $data_file $data_file.bak
  mv $data_file $archPath/$archFile
  # zip it & chown it to ndsuser owner
  gzip $archPath/$archFile
  if [ $? -eq 0 ]; then
    chown $USER:$ndsGROUP $archPath/$archFile.gz
    chmod 640 $archPath/$archFile.gz
  else
    printf "\nError running 'gzip' -- not found in PATH.\n"
    chown $USER:$ndsGROUP $archPath/$archFile
    chmod 640 $archPath/$archFile
  fi
fi

# The remainder of this script is still under development -- just bail for now
exit 0

# If high CPU or slow LDAP response, collect diagnostics
if [ $uscpu -ge 50 -o ${realseconds%.*} -ge 10 ]; then
  $USERhomedir/bin/ndsdiag.sh &
fi

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-1) was last changed on 24-May-2008 13:26 by jeem