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

XML: XML Parser mismatch: Wanted </>, got </prtg> -- JSON: The returned JSON does not match the expe

Votes:

0

I am trying to graph a Performance Monitor counter from our Hyper-V hosts that has multiple objects and I am getting the following error in PRTG:

XML: XML Parser mismatch: Wanted </>, got </prtg> -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

I am using the following PowerShell script:

Invoke-Command -ComputerName computer -ScriptBlock {Get-Counter "\Hyper-V Hypervisor Virtual Processor(*)\CPU Wait Time Per Dispatch" |
  
  ForEach-Object CounterSamples |
  Where-Object InstanceName -ne _total |
  ForEach-Object {
    $InstanceName = $_.InstanceName
    $Value        = $_.CookedValue
 Write-Host
       "<prtg>"
       "<result>"
       "<channel>$InstanceName</channel>"
       "<value>$Value</value>"
       "</result>"
       "</prtg>"

  }
  }
Write-Host "</prtg>"

When I rung the script in PowerShell I get the following output to screen

<prtg>
<result>
<channel>computer1:hv vp 1</channel>
<value>7740.49019607843</value>
</result>
</prtg>

<prtg>
<result>
<channel>computer1:hv vp 0</channel>
<value>10382.5023227005</value>
</result>
</prtg>

<prtg>
<result>
<channel>computer2:hv vp 3</channel>
<value>1897.42268041237</value>
</result>
</prtg>

<prtg>
<result>
<channel>computer2:hv vp 2</channel>
<value>17919.1033138402</value>
</result>
</prtg>

json performance-counters remote-powershell xml

Created on Feb 8, 2018 12:15:02 AM

Last change on Feb 8, 2018 7:24:21 PM by  Stephan Linke [Paessler Support]



3 Replies

Votes:

0

There's a slight mistake in your output:

Write-Host "<prtg>"
Invoke-Command -ComputerName computer -ScriptBlock {Get-Counter "\Hyper-V Hypervisor Virtual Processor(*)\CPU Wait Time Per Dispatch" |
  
  ForEach-Object CounterSamples |
  Where-Object InstanceName -ne _total |
  ForEach-Object {
    $InstanceName = $_.InstanceName
    $Value        = $_.CookedValue
 Write-Host
       "<result>"
       "<channel>$InstanceName</channel>"
       "<value>$Value</value>"
       "</result>"
  }
  }
Write-Host "</prtg>"

The <prtg> and </prtg> tags ony mark the start and end of the actual output. It may as well be that PRTG doesn't see the console output, as you're using Invoke-Command on another host. The Get-Counter cmdlet also has a ComputerName paramete, so you actually don't need to use Invoke-Command :)


Kind regards,
Stephan Linke, Tech Support Team

Created on Feb 8, 2018 7:30:54 PM by  Stephan Linke [Paessler Support]



Votes:

0

Hi Stephan

Thanks, this is working correctly now.

I'm using the Invoke-Command so that I can pass credentials to the remote computer, the Get-Counter cmdlt doesn't appear to have a way of passing credentials.

When PRTG runs the script is it running them as the user configured for the PRTG Probe Service? (ours is running as the Local System account) If it does, what is the minimum permissions an account would need to run the Probe Service on the PRTG Host? EDIT: just remembered I can change the access rights in the Settings for the sensor.

One last question if I may, the performance counter returns values in nanoseconds, I've done some searching and am still looking but is there a way to convert the counter value from nanoseconds to milliseconds? (I've made a change to strip the decimals places from the returned counter by using [int] so I now have the following:

  ForEach-Object {
    $InstanceName = $_.InstanceName
    [int]$Value   = $_.CookedValue
     
  Write-Host
       "<result>"
       "<channel>$InstanceName</channel>"
       "<value>$Value</value>"
       "</result>"

Created on Feb 8, 2018 11:32:56 PM



Votes:

0

Well, you could simply divide it by 1000:

[int]$Value = $_.CookedValue / 1000

That should be it :)

Created on Feb 9, 2018 7:55:52 AM by  Stephan Linke [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.