Skip to main content

Displaying Virtual FC Adapter Stats

Rob McNelly shares a script that can make life easier when working with multiple VIO servers.

sketched out images - chess pieces, etc. over a green background with a purple aixchange header

I've posted a few Dean Rowswell scripts over the years, but it's been awhile. He emailed me recently though, so I'm sharing the following with his permission:
 
There is a really nice -client flag on the VIOS padmin fcstat command that displays virtual FC adapter stats and I wanted to improve on the output and to work with multiple VIO servers so I made a script.
Here is the usage of it:

USAGE: get_vio_fcstat [ -v, -V, -h, -u, -l, -n ]

  -v or -V will print out the version and exit
 -h VIOS hostname(s) or IP address(es) COMMA SEPARATED to use
 -u VIOS userid to use (only required if padmin not used)
 -l will sort the report by LPAR/HOST name
 -n only include specific HOSTS or VIOS

EXAMPLE: get_vio_fcstat -h vios1,vios2

 get_vio_fcstat -n lpar

 get_vio_fcstat -h vios1,vios2 -n "lpar|vio" -l

You will need to change the VIOS_LIST variable at the top of the script and then have password-less ssh setup from the server running it on to the target VIO(S).

I usually run this script from a NIM server for this purpose.

The Script

#!/bin/ksh
# Created by Dean Rowswell, July 27, 2020
# Modified by Dean Rowswell, July 28, 2020
#  V1.1 - change report column order + add flag to display the report sorted by LPAR/HOST name
# Modified by Dean Rowswell, July 30, 2020
#  V1.2 - calculate the total physical and virtual statistics + add flag to only include specific LPAR/HOST names in the report
#
# This script runs the command fcstat -client on Virtual I/O Servers to display the physical and virtual Fibre Channel statistics
# The FC read and FC write statistics are totaled and the default report is sorted from the highest to the lowest
# The VIOS physical adapters are labeled "PHYS"

VIOS_LIST="vios1 vios2"
VIOS_USER="padmin"
VER="1.2"

# Parameter checks
if [ ${#*} -ne 0 ]
then
  while getopts :vVh:u:ln: PARMS
  do
    case $PARMS in
      v|V) echo "This is $0 version: $VER" ; exit ;;
      h)   VIOS_LIST=`echo ${OPTARG} | tr ',' ' '` ;;
      u)   VIOS_USER=${OPTARG} ;;
      n)   LPAR_NAME=${OPTARG} ;;
      l)    LPAR_SORT=1 ;;
      ?)   echo "\nUSAGE:\t$0 [ -v, -V, -h, -u, -l, -n ]" ; echo "\t-v or -V will print out the version and exit" ; echo "\t-h VIOS hostname(s) or IP address(es) COMMA SEPARATED to use"
           echo "\t-u VIOS userid to use (only required if padmin not used)" ; echo "\t-l will sort the report by LPAR/HOST name"
          echo "\t-n only include specific HOSTS or VIOS\n" ; echo "EXAMPLE: $0 -h vios1,vios2\n\t $0 -n lpar\n\t $0 -h vios1,vios2 -n \"lpar|vio\" -l\n" ; exit ;;
    esac
  done
fi

printf "\n%-24s %-12s %-17s %-24s %-6s %14s %11s %12s %12s %11s %12s\n" HOSTNAME DEVICE WWPN VIOS PHYS TOTAL_R+W_GiB "(    TiB   ) =" READS_GiB "(    TiB   )  +" WRITES_GiB "(    TiB   )"
echo "------------------------ ------------ ----------------- ------------------------ ------  ------------- ------------    ----------- ------------    ----------- ------------"
VIOS=""

GET_VIO_FCSTAT () {
for VIO in ${VIOS_LIST}
do
  ssh -q ${VIOS_USER}@${VIO} ioscli ioslevel >/dev/null 2>/dev/null
  if [ $? -ne 0 ]
  then
    echo "Password-less SSH access to VIOS ${VIO} with user ${VIOS_USER} is not setup\n"
    continue
  fi
  ssh -q ${VIOS_USER}@${VIO} "ioscli fcstat -client" 2>/dev/null | awk -v VIOS="$VIOS" -v NAME="$LPAR_NAME" '{
  if (NF == 11 && $1 != "hostname") {
    if (VIOS == "") { VIOS=$1; PHYS=$2 } ; HOST=$1 ; DEV=$2 ; WWPN=$3 ; READ=$7 ; WRITE=$8 ; TOTAL=$7+$8
    if (HOST == VIOS) { DEV=DEV"[PHYS]" }
    if ($1 ~ NAME) { printf "%-24s %-12s %-17s %-24s %-6s %14.3f   %8.3f   %14.3f   %8.3f   %14.3f   %8.3f\n", HOST, DEV, substr(WWPN,3,16), VIOS, PHYS, TOTAL/1073741824, TOTAL/1099511627776, READ/1073741824, READ/1099511627776, WRITE/1073741824, WRITE/1099511627776}}
  if (NF == 0) { VIOS = "" }
  }'
done
}

CALC_TOTALS () {
awk '$2 ~ /[PHYS]/ { P_RW_GB += $6 ; P_RW_TB += $7 ; P_R_GB +=$8 ; P_R_TB += $9 ; P_W_GB += $10 ; P_W_TB += $11 ; print $0 ; next }  { V_RW_GB += $6 ; V_RW_TB += $7 ; V_R_GB +=$8 ; V_R_TB += $9 ; V_W_GB += $10 ; V_W_TB += $11 ; print $0 } END { print "                                                                                ---------------  ------------- ------------    ----------- ------------    ----------- ------------" ;printf "%87s %14.3f ( %8.3f ) %14.3f ( %8.3f ) %14.3f ( %8.3f )\n", "PHYSICAL total:", P_RW_GB, P_RW_TB, P_R_GB, P_R_TB, P_W_GB, P_W_TB ; printf "%87s %14.3f ( %8.3f ) %14.3f ( %8.3f ) %14.3f ( %8.3f )\n", "VIRTUAL total:", V_RW_GB, V_RW_TB, V_R_GB, V_R_TB, V_W_GB, V_W_TB }'
}

if [ ${LPAR_SORT:=0} -eq 1 ]
then
  GET_VIO_FCSTAT | sort | CALC_TOTALS
else
  GET_VIO_FCSTAT | sort -nrk6 | CALC_TOTALS
fi

IBM Systems Webinar Icon

View upcoming and on-demand (IBM Z, IBM i, AIX, Power Systems) webinars.
Register now →