VMware Datastore Information in VCenter:
As the Solarwinds does not currently collect VMware Datastore usage information using the VMware API as shown above I created a Windows PowerShell Script to collect these information and write to Solarwinds Database – NetPerfMon. Then build a SQL report in Solarwinds shown below:
Steps:
(1) Create a table to store Datastore Information in Solarwinds Database – NetPerfMon
(2) On the Solarwinds server (or a polling engine), Install VMware vSphere PowerCLI (You can download it from https://my.vmware.com/web/vmware/details?productId=285&downloadGroup=VSP510-PCLI-510)
(3) Create a PowerShell script to get Datastore Information from a Vcenter (not from VM host) and save to Solarwinds Database – NetPerfMon
################### GetDatastoreInfo.ps1 #####################################
##### Add VMWare Snanpin.
if(-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue))
{
Add-PSSnapin VMware.VimAutomation.Core
}
$MB_TO_GB = 1024
$report = @()
$rowValues = @()
##### Get VC connected. ######################
$VCServer = "your-vcener-ip-or-name"
$VCUserName = "vcenter-user-name"
$VCPassword = "vcenter-password"
$VCconnection = Connect-VIServer $VCServer -Protocol https -User $VCUserName -Password $VCPassword -ErrorAction SilentlyContinue
##### Get Datastore Information ##################
$allDataStores = Get-Datastore
foreach ($dStore in $allDataStores) {
$row = $VCServer + "," + $dStore.Datacenter + "," + $dStore.UID + "," + $dStore.Name + "," + $dStore.Type + "," + [int]($dStore.CapacityMB/$MB_TO_GB*10)/10.0 + "," + [int]($dStore.FreeSpaceMB/$MB_TO_GB*10)/10.0 + "," + [int](($dStore.FreeSpaceMB/$dStore.CapacityMB)*1000)/10.0 + "," + [System.DateTime]::Now
$report += $row
}
Disconnect-VIServer $VCServer -Confirm:$False -ErrorAction SilentlyContinue
##### Write to NetPerfMon database #########################
### open database connection
$SQLServer = "your-solarwinds-sql-server-name-or-ip" #use Server\Instance for named SQL instances!
$SQLDBName = "NetPerfMon"
$SQLDBUser = "db-username"
$SQLDBPwd = "db-password"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; user id=$SQLDBUser;password=$SQLDBPwd"
$SqlConnection.Open()
### instet rows
$Sqlcmd = $SqlConnection.CreateCommand()
foreach ($currentRow in $report){
$rowValues = $currentRow.Split(",")
$InsertStatement = "INSERT [dbo].[VIM_DatastoreInfo] VALUES ( "
$InsertStatement = $InsertStatement + "'" + $rowValues[0] + "','" + $rowValues[1] + "','" + $rowValues[2] + "','" + $rowValues[3] + "','" + $rowValues[4] + "'," + $rowValues[5] + "," + $rowValues[6] + "," + $rowValues[7] + ",'" + $rowValues[8] + "')"
#### Write-Host $InsertStatement --- test code
$Sqlcmd.CommandText = $InsertStatement
$Sqlcmd.ExecuteNonQuery()
}
$SqlConnection.Close()
###########################################
(4) Run the PowerShell script as a schedule task
(5) Create a Solarwinds report
Tested in Solarwins NPM 10.4 & VMware 4 & 5
Thanks