New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Average Sensor Uptime

Votes:

0

Your Vote:

Up

Down

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.

prtg reports sensors uptime

Created on Dec 13, 2016 6:09:28 PM by  Evan Lane (110) 2 1



5 Replies

Accepted Answer

Votes:

1

Your Vote:

Up

Down

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".

Created on Dec 13, 2016 10:03:33 PM by  Arne Seifert [Paessler Support]

Last change on Dec 13, 2016 10:05:27 PM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Dec 20, 2016 4:11:07 PM by  Evan Lane (110) 2 1



Votes:

1

Your Vote:

Up

Down

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 ...]
}

Created on Dec 20, 2016 7:12:29 PM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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!

Created on Dec 20, 2016 7:52:36 PM by  Evan Lane (110) 2 1



Votes:

0

Your Vote:

Up

Down

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.

Created on Dec 20, 2016 8:31:42 PM by  Arne Seifert [Paessler Support]

Last change on Dec 20, 2016 8:32:09 PM by  Arne Seifert [Paessler Support]



Please log in or register to enter your reply.


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.