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

Scripted Multi Sensor Addition

Votes:

0

Hi

I have the following script (I know the output format isn't correct) that I would like to use to monitor a Hyper-v Cluster.

Script Start
==========
function Get-ClusterVM {

[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true,HelpMessage="Name of the Cluster to fetch inventory from",
ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[System.String]
$ClusterName
)

process {

$Cluster = Get-Cluster -Name $ClusterName
$HVHosts = $Cluster | Get-ClusterNode

foreach ($HVHost in $HVHosts) {
    Get-VM -Computer $HVHost | where {$_.ResourceMeteringEnabled -like "False"} | Enable-VMResourceMetering 
	$VMs = Get-VM -Computer $HVHost | Measure-VM
	foreach ($VM in $VMs) {
		write-host "*********"
		write-host "VMName: "$VM.VMName
        write-host "AvgCPU(Mhz): "$VM.AvgCPU
        write-host "AvgRAM(M): "$VM.AvgRAM
        write-host "AggregatedAverageNormalizedIOPS: "$VM.AggregatedAverageNormalizedIOPS
        write-host "AggregatedAverageLatency: "$VM.AggregatedAverageLatency
        write-host "AggregatedDiskDataRead: "$VM.AggregatedDiskDataRead
        write-host "AggregatedDiskDataWritten: "$VM.AggregatedDiskDataWritten
        write-host "MeteringDuration: "$VM.MeteringDuration
        $InboundTraffic = ($VM.NetworkMeteredTrafficReport | where {($_.Direction -eq "Inbound")} | measure-object TotalTraffic -sum).sum
        $OutboundTraffic = ($VM.NetworkMeteredTrafficReport | where {($_.Direction -eq "Outbound")} | measure-object TotalTraffic -sum).sum
        write-host "InboundTraffic(M): "$InboundTraffic
        write-host "OutboundTraffic(M): "$OutboundTraffic

        $TotalIO = ($VM.AggregatedDiskDataRead + $VM.AggregatedDiskDataWritten)
        if ($TotalIO -eq "0") {
           $ReadPercent = "0"
           $WritePercent = "0"
        }
        else {
        $ReadPercent = ($VM.AggregatedDiskDataRead/$TotalIO)*100
        $ReadPercent = [math]::round($ReadPercent)
        $WritePercent = ($VM.AggregatedDiskDataWritten/$TotalIO)*100
        $WritePercent = [math]::round($WritePercent)
        }

        write-host "Total IO: "$TotalIO
        write-host "% Read Data: "$ReadPercent
        write-host "% Write Data: "$WritePercent
		write-host "*********"    

        #Cleanup Values
        $InboundTraffic = ""
        $OutboundTraffic = ""
        $TotalIO = ""
        $ReadPercent = ""
        $WritePercent = ""
		} 
     Get-VM -Computer $HVHost | Reset-VMResourceMetering
     Get-VM -Computer $HVHost | Enable-VMResourceMetering
	}
} 
}

Get-ClusterVM -clustername $ClusterName

Exit 0
=========

Does anyone know how to take each returned set of data (per VM in this instance) and create a sensor with multiple channels for that sensor? This Sensor would be update on subsequent runs

Any help is appreciated

Thanks

custom-sensor failovercluster hyper-v

Created on Jun 30, 2016 10:03:39 AM

Last change on Jun 30, 2016 10:47:42 AM by  Torsten Lindner [Paessler Support]



3 Replies

Votes:

0

Add something like this to the loop and take it from there:

	$result+="   <result>`r`n"
	$result+="       <channel>AvgCPU(Mhz) " + $VM.VMName + "</channel>`r`n"
	$result+="       <unit>#</unit>`r`n"
	$result+="       <value>"+$VM.AvgCPU+"</value>`r`n"
	$result+="   </result>`r`n"
}		
$result+="   <text>OK</text>`r`n"
$result+="</prtg>`r`n"
$result

Created on Jun 30, 2016 1:49:29 PM



Votes:

0

Hi

Thanks, but wont the above create multiple channels in a single sensor ?

Thanks

Created on Jun 30, 2016 2:46:10 PM



Votes:

0

Hello rhyse,
thank you for your reply.

Yes, that's correct. Doing a "loop" for every instance will create a multi-channel sensor which isn't always desirable.

We've recently introduced (In PRTG 16.1.22) a way to do a so-called "metascan" for Exe-sensors, this way the sensor can do a "metascan" (where it will query the list of available instances) and deploy one sensor per instance, please review the official KB-post on the subject:

Best Regards,

Created on Jul 1, 2016 9:17:49 AM by  Luciano Lingnau [Paessler]




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.