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
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 }
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()
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
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/
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
Yes, that's
esxcli system visorfs get
or
$esxcli.system.visorfs.get()
in PowerCLI.
- Andreas
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
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.
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
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 }
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 - 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;
Sample data below;
SR-13266898201-inodes.csv
FreeInodePercent | LowestFreeInodePercent | PeakReservedInodes | PeakUnlinkedInodes | PeakUsedInodes | ReservedInodes | TotalInodes | UnlinkedInodes | UsedInodes | VMHost | Date |
68 | 67 | 2 | 10 | 2637 | 0 | 8192 | 0 | 2556 | myhost1.mydomain | 15/01/2013 16:15 |
68 | 66 | 2 | 10 | 2704 | 0 | 8192 | 0 | 2620 | myhost2.mydomain | 15/01/2013 16:15 |
SR-13266898201-ramdisk.csv
Free | Maximum | PeakUsed | RamdiskName | Reserved | ReservedFree | System | Used | VMHost | Date |
95 | 32768 | 12336 | root | 32768 | 95 | TRUE | 1528 | myhost1.mydomain | 15/01/2013 16:15 |
99 | 28672 | 312 | etc | 28672 | 99 | TRUE | 260 | myhost1.mydomain | 15/01/2013 16:15 |
100 | 196608 | 3952 | tmp | 2048 | 100 | FALSE | 0 | myhost1.mydomain | 15/01/2013 16:15 |
99 | 1078272 | 6224 | hostdstats | 0 | 0 | FALSE | 6224 | myhost1.mydomain | 15/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
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"}