VMware Cloud Community
jrmunday
Commander
Commander
Jump to solution

Free INODES and % free RAMDISK

Hi All,

I need to create a PowerCLI script to gather some informaion from 30x ESXi 5.0 hosts on a daily basis. Here is the equivalent information from a SSH session with the required information in red - but I want to get this without having to SSH onto every host and collate this manually;

~ # stat -f /

  File: "/"

    ID: 1        Namelen: 127     Type: visorfs

Block size: 4096

Blocks: Total: 449852     Free: 330092     Available: 330092

Inodes: Total: 8192       Free: 5562

~ # esxcli system visorfs ramdisk list

Ramdisk Name  System   Reserved      Maximum       Used  Peak Used  Free  Reserved Free

------------  ------  ---------  -----------  ---------  ---------  ----- -------------

root            true  32768 KiB    32768 KiB   1476 KiB   1596 KiB   95 %           95 %

etc             true  28672 KiB    28672 KiB    264 KiB    316 KiB  99 %           99 %

tmp            false   2048 KiB   196608 KiB      0 KiB    340 KiB  100 %          100 %

hostdstats     false      0 KiB  1078272 KiB  14212 KiB  14212 KiB  98 %            0 %

I am aware that the Get-EsxCli cmdlet exists, but have not managed to get it working successfully.

NAME
    Get-EsxCli

SYNOPSIS
    Exposes the ESXCLI functionality.

Is this possible, and if yes, please help with any pointers or ideally a basic script to gather the information - much appreciated!

Thasnk,

Jon

vExpert 2014 - 2022 | VCP6-DCV | http://www.jonmunday.net | @JonMunday77
Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

To get this information for all your hosts and also get the hostname use:

foreach ($VMHost in (Get-VMHost)) {
  $esxcli = Get-EsxCli -vmhost $VMHost
  $esxcli.system.visorfs.get() |
  Add-Member -MemberType NoteProperty -Name VMHost -Value $VMHost.Name -PassThru 
}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
10 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can get the information using the Get-EsxCLi cmdlet with:

$vmhost = Get-VMHost MyHost
$esxcli = Get-EsxCli -vmhost $vmhost
$esxcli.system.visorfs.ramdisk.list()

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
jrmunday
Commander
Commander
Jump to solution

Hi Robert,

Thanks very much for the quick response - this is perfect for what I need.

Do you know if a similar method is available to get the number of free inodes from the "stat -f /" command?

Thanks,

Jon

vExpert 2014 - 2022 | VCP6-DCV | http://www.jonmunday.net | @JonMunday77
Reply
0 Kudos
MKguy
Virtuoso
Virtuoso
Jump to solution

For shell commands such as this you would need to use putty/plink.exe like in this example:

http://www.virtu-al.net/2013/01/07/ssh-powershell-tricks-with-plink-exe/

http://www.shogan.co.uk/vmware/using-plink-to-modify-esxi-host-configuration-files-via-ssh-from-a-po...

Apart from that you could also leverage this awesome host VIB which extends esxcli to run any shell command:

http://www.v-front.de/2013/01/release-esxcli-plugin-to-run-arbitrary.html

-- http://alpacapowered.wordpress.com
Reply
0 Kudos
peetz
Leadership
Leadership
Jump to solution

Yes, that's

esxcli system visorfs get

or

$esxcli.system.visorfs.get()

in PowerCLI.

- Andreas

Twitter: @VFrontDe, @ESXiPatches | https://esxi-patches.v-front.de | https://vibsdepot.v-front.de
peetz
Leadership
Leadership
Jump to solution

Yes, my esxcli-shell plugin would also do the job 😉

But I think that "esxcli system visorfs get" provides the information that you also get through "stat -f /".

- Andreas

Twitter: @VFrontDe, @ESXiPatches | https://esxi-patches.v-front.de | https://vibsdepot.v-front.de
Reply
0 Kudos
peetz
Leadership
Leadership
Jump to solution

BTW, with ESXi 5.1 "esxcli system visorfs ramdisk list" will show additional columns with inode stats per filesystem/mountpoint.

With ESXi 5.0 you need to use "esxcli system visorfs get", and that will show the inode stats of all four RAMdisks (/, /etc, /tmp, and /var/lib/vmware/hostd/stats) summed up.

Twitter: @VFrontDe, @ESXiPatches | https://esxi-patches.v-front.de | https://vibsdepot.v-front.de
Reply
0 Kudos
jrmunday
Commander
Commander
Jump to solution

Thanks Andreas, this (and Roberts tip) give me exactly what I need;


PowerCLI C:\> $vmhost = Get-VMHost myhost.mydomain
PowerCLI C:\> $esxcli = Get-EsxCli -vmhost $vmhost
PowerCLI C:\> $esxcli.system.visorfs.get()


