This article applies to PRTG Network Monitor 19 or later
How to Monitor the Number of Running Virtual Machines
Currently, there is no built-in sensor in PRTG but you can use the following script to determine the number of virtual machines running on your servers. The script is a wrapper that runs a metascan that is normally used in the Add Sensor dialog.
Simply copy and paste the following code into a new .ps1 file and save it to the \Custom Sensors\EXE subfolder of your PRTG program directory. Then add a new EXE/Script sensor to your PRTG installation using this script on the device you want to monitor the number of virtual machines. This is your vCenter server or vSphere host.
For example, you can place a sensor tht counts VMs on each host in your cluster and additionally add a Sensor Factory sensor to your vCenter server that
- a) accumulates the number of VMs to a total value.
- b) accumulates the number of VMs to one channel per dedicated sensor on the hosts.
This way, you can monitor moving VMs per vMotion on your systems.
If you add channels for host CPU and RAM usage to this sensor, you will get a picture of DRS efficiency, too.
Note: If you want to run the script on a remote probe, it is necessary to place the script on the computer that runs the remote probe.
Script
param(
[string]$user,
[string]$pass,
[string]$server
)
######
#
# add this script as an exe-sensor with the following parameters
# -server %host -user %linuxuser -pass %linuxpassword
#
# You can use linux-credentials to hide the password used to access the vSphere-Server.
# You need read-only permissions only to retrieve the number of vms.
#
######
# determine the path for the script to build a relative absolute path to 'vmwaresensor.exe'
$scriptpath = Split-Path $script:MyInvocation.MyCommand.Path
# run a regular 'MetaScan' that returns all machines located on the target server
$vms = & "$($scriptpath)\..\..\Sensor System\VMWareSensor.exe" -s="$($server)" -u="$($user)" -p="$($pass)" -meta -type=vm
try {
# load the result-text as xml
$vmsxml = [xml]$vms
# if an error occured
if ($vmsxml.prtg.SelectNodes("error").count -eq 1) {
$errortext = $vmsxml.prtg.SelectNodes("text").innertext.trim()
# return the message to PRTG
write-host "-1:$($errortext)"
# else
} else {
$vmcount = ($vmsxml.prtg.SelectNodes("result")).count
# return the number of machines
write-host "$($vmcount):OK"
}
} catch {
write-host "-1:An Error occured, please check the sensor manually; $($_.Exception.Message) at Line $($_.invocationinfo.ScriptLineNumber)"
}
Add comment