Calculate total usage in AIX volume group

When looking at the output of the “lsvg” command in AIX, you’ll see a whole bunch of information regarding the volume group. The PP size, how many PPs are in the volume group, stale PVs, quorum, so on and so on. What I’m normally looking for when running the “lsvg” command is:

1. How much storage (PPs) do I have free.
2.How much storage (PPs) is in use.
3.How much storage (PPs) is actually being used.

I can get the first two questions answered looking at the output of “lsvg”, but the last one I cannot.

Now, lets take a look at the following “lsvg” output:

root@AIX / > lsvg data
VOLUME GROUP:       data                     VG IDENTIFIER:  000771a50000d6000000011bd8f66761
VG STATE:           active                   PP SIZE:        128 megabyte(s)
VG PERMISSION:      read/write               TOTAL PPs:      13410 (1716480 megabytes)
MAX LVs:            256                      FREE PPs:       7729 (989312 megabytes)
LVs:                12                       USED PPs:       5681 (727168 megabytes)
OPEN LVs:           12                       QUORUM:         4
TOTAL PVs:          6                        VG DESCRIPTORS: 6
STALE PVs:          0                        STALE PPs:      0
ACTIVE PVs:         6                        AUTO ON:        yes
MAX PPs per VG:     30480
MAX PPs per PV:     3048                     MAX PVs:        10
LTG size (Dynamic): 256 kilobyte(s)          AUTO SYNC:      no
HOT SPARE:          no                       BB POLICY:      relocatable

“Used PPs” tells us that 727GB has been allocated to filesystems in the “data” volume group. However, the output of a “df -vg” shows that only a little over 250GB is actually being used.

This information is helpful to know when you’re struggling to find space to increase filesystems, or allocate space for a new one. It’s good to know exactly how much a filesystem is consuming of the potential data allocation in the volume group itself, and how much can be taken for other filesystems to fulfill the allocation request.

Unless there is an AIX command which I haven’t stumbled across yet, you need to work all this out by doing the following.

1. Do a “lsvg -l ” to find out which filesystems belong to the volume group.
2. Do a “df -vg” on each of the filesystems to see how much is actually being used.
3. Add all the values together to get the total sum.

Pain in the ass if you ask me, and the resolution is the exact reason why task automation via shell scripting is great.

Here is a script that I wrote called “vgusage”. Put it in /usr/bin and “chmod +x” it.

#!/usr/bin/ksh
#
# Script calculates total usage in a volume group
# and not just space allocated to filesystems.
 
# Create usage function
usage() {
        echo "USAGE: $0 [k|m|g] [vg]"
}
 
# Case statement to assign SIZE var
case $1 in
        k)
          SIZE=$1
          SIZEB=KB
          ;;
        m)
          SIZE=$1
          SIZEB=MB
          ;;
        g)
          SIZE=$1
          SIZEB=GB
          ;;
        *)
          usage
          exit 1
          ;;
esac
 
# Check if $2 exists and assign VG var
if [ -z "$2" ]; then
  usage
  exit 1
else
  VG=$2
fi
 
 
# Check that volume group exists
lsvg $VG > /dev/null 2>&1
if [ $? -ne 0 ]; then
  echo "Volume group [$VG] does not exist."
  exit 1
fi
 
# Create array of all filesystems in volume group
set -A fsname `lsvg -l $VG | awk '{ print $7 }' | awk 'NR!=1' | grep -vE 'LV|N/A'`
 
# Create array of all filesystem sizes in volume group
count=0
while (( $count < ${#fsname[*]} )); do
           fssize[$count]=`df -v$SIZE "${fsname[$count]}" | awk 'NR!=1' | awk '{ print $3 }'`
        let count="count + 1"
done
 
 
# Array loop to print FS and SIZE
count=0
printf "%-30s %s\n" ---------- -------
printf "%-30s %s\n" Filesystem Size-$SIZEB
printf "%-30s %s\n" ---------- -------
while (( $count < ${#fsname[*]} )); do
           printf "%-30s %s\n" ${fsname[$count]} ${fssize[$count]}
        let count="count + 1"
done
 
# Calculate totals
TOTAL=`echo ${fssize[*]} | awk 'BEGIN {RS=" "} {SUM+=$1} END {print SUM}'`
 
 
printf "%-30s %s\n" ----- --------
printf "%-30s %s\n" Total $TOTAL
printf "%-30s %s\n" ----- --------
 
exit 0

The script takes two parameters. The first being the block value (KB, MB, GB), and the second being the name of the volume group.

root@AIX / > vgusage
USAGE: /usr/bin/vgusage [k|m|g] [vg]

Script being run on the data volume group with the output in GB blocks.

root@AIX / > vgusage g data
----------                     -------
Filesystem                     Size-GB
----------                     -------
/u02                           148.68
/ora/repagg/data01             12.39
/ora/repagg/data02             32.79
/ora/repagg/data03             14.84
/ora/repagg/data04             11.02
/ora/repagg/redo01             0.29
/ora/repagg/redo02             0.29
/app                           0.38
/app/backup                    29.71
/ora/repagg/dat                0.01
/u03                           0.64
-----                          --------
Total                          251.04
-----                          --------

As always, post any questions to the comments.

6 thoughts on “Calculate total usage in AIX volume group

  1. Hi, Very helpful script but, just want to know how to run the same script sitting on a A node to B node instead of copying this script to B node and excute it from there.

    • Hi Laszlo,

      Not in its current form, but the script can easily be modified to include an exclude function. If you’re familiar with scripting, you’re welcome to modify it…if you want a hand with doing it, then I can assist.

      -Kristijan

      • Hi Kristijan,

        In the meantime I just thought it over and due to the variety of the FS to be excluded from the calculation, custom on each of the servers, so not worth to make it happen.

        It’s easier to drop the outcome into an excel sheet and remove the unwanted lines (FS) then re-calculate the total.

        Anyway. Thank you for the script, it’s a great help for me.

        Regards,

        Laszlo

Leave a Reply

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.