What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

How can I count the number of Virtual Machines running in my vSphere environment?

Votes:

0

Is there a sensor in PRTG to count the number of VMs that are running on my servers?

count custom-script-exe prtg vmware vmware-monitoring

Created on Jan 16, 2017 12:26:07 PM by  Dieter Loskarn [Paessler Support]

Last change on Aug 7, 2019 7:11:07 AM by  Maike Guba [Paessler Support] (2,404) 2 1



5 Replies

Accepted Answer

Votes:

1

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)"
}

Created on Jan 16, 2017 12:30:00 PM by  Dieter Loskarn [Paessler Support]

Last change on Sep 11, 2019 5:32:07 AM by  Maike Guba [Paessler Support] (2,404) 2 1



Votes:

0

Hi,

I am trying this script, but it gets a System Error: Please enter the VMware user and password in the device (code: PE022). Other sensors are working on same device.

What might be wrong?

Regards

Created on Jun 16, 2017 12:36:57 AM



Votes:

0

As this is a custom script and you can’t use the vCenter-Credentials via placeholders within parameters please enter the credentials in the linux-part of the sensor settings page. Now you can use the parameter string as described (‘-server %host -user %linuxuser -pass %linuxpassword’)

Please keep in mind that this solution is to hide the password from other users who may be allowed to see the parameter settings for this sensor. If you don’t have such users a parameter string like ‘-server %host -user readonlyuser -pass readonlypass’ may be valid for you too but this is not recommended for obvious reasons.

Best regards, Dieter

Created on Jun 19, 2017 12:34:38 PM by  Dieter Loskarn [Paessler Support]



Votes:

0

Great script.

How can you show number of VMs on each host.?

Regard

Created on Jul 6, 2021 11:37:20 AM



Votes:

0

Hi ishelpPRTG,

You can add one of these custom sensors to each of your ESXi-hosts and then collect the distribution of VMs on your hosts in an additional sensor-factory sensor.

There are other ways to monitor the number of VMs on each host in a single sensor as separate channels but this will need additional software installations on your PRTG server (PowerCLI).

Kind regard, Dieter

Created on Jul 6, 2021 1:39:16 PM by  Dieter Loskarn [Paessler Support]

Last change on Jul 6, 2021 1:39:32 PM by  Dieter Loskarn [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.