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

Performance Monitor with wildcard

Votes:

0

Hi. We tried to add a performance monitor with wildcard, but it looks like it's not supported, so I wrote a script for Powershell and thought that if would be nice for others to also have it.

The code:

#CommandLine Example:
#"ComputerName:%device" "Query:\BizTalk:Message Box:Host Counters(*)\Host Queue - Suspended Msgs - Length" "LimitMinWarning:1"
#
#For testing:
#$MyArgs = @("ComputerName:SERVERNAME","Query:\BizTalk:Message Box:Host Counters(*)\Host Queue - Suspended Msgs - Length","LimitMinWarning:1","LineBreak:1")
#if ($MyArgs) {
#    foreach ($MyArg in $MyArgs) {
#        $MyType = $MyArg.Split(':')[0]
#        $MyValue = $MyArg.Substring($MyType.Length+1)


#Handle arguments:
if ($args) {
    foreach ($arg in $args) {
        $MyType = $arg.Split(':')[0]
        $MyValue = $arg.Substring($MyType.Length+1)
        switch($MyType.ToLower()){
            "computername"{$ComputerName = $MyValue}
            "query"{$Query = $MyValue}
            "limitmaxerror"{$LimitMaxError = $MyValue}
            "limitmaxwarning"{$LimitMaxWarning = $MyValue}
            "limitminerror"{$LimitMinError = $MyValue}
            "limitminwarning"{$LimitMinWarning = $MyValue}
            "valuelookup"{$ValueLookup = $MyValue}
            "unit"{$Unit = $MyValue}
            "customunit"{$CustomUnit = $MyValue}
            "linebreak"{$LineBreak = $MyValue}
        }
    }
}

#Get the data
$PerfSamples = Get-Counter -ComputerName $ComputerName -Counter $Query

#Function used for creating the results as XML format
function createResult{
    Param(
            [Parameter (Mandatory = $true)] [String]$Channel,
            [Parameter (Mandatory = $true)] [String]$Value,
            [Parameter (Mandatory = $false)] [Int]$LimitMaxError,
            [Parameter (Mandatory = $false)] [Int]$LimitMaxWarning,
            [Parameter (Mandatory = $false)] [Int]$LimitMinError,
            [Parameter (Mandatory = $false)] [Int]$LimitMinWarning,
            [Parameter (Mandatory = $false)] [String]$ValueLookup,
        [Parameter (Mandatory = $false)] [String]$Unit,
        [Parameter (Mandatory = $false)] [String]$CustomUnit,
        [Parameter (Mandatory = $false)] [Int]$LineBreak = 0
    )
    if ($LineBreak -eq 1)
    {
        $LB = "`n"
    }
    $prtgResult += "<result>$LB"
    $prtgResult += "<channel>$Channel</channel>$LB"
    $prtgResult += "<value>$Value</value>$LB"
    if ($LimitMaxError) 
    {
        $prtgResult += "<LimitMaxError>$LimitMaxError</LimitMaxError>$LB"
    }
    if ($LimitMaxWarning)
    {
        $prtgResult += "<LimitMaxWarning>$LimitMaxWarning</LimitMaxWarning>$LB"
    }
    if ($LimitMinError)
    {
        $prtgResult += "<LimitMinError>$LimitMinError</LimitMinError>$LB"
    }
    if ($LimitMinWarning)
    {
        $prtgResult += "<LimitMinWarning>$LimitMinWarning</LimitMinWarning>$LB"
    }
    if ($ValueLookup) 
    {
        $prtgResult += "<ValueLookup>$ValueLookup</ValueLookup>$LB"
    }
    if ($LimitMaxError -Or $LimitMaxWarning -Or $LimitMinError -Or $LimitMinWarning)
    {
        $prtgResult += "<LimitMode>1</LimitMode>$LB"
    } 
    if ($Unit)
    {
        $prtgResult += "<Unit>$Unit</Unit>`n"
        if ($Unit -eq "Custom")
        {
            $prtgResult += "<CustomUnit>$CustomUnit</CustomUnit>$LB"
        }
    } 
    $prtgResult += "</result>$LB"
    return $prtgResult
}

#Looping through the data and creating the XML data for Write-Host
$prtgXML = '<Prtg>'
foreach ($Instance in $PerfSamples.CounterSamples) {
    $prtgXML += createResult -Channel $Query'\'$($Instance.InstanceName) -Value $($Instance.CookedValue) -LimitMaxError $LimitMaxError -LimitMaxWarning $LimitMaxWarning -LimitMinError $LimitMinError -LimitMinWarning $LimitMinWarning -ValueLookup $ValueLookup -Unit $Unit -CustomUnit $CustomUnit -LineBreak $LineBreak
}
$prtgXML += '</Prtg>'

#Printing out the data
Write-Host $prtgXML

code monitor performance powershell wildcard xml

Created on Dec 16, 2022 11:16:34 AM



Replies

Nobody has replied yet


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.