Oraclue

Oracle internals, debugging and undocumented features

Script to show disk usage/allocation of VxVM/SEVM disk groups

I  used run this  script on Solaris …  You can customize it  e.g. ( to display certain groups only )

Usage: 

vxusage -a | -l | diskgroup_name 

#! /bin/sh
#
# @(#)vxusage – show disk usage/allocation of VxVM/SEVM disk groups
#
# $Id: vxusage,v 0.1 1998/01/27 23:05:03 seeger Exp seeger $
#
# WARNING: WORK IN PROGRESS!  Use only at your own risk!
#
# Typical invocation (ouput to stdout):
#
# vxusage -a | -l | diskgroup_name …
#
# Note: since vxprint is normally installed suid root, this script can
# be run by an unpriveleged user.
#

StartPATH=$PATH
ProgPATH=/usr/bin:/usr/sbin:/opt/bin:/local/bin:/local/sbin:/usr/ucb

PATH=$ProgPATH
export PATH
umask 022

Name=vxusage
Release=0
Revision=1
Patch=0
Version=$Release.$Revision.$Patch
VersionString=”$Name $Version”
###############################################################################
#
# Functions
#

ErrEcho() {
 echo “${ProgName}: Error: $*”   1>&2
}
Require() {
 while [ $# -gt 0 ]; do
  type ${1:-nocommand} > /dev/null || {
   ErrEcho “command \”$1\” not found”
   exit 1
  }
  shift
 done
}
###############################################################################
#
# Preconditions
#

#
# Required commands
#
#Require getopts basename cat getopts expr awk sed sort
Require vxprint
###############################################################################
#
# Usage Information and Command Line Processing
#

ProgName=`basename $0`

OptString=”VhAalqv”
Usage() {
cat << EOUsage
Usage: $ProgName -$OptString [ diskgroup … ]
 -a use all disk groups
 -l list all disk groups
EOUsage
}

#
# Process command line options.
#
while getopts “$OptString” _c_ ; do
 case “$_c_” in
 V) echo $Version ; exit 0 ;;
 h|\?) Usage ; exit 0 ;;
 a|A) DGList=ALL_DGs ;;
 l) DGList=LIST_DGs ;;
 q) quiet=True ;;
 v) verbose=True ;;
 *) ErrEcho “Unknown option \”-$_c_\”.” ; exit 1 ;;
 esac
done
shift `expr $OPTIND – 1`
unset _c_
###############################################################################
#
# main()
#

if [ “X${DGList:-}” = “XLIST_DGs” ]; then
 set — `vxprint -Gq | sed -n ‘s/^dg \([^ ]*\) .*/\1/p’`
 echo $@
 exit 0
elif [ “X${DGList:-}” = “XALL_DGs” ]; then
 DGList=`vxprint -Gq | sed -n ‘s/^dg \([^ ]*\) .*/\1/p’`
elif [ $# -eq 0 ]; then
 # XXX Hmmm.  Should the default be rootdg or the usage message?
 DGList=rootdg
else
 DGList=”$@”
fi
#
# XXX Be very careful about changing anything below here.
# XXX All the formatting is painfully interrelated, and proper
# XXX operation requires the correct sort order.
#

dmfmt=’dm:%{type} %{name:-14} 0 %{name:-14} %{device_tag:-9} %{len:11} %{iosize:5} %{sd_num:3} %{admin_state:-5} %{reserved:-3} %{removed:-3}’
sdfmt=’sd:%{type} %{dm_name:-14} %{dev_offset:11} %{name:-14} %{len:11} %{vname} %{plname}’

#
# XXX Unsophisticated reliance on “dm” sorting ahead of “sd”.
#
for DiskGroup in $DGList ; do
 echo “\nDisk usage for disk group \”${DiskGroup}\”\n”
 vxprint -Gds -F “$dmfmt” -F “$sdfmt” -g $DiskGroup \
 | sort -k 2,2 -k 3n,3n \
 | awk ‘ BEGIN { PERMEG = 1 / ( 1024 * 1024 ) }
  /^dg / { dgname = $4 }
  /^dm / {
   if ( disksize > 0 ) {
    totalfree += free
    printf (“%-28s %11.3f MB (%6.2f%%)%s\n\n”, \
     diskname ” Free Space: “, \
     free*mbps, 100*free/disksize, tags)
   }
   diskname = $2
   devtag = $5
   disksize = $6
   iosize = $7
   sdnum = $8
   state = $9
   reserved = $10
   removed = $11
   totalsize += disksize
   free = disksize
   mbps = iosize * PERMEG
   # Handle some special cases, like SPARE drives.
   extra = “”
   tags = “”
   if ( state != “-” ) { tags = tags ” ” state }
   if ( reserved == “on” ) { tags = tags ” reserved” }
   if ( removed == “on” ) { tags = tags ” removed” }
   if ( length(tags) > 0 ) {
    tags = sprintf(“%1s%s”, “”, tags)
    extra = sprintf(“%10s%s”, “”, tags)
   }
   printf (“%-28s %11.3f MB%s\n”, \
    diskname ” (“devtag”)”, disksize*mbps, extra)
  }
  /^sd / {
   sdoffset = $3
   sdname = $4
   sdsize = $5
   volname = $6
   plexname = $7
   sdcount += 1
   free -= sdsize
   printf (”  %-14s %11.3f %11.3f MB (%6.2f%%)  %s\n”, \
    sdname, sdoffset*mbps, sdsize*mbps, \
    100*sdsize/disksize, volname “:” plexname)
  }
  END {
   printf (“%-28s %11.3f MB (%6.2f%%)%s\n\n”, \
    diskname ” Free Space: “, \
    free*mbps, 100*free/disksize, tags)
   printf (“%-26s %13.3f MB\n”, \
    “Disk Group Size (“dgname”):”, totalsize*mbps)
   printf (“%-26s %13.3f MB (%6.2f%%)\n\n”, \
    “Disk Group Free (“dgname”):”, \
    totalfree*mbps, 100*totalfree/totalsize)
  }’
done

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: