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?
Add comment