#!/usr/bin/perl # Author: # Alexander Kuehn # print summary over dg usage on Vertas LVM # Artistic license (same as Perl) # version 1.0 2008-08-20 use strict; use English; #use Data::Dumper; #my @data = `cat vxprint.txt`; my @data = `vxprint -A`; # all information goes here # $infohash{$dg}{"size"} # @infohash{$dg}->lvols # $infohash{$dg}->lvols->$lvol->size # $infohash{$dg}->lvols->$lvol->fsgen my %infohash; my ($current_dg,$lvol); for (@data) { if (/^dg\ (\w+)/){ # new diskgroup? $current_dg=$1; $infohash{$current_dg}{"size"}=0; @{$infohash{$current_dg}{"lvols"}}=(); } elsif (/^dm\ /){ # collect disks for current dg my @t=split(/\s+/, $POSTMATCH); $infohash{$current_dg}{"size"}+=$t[3]; } elsif (/^v\ \ (\w+)/){ # new volume in current dg $lvol=$1; push (@{$infohash{$current_dg}{"lvols"}}, $lvol); my @t=split(/\s+/, $POSTMATCH); $infohash{$current_dg}{$lvol}{"fsgen"}=$t[3]; } elsif (/^pl\ /){ # plex for lvol my @t=split(/\s+/, $POSTMATCH); $lvol=$t[1]; $infohash{$current_dg}{$lvol}{"size"}=$t[3]; } } # calculate available space & do the printing print " dg size(MB) avail(MB) in% volume(s) fs-space(MB)\n"; foreach $current_dg (sort keys %infohash) { $infohash{$current_dg}{"avail"}=$infohash{$current_dg}{"size"}; $infohash{$current_dg}{"fsspace"}=0; for (@{$infohash{$current_dg}{"lvols"}}) { $infohash{$current_dg}{"avail"}-=$infohash{$current_dg}{$_}{"size"}; $infohash{$current_dg}{"fsspace"}+=$infohash{$current_dg}{$_}{"fsgen"}; } printf ("%6s %10s %10s %3d%% %4d %10s\n", $current_dg, fmt_int($infohash{$current_dg}{"size"}/1024), fmt_int($infohash{$current_dg}{"avail"}/1024), 100*$infohash{$current_dg}{"avail"}/$infohash{$current_dg}{"size"}, scalar @{$infohash{$current_dg}{"lvols"}}, fmt_int($infohash{$current_dg}{"fsspace"}/1024)); } # simplistic number formatting to insert the thousands delimiter sub fmt_int($) { my $t=int shift; my $s; do { $s=$t; $t=~s/(\d)(\d{3})(\D|$)/$1,$2$3/g; } while ($t!=$s); return $t; } #print Dumper(%infohash);