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

Custom Rest sensor - expressions and filtering

Votes:

0

Hi,

Trying to use a custom rest sensor to monitor an endpoint, but I'm having trouble finding the correct syntax to do calculations.

For example:

This is the JSON returned:

[ { "request": { "path": "used", "mbean": "java.lang:type=Memory", "attribute": "HeapMemoryUsage", "type": "read" }, "value": 505026552, "timestamp": 1674569295, "status": 200 }, { "request": { "path": "max", "mbean": "java.lang:type=Memory", "attribute": "HeapMemoryUsage", "type": "read" }, "value": 4294967296, "timestamp": 1674569295, "status": 200 } ]

This is my template:

{ "prtg": { "result": [ { "channel": "Used Heapmemory", "unit": "Percent", "value": $[[email protected]=="HeapMemoryUsage" && @.request.path=="used"].value * 100 } ] } }

This gives me an error:

invalid operation ([]interface {}) * (float64)

Ultimately I want to calculate a percent, like so:

"value": 100 * $[[email protected]=="HeapMemoryUsage" && @.request.path=="used"].value / $[[email protected]=="HeapMemoryUsage" && @.request.path=="max"].value

But for now I'm just trying to get it to multiply with 100.

This works: "value": $[[email protected]=="HeapMemoryUsage" && @.request.path=="used"].value returns: 505026552

This also works: "value": $[0].value * 100 returns: 50502655200

But the combination gives me the error.

Based on another KB item I've also tried:

"value": $($[[email protected]=="HeapMemoryUsage" && @.request.path=="used"].value) * 100

But alas, same error.

What's the correct syntax here?

custom-rest expression prtg

Created on Jan 25, 2023 10:53:09 AM



1 Reply

Accepted Answer

Votes:

0

Found the answer.

A filter, like this, always returns an array, not a value:

$[[email protected]=="HeapMemoryUsage" && @.request.path=="used"].value

Because more than one element may returned by the filter. And since it’s not possible to multiply an array with a constant you need to do this:

100* $($[[email protected]=="HeapMemoryUsage" && @.request.path=="used"].value)[0]

In other words, select the first element of the array returned by the filter (I designed the filter to only return one element so I know the first one is the one I want).

Created on Jan 26, 2023 2:25:03 PM

Last change on Jan 26, 2023 3:57:16 PM by  Felix Wiesneth [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.