Blame IbaTools/opacheckload/opacheckload.sh

Packit 857059
#!/bin/bash
Packit 857059
# BEGIN_ICS_COPYRIGHT8 ****************************************
Packit 857059
# 
Packit 857059
# Copyright (c) 2015, Intel Corporation
Packit 857059
# 
Packit 857059
# Redistribution and use in source and binary forms, with or without
Packit 857059
# modification, are permitted provided that the following conditions are met:
Packit 857059
# 
Packit 857059
#     * Redistributions of source code must retain the above copyright notice,
Packit 857059
#       this list of conditions and the following disclaimer.
Packit 857059
#     * Redistributions in binary form must reproduce the above copyright
Packit 857059
#       notice, this list of conditions and the following disclaimer in the
Packit 857059
#       documentation and/or other materials provided with the distribution.
Packit 857059
#     * Neither the name of Intel Corporation nor the names of its contributors
Packit 857059
#       may be used to endorse or promote products derived from this software
Packit 857059
#       without specific prior written permission.
Packit 857059
# 
Packit 857059
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 857059
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 857059
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit 857059
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
Packit 857059
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 857059
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit 857059
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit 857059
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit 857059
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 857059
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 857059
# 
Packit 857059
# END_ICS_COPYRIGHT8   ****************************************
Packit 857059
Packit 857059
# [ICS VERSION STRING: unknown]
Packit 857059
Packit 857059
# get loadavg on all hosts and show busiest or least busy hosts
Packit 857059
# This can be used to make sure hosts are idle before starting a MPI benchmark
Packit 857059
# or to see if a benchmark is running
Packit 857059
Packit 857059
# optional override of defaults
Packit 857059
if [ -f /etc/opa/opafastfabric.conf ]
Packit 857059
then
Packit 857059
   . /etc/opa/opafastfabric.conf
Packit 857059
fi
Packit 857059
Packit 857059
. /usr/lib/opa/tools/opafastfabric.conf.def
Packit 857059
Packit 857059
. /usr/lib/opa/tools/ff_funcs
Packit 857059
Packit 857059
trap "exit 1" SIGHUP SIGTERM SIGINT
Packit 857059
Packit 857059
Usage_full()
Packit 857059
{
Packit 857059
	echo "Usage: opacheckload [-f hostfile] [-h 'hosts'] [-r] [-a|-n numprocs]" >&2
Packit 857059
	echo "                      [-d uploaddir]" >&2
Packit 857059
	echo "              or" >&2
Packit 857059
	echo "       opacheckload --help" >&2
Packit 857059
	echo "   --help - produce full help text" >&2
Packit 857059
	echo "   -f hostfile - file with hosts to check," >&2
Packit 857059
	echo "                 default is $CONFIG_DIR/opa/hosts" >&2
Packit 857059
	echo "   -h hosts - list of hosts to check" >&2
Packit 857059
	echo "   -r - reverse output, show least busy hosts, default is busiest hosts" >&2
Packit 857059
	echo "   -n numprocs - show top numprocs hosts, default 10" >&2
Packit 857059
	echo "   -a - show all hosts, default 10" >&2
Packit 857059
	echo "   -d upload_dir - directory to upload loadavg to, default is uploads" >&2
Packit 857059
	echo >&2
Packit 857059
	echo " Environment:" >&2
Packit 857059
	echo "   HOSTS - list of hosts, used if -h option not supplied" >&2
Packit 857059
	echo "   HOSTS_FILE - file containing list of hosts, used in absence of -f and -h" >&2
Packit 857059
	echo "   UPLOADS_DIR - directory to upload loadavg to, used in absence of -d" >&2
Packit 857059
	echo "   FF_MAX_PARALLEL - maximum concurrent operations" >&2
Packit 857059
	echo "example:">&2
Packit 857059
	echo "   opacheckload" >&2
Packit 857059
	echo "   opacheckload -h 'arwen elrond'" >&2
Packit 857059
	echo "   HOSTS='arwen elrond' opacheckload" >&2
Packit 857059
	exit 0
Packit 857059
}
Packit 857059
Packit 857059
Usage()
Packit 857059
{
Packit 857059
	echo "Usage: opacheckload [-f hostfile] [-r] [-a|-n numprocs]" >&2
Packit 857059
	echo "              or" >&2
Packit 857059
	echo "       opacheckload --help" >&2
Packit 857059
	echo "   --help - produce full help text" >&2
Packit 857059
	echo "   -f hostfile - file with hosts to check," >&2
Packit 857059
	echo "                 default is $CONFIG_DIR/opa/hosts" >&2
Packit 857059
	echo "   -r - reverse output, show least busy hosts, default is busiest hosts" >&2
Packit 857059
	echo "   -n numprocs - show top numprocs hosts, default 10" >&2
Packit 857059
	echo "   -a - show all hosts, default 10" >&2
Packit 857059
	echo "   -H - supress headers for script parsing" >&2
Packit 857059
	echo >&2
Packit 857059
	echo " Environment:" >&2
Packit 857059
	echo "   FF_MAX_PARALLEL - maximum concurrent operations" >&2
Packit 857059
	echo "example:">&2
Packit 857059
	echo "   opacheckload" >&2
Packit 857059
	echo "   opacheckload -f good" >&2
Packit 857059
	exit 2
Packit 857059
}
Packit 857059
Packit 857059
if [ x"$1" = "x--help" ]
Packit 857059
then
Packit 857059
	Usage_full
