Operating System - HP-UX
1833770 Members
2178 Online
110063 Solutions
New Discussion

Re: Calculating Disk usage

 
SOLVED
Go to solution
Sonison James
Frequent Advisor

Calculating Disk usage

Hello,

Given a PV I have to calculate the sum of free space on all file systems on that PV. I need to do this programatically, so API(s) would be really helpful.

Thanks and regards
Sonison James
10 REPLIES 10
Sridhar Bhaskarla
Honored Contributor
Solution

Re: Calculating Disk usage

Hi,

See if this small script helps you.

#!/usr/bin/ksh
if [ $# -ne 1 ]
then
echo "Usage: $0 PV"
exit
fi

/usr/sbin/pvdisplay -v $1 > /tmp/pv$$ 2>&1

if [ $? != 0 ]
then
echo "$1 is not a PV"
exit
fi

for LV in $(awk '/current/ {print $3}' /tmp/pv$$|sort|uniq)
do
bdf $LV > /tmp/pv$$ 2>&1
if [ $? = 0 ]
then
FREE=$(df -k $LV|awk '/free/ {print $1}')
echo $LV ${FREE} KB
else
echo "$LV failed"
fi
done

rm /tmp/pv$$

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Con O'Kelly
Honored Contributor

Re: Calculating Disk usage

Hi

Not entirely sure what you are trying to achieve but the following may help.

First you need to determine which filesystems are on that PV.
Issue the following command:
# pvdisplay -v

This will show you which LV's are using space on that PV. You can then do a bdf and look at the free space for that LV (filesystem). Remember that LV's (filesystems) can span multiple disks. You can check which PV's an LV is using by:
# lvdisplay -v
eg lvdisplay -v /dev/vg01/lvol3

To calculate how much free space is on the PV look for "Free PE" value in the pvdisplay output.
You need to multiply the Free PE value by the PE size (this can seen in the vgdisplay output) to get free space on the PV in Mbytes.

I have attached a script which may help you in analysing your disk usage.

Cheers
Con
Sonison James
Frequent Advisor

Re: Calculating Disk usage

Hello,

Sri your script seems to solved my problem except for some 'failed' messages that I get for some LVs. Please see the output that I got for one PV:

[james@c test]$ ./diskinfo /dev/dsk/c1t15d0
/dev/vg00/lv_cpifs 926844 KB
/dev/vg00/lv_i2nj 4462177 KB
/dev/vg00/lvol1 211224 KB
/dev/vg00/lvol2 failed
/dev/vg00/lvol3 123224 KB
/dev/vg00/lvol4 176480 KB
/dev/vg00/lvol5 278864 KB
/dev/vg00/lvol6 147752 KB
/dev/vg00/lvol7 303280 KB
/dev/vg00/lvol8 1197752 KB

Am I doing something wrong or is there an error?

Thanks and regards
Sonison James
twang
Honored Contributor

Re: Calculating Disk usage

Attached sysinfo is a very good utility which allow you to collect hpux information, of course you can collect only PHYSICAL DISK DATA.
Kenneth_19
Trusted Contributor

Re: Calculating Disk usage

Hi,

Since /dev/vg00/lvol2 is the primary swap to most HP-UX machines, therefore it is not a filesystem and hence it fails during bdf.

So in other words, those "failed" LVs are not filesystems but raw devices.

Hope this can help.

Kenneth
Always take care of your dearest before it is too late
twang
Honored Contributor

Re: Calculating Disk usage

Sorry, I uploaded a wrong script.
twang
Honored Contributor

Re: Calculating Disk usage

-
Con O'Kelly
Honored Contributor

Re: Calculating Disk usage

Hi
lvol2 will fail in vg00 as it is primary swap, nothing to worry about.
Sri - thats a nice script.

Should have mentioned my script is only designed if bdf output is on one line.

Cheers
Con
Sridhar Bhaskarla
Honored Contributor

Re: Calculating Disk usage

Hi Sonison,

If any of the logical volumes is not a filesystem, then it cannot calculate the free space and will display the message "failed". If you don't like the word "failed", replace it with "undetermined" in the script. I wrote it on the fly to give you an idea so I didn't pay much attention to the messages.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sonison James
Frequent Advisor

Re: Calculating Disk usage

Hello,

Kenneth, Sri and Con thanks for the information, this has solved my problem. Twang thanks for the script.

Regards
Sonison James