Had a request to find out how much space each LUN was using.

by New Contributor on ‎2010-06-30 10:05 AM

Have a customer that want to see how much space each LUN was consuming. He was comfortable with Thin Provisioning his LUNs only if he could do a quick query to find out what his average occupied space was per LUN. I wrote upa quick sample script that does just this.

Sample Output of the Script is as follows.

LUN =  /vol/DPDataSet1/test1  : LUN Size =  107374182400 : Used Size =  0 : % used =  0 %

LUN =  /vol/DPDataSet1/SetB  : LUN Size =  2147587706880 : Used Size =  155582464 : % used =  0.01 %

LUN =  /vol/DPDataSet1/SetA  : LUN Size =  2145416232960 : Used Size =  912173178880 : % used =  42.52 %

Script content is below.

# Quick and Dirty Script to Determine the Oversubscription rate of Thinly provisioned LUNs on a Target Filer.

$Filer = "10.58.92.xyz"

$pass = ConvertTo-SecureString "password" -AsPlainText -Force

$admin = "administrator"

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $admin,$pass

Connect-naController $Filer -credential $cred

$LunList = Get-NaLun

Foreach ($LUN in $LunList)

{

      [single]$perc=100 * ([single]((get-nalunoccupiedsize $LUN.path)) /[single]($LUN.Size))

      $perc=[math]::Round($perc,2)

      Write-Host "LUN = " $LUN.path " : LUN Size = " $LUN.size          -nonewline

      write-host " : Used Size = " (get-nalunoccupiedsize $LUN.path)    -nonewline

      Write-Host " : % used = " $perc "%"

Chris Lionetti

Reference Architect

Microsoft Alliance Engineering

lionetti@netapp.com

OK. Here is the update to Version 2.0. I had some requests to make it more readable by using GB instead of Bytes, and to show the Oversubscription rating of the Volumes and not just the LUNs. I added some highlighting in the test to the all importaint oversubscription rating of both the Volumes and the Aggrs.

This script also now groups the LUNs into the volumes and groups the volumes into the Aggrs. It will walk through every Aggr on the array.

Most of the code is really about formating the output, without that it would be a very easy script to read.

Output of the Script is as follows.

Aggr Start      -  aggr0 : Aggr Size =  12737.9 GB : Used Size =  850.6 GB : % used =  7 %

      Vol Start -  Test1 : Vol Size =  20 GB : Used Size =  0 %

          LUN   =  /vol/Test1/Testlun2 : Size =  10 GB : Used =  0 GB =  0%

          LUN   =  /vol/Test1/TestLUN1 : Size =  5 GB : Used =  0 GB =  0%

      Vol End   -  Test1 : Vol Subscribed =  15 GB OverSubscribed Ratio =  0.8 :1

      Vol Start -  vol0 : Vol Size =  537.3 GB : Used Size =  0.19 %

      Vol End   -  vol0 : Vol Subscribed =  0 GB OverSubscribed Ratio =  0.0 :1

      Vol Start -  DPMDataSet1 : Vol Size =  1999 GB : Used Size =  10.83 %

          LUN   =  /vol/DPMDataSet1/test1 : Size =  100 GB : Used =  0 GB =  0%

          LUN   =  /vol/DPMDataSet1/SetB : Size =  2000.1 GB : Used =  3.9 GB =  0.2%

          LUN   =  /vol/DPMDataSet1/SetA : Size =  1998.1 GB : Used =  860.2 GB =  43.05%

      Vol End   -  DPMDataSet1 : Vol Subscribed =  4098.2 GB OverSubscribed Ratio =  2.1 :1

Aggr End        -  aggr0 : SubScribed =  4113.2 GB OverSubscribed Ratio =  0.3 :1

Script content is below.

# Quick and Dirty Script to Determine the Oversubscription rate of Thinly provisioned LUNs

# on a Target Filer.

$Filer = "10.58.92.120"

$pass = ConvertTo-SecureString "Netapp11" -AsPlainText -Force

$admin = "administrator"

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $admin,$pass

Connect-naController $Filer -credential $cred

$aggrlist = Get-NAAggr

Foreach ($aggr in $aggrlist){

      [double]$AggrOverSub=1

      Write-Host "Aggr Start      - " $aggr.Name -NoNewline

      Write-host " : Aggr Size = " ([Math]::Round(($aggr.SizeTotal/(1024*1024*1024)),1))"GB" -nonewline

      Write-host " : Used Size = " ([Math]::Round($aggr.SizeUsed/(1024*1024*1024),1))"GB" -nonewline

      Write-host " : % used = " $aggr.SizePercentageUsed"%"

      $LunList = Get-NaLun

      $Vollist = Get-NaVol

      ForEach ($volume in $Vollist)

      {     [double]$VolOverSub=1

            $vol = (get-navol $volume.name)

            [single]$perc=100 * ([single]($vol.SizeUsed) /[single]($vol.SizeTotal))

            $perc=[math]::Round($perc,2)

            if ($aggr.name -eq $vol.containingaggregate )

            {     Write-Host "      Vol Start - " $vol.Name -NoNewline

                  Write-host " : Vol Size = " ([math]::round(($volume.SizeTotal/(1024*1024*1024)),1))"GB" -nonewline

                  Write-host " : Used Size = " $Perc "%"

                  Foreach ($LUN in $LunList)

                  {     $Sour=$LUN.Path

                        if ($Sour.Contains($vol.name))

                        {     [single]$perc=100 * ([single]((get-nalunoccupiedsize $LUN.path)) /[single]($LUN.Size))

                              $perc=[math]::Round($perc,2)

                              Write-Host "          LUN   = " $LUN.path -NoNewline

                              Write-Host " : Size = " ([Math]::Round(($LUN.size/(1024*1024*1024)),1))"GB" -NoNewline

                              Write-Host " : Used = " ([Math]::Round( ((get-nalunoccupiedsize $LUN.path)/(1024*1024*1024)),1))"GB" -NoNewline

                              Write-Host " = " $perc"%"

                              $VolOverSub=$VolOverSub+[double]$LUN.Size

                        }

                  }

                  Write-Host "      Vol End   - " $vol.Name -NoNewline

                  Write-Host " : Vol Subscribed = " ([Math]::Round(($VolOverSub/(1024*1024*1024)),1))"GB"  -NoNewline

                  Write-Host " OverSubscribed Ratio = " ([Math]::Round(($VolOverSub/$Vol.SizeTotal),1))":1"

                  $AggrOverSub=$AggrOverSub+$VolOverSub

            }

      }   

      Write-Host "Aggr End        - " $aggr.Name -NoNewline

      Write-host " : SubScribed = " ([Math]::Round(($AggrOverSub/(1024*1024*1024)),1))"GB" -NoNewline

      Write-host " OverSubscribed Ratio = " ([Math]::Round(($AggrOverSub/$aggr.SizeTotal),1))":1"

}   

Comments

Thanks for the script lionetti.  Though i had an error using the script. Becuase you used the Contains condition here

Foreach ($LUN in $LunList)

                  {     $Sour=$LUN.Path

                       if ($Sour.Contains($vol.name))

                        {     [single]$perc=100 * ([single]((get-nalunoccupiedsize $LUN.path)) /[single]($LUN.Size))

I had an issue with it matching some Luns to additional Volumes.  These volumes also had part of the right volume name so the "contains" condition was matching it eg see below.  The exch luns where correctly matched to the ExchData volume but incorrectly to Data.


Vol :  ExchData : Vol Size =  200 GB : Used Size =  50.12 %
       LUN:  =  /vol/ExchData/exchdata.lun : Size =  50 GB : Used =  10 GB =  20.09%
       LUN:  =  /vol/ExchData/exchlogs.lun : Size =  12 GB : Used =  12 GB =  99.92%
       LUN:  =  /vol/ExchData/exchpf.lun : Size =  5 GB : Used =  0.1 GB =  1.04%
    Vol :  Data : Vol Size =  96 GB : Used Size =  44.02 %
       LUN:  =  /vol/ExchData/exchdata.lun : Size =  50 GB : Used =  10 GB =  20.09%
       LUN:  =  /vol/ExchData/exchlogs.lun : Size =  12 GB : Used =  12 GB =  99.92%
       LUN:  =  /vol/ExchData/exchpf.lun : Size =  5 GB : Used =  0.1 GB =  1.04%

I arent 100% sure this is the correct way of doing this(i am a pretty bad scripting person) but it worked for me but i changed my Script to split the path to an array and matched based on an exact match to get around this to,

foreach ($LUN in $LunList)
                  {     $Sour=$LUN.Path
                        $spath = $Sour.Split("/")
                        if ($spath[2].equals($vol.name))

                        {     [single]$perc=100 * ([single]((get-nalunoccupiedsize $LUN.path)) /[single]($LUN.Size))

This correctly returns me

Vol :  ExchData : Vol Size =  200 GB : Used Size =  50.23 %
       LUN:  =  /vol/ExchData/exchdata.lun : Size =  50 GB : Used =  10 GB =  20.09%
       LUN:  =  /vol/ExchData/exchlogs.lun : Size =  12 GB : Used =  6.1 GB =  50.49%
       LUN:  =  /vol/ExchData/exchpf.lun : Size =  5 GB : Used =  0.1 GB =  1.04%
      Vol :  Data : Vol Size =  96 GB : Used Size =  44.02 %   

Warning!

This NetApp Community is public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available. This includes the rich text editor which is not encrypted for https.

In accordance to our Code of Conduct and Community Terms of Use DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.