We have a service that outputs a set of monitoring data (channels) in json or xml format. What is the most efficient way of getting these data into PRTG? Do I have to use one sensor per channel - or is it possible to use one sensor per group?
Sample JSON: { "general": { "Exceptions": "0" }, "tcp": { "TCPTelegramsIn": "0", "TCPTelegramsOut": "0", "TCPResponseTime": "0", "TCPErrors": "0", "TCPConnects": "0", "TCPDisconnects": "0", "TCPTelegramsInCL": "9.49940747546472E-43", "TCPTelegramsOutCL": "0", "TCPResponseTimeCL": "0", "TCPErrorsCL": "0", "TCPConnectsCL": "0", "TCPDisconnectsCL": "0" }, "notifications": { "NotificationsIn": "0", "NotificationsOut": "0" }, "m3api": { "M3APICalls": "2.06414875439106E-9", "M3APIErrors": "0", "M3APIResultCounts": "0", "M3APIResponseTime": "8.57911826043786E-8" }, "db": { "DBReads": "8401.19020875096", "DBWrites": "4828.46466000697", "DBErrors": "0" }, "data": { "PSDOrders": "0", "PSDMoveOrders": "0", "PSDPickOrders": "0" } }
[edit] I just wrapped the json code so it's readable
Article Comments
That would be nice - our service already provides the json data through http - adding another format would be trivial.
Could you make a "bracket example" based on my original sample, to clarify how it is done properly?
Jun, 2015 - Permalink
Something like this:
Exceptions: [0] TCPTelegramsIn: [0] TCPTelegramsOut: [0] TCPResponseTime: [0] TCPErrors: [0] TCPConnects: [0] TCPDisconnects: [0] TCPTelegramsInCL: [9.49940747546472E-43] TCPTelegramsOutCL: [0] TCPResponseTimeCL: [0] TCPErrorsCL: [0] TCPConnectsCL: [0] TCPDisconnectsCL: [0] NotificationsIn: [0] NotificationsOut: [0] M3APICalls: [2.06414875439106E-9] M3APIErrors: [0] M3APIResultCounts: [0] M3APIResponseTime: [8.57911826043786E-8] DBReads: [8401.19020875096] DBWrites: [4828.46466000697] DBErrors: [0] PSDOrders: [0] PSDMoveOrders: [0] PSDPickOrders: [0]
The text is actually obligatory, PRTG only cares for what's within the brackets. They're put into channels automatically, the line number resembles the channel ID. Make sure to set the channel number during the creation of the sensor correctly, otherwise, the sensor will error (not enough values).
Jun, 2015 - Permalink
Thanks!
Just a thought: It would be nice if you made a proper JSON format specification which adds units and grouping. So much easier to develop towards a proper spec.
Jun, 2015 - Permalink
Well the sensor is not designed specifically to work with JSON values, more for values on a website that need to be tracked. It should be rather easy to develop a PowerShell script that iterates through a given JSON response and creates the channels accordingly :)
Jun, 2015 - Permalink
Hi All,
What would be the case for a JSON output with an Array?
{ "@count": 3, "@start": 1, "@totalcount": 3, "Messages": [], "ResourceName": "Incident", "ReturnCode": 0, "content": [ {"Incident": {"IncidentID": "IM10231"}}, {"Incident": {"IncidentID": "IM10258"}}, {"Incident": {"IncidentID": "IM10261"}} ] }
As the ConvertFrom-Json doesn't play nice with the JSON arrays. Output goes from above to:
@{ @count=3; @start=1; @totalcount=3; Messages=System.Object[]; ResourceName=Incident; ReturnCode=0; content=System.Object[] }
Jan, 2017 - Permalink
The best way to get this into PRTG is via the EXE/Script (Advanced) sensor. Create a PowerShell script that creates an object from the JSON response (using ConvertFrom-JSON) and put the values into their corresponding channels.
Edit On the other hand, if you can modify the service to output the numeric values in brackets as a 3rd output option, you can use the HTTP content sensor. Whatever causes the least work for you :)
Jun, 2015 - Permalink