I need get max value of Sensor's Historic data (etc: bandwidth of sensor eth0)? Pls help me?
How to get max value of Sensor's Historic data (etc: bandwidth of sensor eth0)?
Votes:
0
Best Answer
Votes:
1
Thanks zajng9an,
Based on this, you're not going to be able to use PrtgAPI to easily retrieve and be able to manipulate this data via PowerShell.
The raw API request Get-SensorHistory would have executed in this place is as follows
https://prtg.example.com/api/historicdata.xml?id=2911&edate=2019-03-20-21-02-07&sdate=2019-03-13-21-02-07&avg=0&sortby=-datetime&count=50000&username=prtgadmin&password=password
If this request works in PRTG 13 you should get an XML document that you will then potentially be able to sort and manipulate to calculate the answer to your question
Regards,
lordmilko
10 Replies
Votes:
0
You can use PRTGapi (see my signature) and the following command for that:
Get-Sensor -Id 12345 | Get-SensorHistory -EndDate (Get-Date).AddDays(-7) | Sort-Object 'TrafficTotal(volume)' -Descending
12345 being the sensor ID. This will sort the historic data of the Sensor for you, top to bottom :)
PRTGapi |
Feature Requests |
WMI Issues |
SNMP Issues
Kind regards,
Stephan Linke, Tech Support Team
Votes:
0
thank Stephan but still get error :(
PS C:\WINDOWS\system32> Get-Sensor -Id 2911 | Get-SensorHistory -EndDate (Get-Date).AddDays(-7) | Sort-Object 'TrafficTotal(volume)' -Descending
Get-Sensor : An error occurred while attempting to deserialize XML element 'intervalx_raw': cannot assign 'null' to
value type 'TimeSpan'.
At line:1 char:1
+ Get-Sensor -Id 2911 | Get-SensorHistory -EndDate (Get-Date).AddDays(- ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Sensor], XmlDeserializationException
+ FullyQualifiedErrorId : PrtgAPI.XmlDeserializationException,PrtgAPI.PowerShell.Cmdlets.GetSensor
Created on Mar 19, 2019 10:14:10 AM
Last change on Mar 19, 2019 11:10:50 AM by
Stephan Linke [Paessler Support]
Votes:
0
This should actually work, just tested it again. What PowerShell version are you running? You can check this with $PRTGVersionTable.
PRTGapi |
Feature Requests |
WMI Issues |
SNMP Issues
Kind regards,
Stephan Linke, Tech Support Team
Votes:
0
Hi zajng9an,
This error implies that somehow the sensor with ID 2911 does not have an "interval" property, which should be impossible
Can you potentially execute the following commands and advise what the output is?
Set-PrtgClient -LogLevel Response Get-Sensor -Id 2911 -Verbose
Regards,
lordmilko
Votes:
0
This error implies that somehow the sensor with ID 2911 does not have an "interval" property, which should be impossible
With PRTG, nothing is impossible! :D Thanks for chiming in! :)
PRTGapi |
Feature Requests |
WMI Issues |
SNMP Issues
Kind regards,
Stephan Linke, Tech Support Team
Votes:
0
Hi lordmilko,
Pls see error after excute your command:
PS C:\WINDOWS\system32> Get-Sensor -Id 2911 -Verbose VERBOSE: Get-Sensor: <?xml version="1.0" encoding="UTF-8"?> <sensors> <prtg-version>13.1.2.1462</prtg-version> <item> <objid>2911</objid> <name>(002) eth0</name> <probe>Local probe</probe> <group>KQLIVE</group> <favorite/> <favorite_raw>0</favorite_raw> <lastvalue>7,303 kbit/s</lastvalue> <lastvalue_raw>912920.6000</lastvalue_raw> <device>appsv_kqlive (45.77.41.173) [Linux/Unix]</device> <downtime>0.0021%</downtime> <downtime_raw>000000000000021</downtime_raw> <downtimetime>4 m</downtimetime> <downtimetime_raw>000000000000240</downtimetime_raw> <downtimesince/> <uptime>99.9979%</uptime> <uptime_raw>000000000999979</uptime_raw> <uptimetime>132 d 7 h</uptimetime> <uptimetime_raw>000000011433190</uptimetime_raw> <uptimesince>98 d 4 h</uptimesince> <uptimesince_raw>000000008483168</uptimesince_raw> <knowntime>132 d 7 h <span class="percent"> [=100% coverage]</span></knowntime> <knowntime_raw>000000011433430</knowntime_raw> <cumsince>11/7/2018 2:56:31 PM <span class="percent">[132 d 17 h ago]</span></cumsince> <cumsince_raw>43411.3309153009</cumsince_raw> <lastcheck>3/20/2019 8:55:47 AM <span class="percent">[38 s ago]</span></lastcheck> <lastcheck_raw>43544.0804055903</lastcheck_raw> <lastup>3/20/2019 8:55:47 AM <span class="percent">[38 s ago]</span></lastup> <lastup_raw>43544.0804055903</lastup_raw> <lastdown>12/12/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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</minigraph> <schedule/> <basetype>sensor</basetype> <baselink>/sensor.htm?id=2911</baselink> <baselink_raw>2911</baselink_raw> <parentid>2906</parentid> <notifiesx>Inherited</notifiesx> <intervalx>Inherited (60)</intervalx> <access>Full</access> <access_raw>0000000400</access_raw> <dependency>Parent</dependency> <dependency_raw>appsv_kqlive (45.77.41.173) [Linux/Unix]</dependency_raw> <position>30</position> <position_raw>0000000030</position_raw> <status>Up </status> <status_raw>3</status_raw> <priority>3</priority> <message><div class="status">OK<div class="moreicon"></div></div></message> <message_raw>OK</message_raw> <tags>bandwidthsensor snmptrafficsensor</tags> <type>SNMP Traffic 64bit</type> <type_raw>snmptraffic</type_raw> <active>True</active> <active_raw>-1</active_raw> </item> </sensors> Get-Sensor : An error occurred while attempting to deserialize XML element 'intervalx_raw': cannot assign 'null' to value type 'TimeSpan'. At line:1 char:1 + Get-Sensor -Id 2911 -Verbose + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-Sensor], XmlDeserializationException + FullyQualifiedErrorId : PrtgAPI.XmlDeserializationException,PrtgAPI.PowerShell.Cmdlets.GetSensor
Created on Mar 20, 2019 2:01:16 AM
Last change on Mar 20, 2019 8:06:26 AM by
Stephan Linke [Paessler Support]
Votes:
1
Thanks zajng9an,
I can see you are running a fairly old version of PRTG (version 13.1.2.1462). PrtgAPI is developed against PRTG 14.4 and up. It appears in PRTG 13.1 requesting the interval of a sensor only returns the "intervalx" property, instead of the "intervalx" and "intervalx_raw" as it does in newer versions.
As a workaround for this task, you should be able to utilize the Get-SensorHistory cmdlet by specifying the -Id of the sensor directly. Are you able to advise whether the following works?
Get-SensorHistory -Id 2911 -EndDate (Get-Date).AddDays(-7) | Sort-Object 'TrafficTotal(volume)' -Descending
Votes:
0
That's indeed somewhat old. Kinda suprised it would (theoretically) work with 14.4 already :) Thanks for providing a possible workaround!
PRTGapi |
Feature Requests |
WMI Issues |
SNMP Issues
Kind regards,
Stephan Linke, Tech Support Team
Votes:
0
Thank lordmilko & Stephan,
Still error with new command :(
PS C:\WINDOWS\system32> Get-SensorHistory -Id 2911 -EndDate (Get-Date).AddDays(-7) | Sort-Object 'TrafficTotal(volume)' -Descending Get-SensorHistory : An error occurred while attempting to deserialize XML element 'totalcount': cannot assign 'null' to value type 'Int32'. At line:1 char:1 + Get-SensorHistory -Id 2911 -EndDate (Get-Date).AddDays(-7) | Sort-Obj ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-SensorHistory], XmlDeserializationException + FullyQualifiedErrorId : PrtgAPI.XmlDeserializationException,PrtgAPI.PowerShell.Cmdlets.GetSensorHistory
Created on Mar 20, 2019 9:41:45 AM
Last change on Mar 20, 2019 9:52:34 AM by
Stephan Linke [Paessler Support]
Votes:
1
Thanks zajng9an,
Based on this, you're not going to be able to use PrtgAPI to easily retrieve and be able to manipulate this data via PowerShell.
The raw API request Get-SensorHistory would have executed in this place is as follows
https://prtg.example.com/api/historicdata.xml?id=2911&edate=2019-03-20-21-02-07&sdate=2019-03-13-21-02-07&avg=0&sortby=-datetime&count=50000&username=prtgadmin&password=password
If this request works in PRTG 13 you should get an XML document that you will then potentially be able to sort and manipulate to calculate the answer to your question
Regards,
lordmilko
Add comment