Hi All,

Is there a way to generate the average uptime of all sensors in PRTG, whether via a Report or a Sensor or Custom Sensor?


I have so far attempted using the Factory Sensor to pull the downtime from sensor channels of a couple test Devices but the Factory Sensor does not seem to keep track of it's uptime/downtime.
More on Factory Sensors: https://www.paessler.com/manuals/prtg/sensor_factory_sensor

I do not see a way to get a Report to generate what I require - It simple outputs all current data for uptime and downtime per sensor. I could always output to .csv and do the math myself, but would like to investigate other methods.


Article Comments

Attention: This article is a record of a conversation with the Paessler support team. The information in this conversation is not updated to preserve the historical record. As a result, some of the information or recommendations in this conversation might be out of date.

Dear Evan

An option would be to employ the PRTG API in a 3-step process:

  • Generate a list of all sensors
  • Query each sensor
  • Compute the average

A sensor list can be created via

/api/table.xml?id=0&content=sensors&columns=objid,name&count=*

Now get the live data for each sensor (this example is for a sensor ID 2123, please use the IDs queried via the above call.)

/api/getsensordetails.xml?id=2123

This gets you several properties, including up/downtime. You can sum them up and devide by the count.

In powershell you can cast the HTTP result to XML to make the processing much easier.

[xml]$result = (new-object System.Net.WebClient).downloadstring($apiurl)

In this case, you can access the data via

$node="uptime"
write-host $result.sensordata.$node.innertext

All these API examples only show the core of the call. The full HTTP API syntax is described in the PRTG API documentation available via menu Setup / PRTG API, tab "HTTP API".


Dec, 2016 - Permalink

Hi @Arne,

Following up on the three step process provided above, I had a couple questions in regards to generating the list and the Powershell aspect.

If I wanted to output the list of sensors the same as the uptime of the sensors. Would the following work?

$apiurl="http://prtg.server.com:8080/api/table.xml?id=0&content=sensors&columns=objid,name&count=*"
[xml]$result = (new-object System.Net.WebClient).downloadstring($apiurl)
$objectid ="objid"
write-host $result.sensors.item.$objectid.innertext

Because from that output I could input a variable for the sensors id and input in it:

$apiurl="http://prtg.server.com:8080/api/getsensordetails.xml?id="+$sensorid"
[xml]$result = (new-object System.Net.WebClient).downloadstring($apiurl)
$node="uptime"
write-host $result.sensordata.$node.innertext

Where $sensorid is = to $objectid.

Haven't worked out the logic 100%, but was wondering it the initial code block was something valid I could do? - also if the "write-host $result.sensors.item.$objectid.innertext" is correct


Dec, 2016 - Permalink

Dear Evan

I am sorry, our technical support does not cover the debugging of custom scripts. But I can tell you that the first example should use a foreach loop to iterate over all objid values.

foreach ($ID in $result.sensors.item.objid) 
{
    [... your code here, using $ID to access each ID with each loop ...]
}

Dec, 2016 - Permalink

Hi @Arne,

Sorry I don't think I was clear on what I was asking - I understand that you don't help with custom scripts, but thanks for trying to give me a bit of a pointer!

My question was more along the lines of the proper XML formatting for the output from:

/api/table.xml?id=0&content=sensors&columns=objid,name&count=*

Because the following doesn't work, despite the nodes in the XML table being:

$result.sensors.item.objid.innertext
<?xml version="1.0" encoding="UTF-8"?>
  <sensors totalcount="96" listend="1">
   <prtg-version>16.4.28.7352</prtg-version>
   <item>
    <objid>1001</objid>
    <name>System Health</name>
   </item>

I tend to try and give as much information as possible so you have an idea of why I am asking the question, but I may have added too much before and made it confusing for what I was asking for. Thanks for the help!


Dec, 2016 - Permalink

Dear Evan

The innertext method example only works if there is just one such node. Since the table returns many rows, please use a foreach loop to iterate over each according node.


Dec, 2016 - Permalink