FreeInodePercent       : 67
LowestFreeInodePercent : 66
PeakReservedInodes     : 2
PeakUnlinkedInodes     : 9
PeakUsedInodes         : 2731
ReservedInodes         : 0
TotalInodes            : 8192
UnlinkedInodes         : 0
UsedInodes             : 2654

PowerCLI C:\> $esxcli.system.visorfs.ramdisk.list() | ft -au

Free Maximum PeakUsed RamdiskName Reserved ReservedFree System Used
---- ------- -------- ----------- -------- ------------ ------ ----
95   32768   12400    root        32768    95           true   1552
99   28672   316      etc         28672    99           true   264
100  196608  3952     tmp         2048     100          false  0
98   1078272 16536    hostdstats  0        0            false  16536

I can work with this, but as a last "wish list" can I include the hostname in the results so that when I collect this information for 30x hosts I know which set of data applies to which host?

Thanks,

Jon

vExpert 2014 - 2022 | VCP6-DCV | http://www.jonmunday.net | @JonMunday77
Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

To get this information for all your hosts and also get the hostname use:

foreach ($VMHost in (Get-VMHost)) {
  $esxcli = Get-EsxCli -vmhost $VMHost
  $esxcli.system.visorfs.get() |
  Add-Member -MemberType NoteProperty -Name VMHost -Value $VMHost.Name -PassThru 
}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
jrmunday
Commander
Commander
Jump to solution

Hi All,

Thanks very much for the help with script syntax and general support, here is the final result which can be improved from a coding perspective, but it does exactly what I need it to so I will use it as is Smiley Happy - hopefully someone else will find a use for it?

<#

NAME : Collect-VisorFS-data.ps1

AUTHOR : Jon Munday

DATE : 16/01/2013

PURPOSE : This script collects relevant VisorFS data and is intended to support a root cause analysis

for a situation where inodes are exhausted causing ESXi hosts to become disconnected from

vCenter. The issues is discussed in http://kb.vmware.com/kb/2037798

#>

## Show current date and time for start of script

Write-Host "START :"(Get-Date) -ForegroundColorYellow

## Location of Log files

$outfile_inodes ="C:\_Temp\SR-13266898201\logs\SR-13266898201-inodes-{0:yyyyMMdd-HHmm}.csv"-f(Get-Date)

$outfile_ramdisk ="C:\_Temp\SR-13266898201\logs\SR-13266898201-ramdisk-{0:yyyyMMdd-HHmm}.csv"-f(Get-Date)

## Create empty arrays

$results_inodes =@()

$results_ramdisk =@()

## Collect file system information for each host and populate the empty arrays

