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 :smileyhappy: - 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;
- Collects required data from each host
- Logs the information into a CSV file
- 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
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