Hi again Guys, I have now completed my quick and dirty VMware PowerCLI script for collecting NFS latency Performance Counters from ESXi / vSphere and publishing these values into PRTG Monitor (Custom XML Sensor).
It was a couple of years ago I did some courses in programming so please bee nice ;-)
Once again I would like to thank (Sensei) LucD for all of his assistance all over the VMware forum(s).
Here are my script for others to use, please add any comments, optimizations or suggestions if I could do this a better way ;-)
Script:
$VIServer = "x.x.x.x"
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction "SilentlyContinue"
function InitializePCLI($VIServer) {
# add VMware PS snapin
if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {
Add-PSSnapin VMware.VimAutomation.Core
}
# Set PowerCLI to single server mode
#Set-PowerCLIConfiguration -DefaultVIServerMode Single -Confirm:$False
# connect vCenter server session
if ($VIServer -eq $null) {
Connect-VIServer $VIServer -Protocol https -User username -Password xxxx | Out-Null
} else {
Connect-VIServer $VIServer -Protocol https -User username -Password xxxx | Out-Null
}
}
InitializePCLI($VIServer)
$stat = "datastore.totalWriteLatency.average"
#$start = (Get-Date).AddDays(-5)
#$start = (Get-Date).AddMinutes(-1)
$start = (Get-Date).AddSeconds(-20)
echo '<?xml version="1.0" encoding="Windows-1252" ?>'
echo '<prtg>'
Get-Datastore | where {$_.Type -eq "NFS"} | %{
$dsName = $_.Name
$uuid = $_.ExtensionData.Info.Url.Split('/')[-2]
$colItems = Get-VMHost -Datastore $_ |
Get-Stat -Stat $stat -Start $start |
where {$_.Instance -eq $uuid} |
Select Timestamp,MetricId,Value,@{N="Datastore";E={$dsName}}
foreach ($objItem in $colItems) {
if ($_.Name -eq $dsName) {
echo '<result>'
echo "<channel>$dsName</channel>"
echo "<value>"$objItem.Value"</value>"
echo '</result>'
}
}
}
echo '</prtg>'
Thanks Joakim Lindgren
Add comment