Packit 857059
fi
Packit 857059
Packit 857059
numprocs=10
Packit 857059
ropt=-r
Packit 857059
while getopts f:h:n:d:aHr param
Packit 857059
do
Packit 857059
	case $param in
Packit 857059
	h)
Packit 857059
		HOSTS="$OPTARG";;
Packit 857059
	H)
Packit 857059
		skip_headers=1;;
Packit 857059
	f)
Packit 857059
		HOSTS_FILE="$OPTARG";;
Packit 857059
	n)
Packit 857059
		numprocs="$OPTARG";;
Packit 857059
	d)
Packit 857059
		UPLOADS_DIR="$OPTARG";;
Packit 857059
	a)
Packit 857059
		numprocs="1000000";;	# more than ever expected to be found
Packit 857059
	r)
Packit 857059
		ropt="";;	# sort from lowest to highest, shows least busy
Packit 857059
	?)
Packit 857059
		Usage;;
Packit 857059
	esac
Packit 857059
done
Packit 857059
shift $((OPTIND -1))
Packit 857059
Packit 857059
if [ $# -ne 0 ]
Packit 857059
then
Packit 857059
	echo "opacheckload: extra arguments: $@" >&2
Packit 857059
	Usage
Packit 857059
fi
Packit 857059
Packit 857059
check_host_args opacheckload
Packit 857059
# HOSTS now lists all the hosts, pass it along to the commands below via env
Packit 857059
export HOSTS
Packit 857059
unset HOSTS_FILE
Packit 857059
Packit 857059
# remove any stale data so we don't mistakenly report it below
Packit 857059
for j in $HOSTS
Packit 857059
do
Packit 857059
	rm -f $UPLOADS_DIR/$j/loadavg
Packit 857059
done
Packit 857059
Packit 857059
opacmdall -p 'cat /proc/loadavg > /tmp/loadavg' >/dev/null
Packit 857059
opauploadall -p /tmp/loadavg loadavg >/dev/null
Packit 857059
if [ -z $skip_headers ]; then
Packit 857059
	echo "loadavg					host"
Packit 857059
fi
Packit 857059
Packit 857059
for j in $HOSTS
Packit 857059
do
Packit 857059
	i=$UPLOADS_DIR/$j/loadavg
Packit 857059
	if [ ! -e $i ]
Packit 857059
	then
Packit 857059
		echo "opacheckload: $j: Unable to get loadavg" >&2
Packit 857059
	else
Packit 857059
		l=`cat $i`
Packit 857059
		echo "$l	$j"
Packit 857059
	fi
Packit 857059
done | sort -n $ropt|head -n $numprocs