foreach ($VMHostin(Get-VMHost-Name*| Sort-ObjectName)) {

$esxcli =Get-EsxCli-vmhost$VMHost

Write-Host "Processing :"$VMHost-ForegroundColorGray

$results_inodes +=(

     $esxcli.system.visorfs.get() |

     Add-Member-MemberTypeNoteProperty-NameVMHost-Value$VMHost.Name -PassThru|

     Add-Member-MemberTypeNoteProperty-NameDate-Value(Get-Date) -PassThru) ;

 

$results_ramdisk +=(

      $esxcli.system.visorfs.ramdisk.list() |

     Add-Member-MemberTypeNoteProperty-NameVMHost-Value$VMHost.Name -PassThru|

     Add-Member-MemberTypeNoteProperty-NameDate-Value(Get-Date) -PassThru)

## Export results to CSV files

$results_inodes | Export-CSV-Path$outfile_inodes-NoTypeInformation

$results_ramdisk | Export-CSV-Path$outfile_ramdisk-NoTypeInformation

## Show log files for current execution

Write-Host "END :"(Get-Date) -ForegroundColorYellow

Write-Host ""

Write-Host "LOG :"$outfile_inodes-ForegroundColorGreen

Write-Host "LOG :"$outfile_ramdisk-ForegroundColorGreen

Write-Host ""

## Merge CSV files from the current run into a master file containing results of all previous iterations

Write-Host "Merging inode CSV data :"(Get-Date) -ForegroundColorYellow

$MASTER_outfile_inodes ="C:\_Temp\SR-13266898201\SR-13266898201-inodes.csv"

$MASTER_outfile_ramdisk ="C:\_Temp\SR-13266898201\SR-13266898201-ramdisk.csv"

Get-ChildItem "C:\_Temp\SR-13266898201\logs\*-inodes-*.csv"|

     ForEach-Object{Import-Csv$_} |

     Export-Csv-NoTypeInformation$MASTER_outfile_inodes

Write-Host "Merging ramdisk CSV data :"(Get-Date) -ForegroundColorYellow

Get-ChildItem"C:\_Temp\SR-13266898201\logs\*-ramdisk-*.csv"|

     ForEach-Object{Import-Csv$_} |

     Export-Csv-NoTypeInformation$MASTER_outfile_ramdisk

Write-Host ""

The script requires you to have a connection to vCenter and does the following;

  1. Collects required data from each host
  2. Logs the information into a CSV file
  3. Merges the data from the current execution into a masteCSV file with all the historical data from all your previous runs.

Sample data below;

SR-13266898201-inodes.csv

FreeInodePercentLowestFreeInodePercentPeakReservedInodesPeakUnlinkedInodesPeakUsedInodesReservedInodesTotalInodesUnlinkedInodesUsedInodesVMHostDate
686721026370819202556myhost1.mydomain15/01/2013 16:15
686621027040819202620myhost2.mydomain15/01/2013 16:15

SR-13266898201-ramdisk.csv

FreeMaximumPeakUsedRamdiskNameReservedReservedFreeSystemUsedVMHostDate
953276812336root3276895TRUE1528myhost1.mydomain15/01/2013 16:15
9928672312etc2867299TRUE260myhost1.mydomain15/01/2013 16:15
1001966083952tmp2048100FALSE0myhost1.mydomain15/01/2013 16:15
9910782726224hostdstats00FALSE6224myhost1.mydomain15/01/2013 16:15

I plan to execute this say every hour or two for period of time to see if I an correlate a specific event or sequence of events which lead up to the inodes being exhausted and production ESXi hosts becoming disconnected.

Thanks again for all your help!

Cheers,

Jon

vExpert 2014 - 2022 | VCP6-DCV | http://www.jonmunday.net | @JonMunday77
Reply
0 Kudos
GaryPichlerMN
Contributor
Contributor
Jump to solution

Jon-

I found your script, made some modifications...  It didn't work for me prior to mods, hope this helps anyone that might need it!

<#

NAME : Collect-VisorFS-data.ps1

AUTHOR : Jon Munday

DATE : 16/01/2013, updated 19/03/2015 (gp)

PURPOSE : This script collects relevant VisorFS data and is intended to support a root cause analysis

for a situation where inodes are exhausted causing ESXi hosts to become disconnected from

vCenter. The issues is discussed in http://kb.vmware.com/kb/2037798

#>

## Show current date and time for start of script

Write-Host "START :"(Get-Date)

## Location of Log files

$outfile_inodes = "C:\Temp\ramdisk\logs\inodes-{0:yyyyMMdd-HHmm}.csv" -f (Get-Date)

$outfile_ramdisk = "C:\Temp\ramdisk\logs\ramdisk-{0:yyyyMMdd-HHmm}.csv" -f (Get-Date)

## Create empty arrays

$results_inodes =@()

$results_ramdisk =@()

## Collect file system information for each host and populate the empty arrays

foreach ($VMHost in (Get-VMHost)) {

$esxcli = Get-EsxCli -vmhost $VMHost

Write-Host "Processing :" $VMHost

$results_inodes +=(

     $esxcli.system.visorfs.get() |

     Add-Member -Type NoteProperty -name VMHost -Value $VMHost.Name -PassThru|

     Add-Member -Type NoteProperty -name Date -Value (Get-Date) -PassThru) ;

$results_ramdisk +=(

      $esxcli.system.visorfs.ramdisk.list() |

     Add-Member -Type NoteProperty -name VMHost -Value $VMHost.Name -PassThru|

     Add-Member -Type NoteProperty -name Date -Value (Get-Date) -PassThru)

## Export results to CSV files

$results_inodes | Export-CSV -Path $outfile_inodes -NoTypeInformation

$results_ramdisk | Export-CSV -Path $outfile_ramdisk -NoTypeInformation

## Show log files for current execution

Write-Host "END :"(Get-Date)

Write-Host ""

Write-Host "LOG :"$outfile_inodes

Write-Host "LOG :"$outfile_ramdisk

Write-Host ""

## Merge CSV files from the current run into a master file containing results of all previous iterations

Write-Host "Merging inode CSV data :"(Get-Date)

$MASTER_outfile_inodes ="C:\Temp\ramdisk\inodes.csv"

$MASTER_outfile_ramdisk ="C:\Temp\ramdisk\ramdisk.csv"

Get-ChildItem "C:\Temp\ramdisk\logs\inodes-*.csv"|

     ForEach-Object{Import-Csv $_} |

     Export-Csv -NoTypeInformation $MASTER_outfile_inodes

Write-Host "Merging ramdisk CSV data :"(Get-Date)

Get-ChildItem "C:\Temp\ramdisk\logs\ramdisk-*.csv"|

     ForEach-Object{Import-Csv $_} |

     Export-Csv -NoTypeInformation $MASTER_outfile_ramdisk

Write-Host "Complete"}

Reply
0 Kudos