This article applies as of PRTG 22
I want to export the monitoring data of PRTG to a .csv or .xml file on a daily basis. This way, I can analyze the data in my own software or import it to Microsoft Excel
Exporting historic sensor data into .csv or .xml files with the PRTG API
The PRTG API allows you to export historic sensor data into .csv or .xml files. This is useful if you need sensor data in a format that allows you to view your own statistics in external programs or for additional computations.
The API documentation contains all the information that you need to build your queries. You can run API calls from a supported browser in URL format. The URL call must include the PRTG website name and credentials, for example:
https://<your-PRTG-server>/api/historicdata.xml?....&username=myuser&passhash=mypasshash
API calls for historic data in CSV or XML format
The following API calls give you historic data tables, either in CSV or XML format.
Notes:
- The authentication with user name and passhash(or user name and password) must always be included in each request by using the user name and passhash (or user name and password) parameters. You can find the passhash in the PRTG web interface:
- Select Setup | Account Settings | My Account from the main menu bar.
- Click the Show passhash button.
- You must supply the object ID of a sensor as well as a start date/time sdate and end date/time edate to get the raw data table. You can find the object ID on a sensor’s Overview tab or by hovering over the sensor in the device tree, for example.
CSV format
/api/historicdata.csv?id=objectid&avg=0&sdate=2018-01-20-00-00-00&edate=2018-01-21-00-00-00&username=myuser&passhash=mypasshash
XML format
/api/historicdata.xml?id=objectid&avg=0&sdate=2017-01-20-00-00-00&edate=2017-01-21-00-00-00&username=myuser&passhash=mypasshash
Example
You can use the following example call to query historic data for a Core Health sensor with ID #1002 in CSV format:
/api/historicdata.csv?id=1002&avg=0&sdate=2018-02-01-00-00-00&edate=2018-02-15-00-00-00&username=myuser&passhash=mypasshash
The avg (average) is 0, so raw data is displayed. The sdate is February 1st, 2018 at 12 A.M and the edate is February 15th, 2018 at 12 A.M. The result is a spreadsheet (.csv) file where data of each channel is represented in an individual column.
Common parameters for historic data API calls
You can use the following parameters for the historic graphs and data tables:
Parameter | Description | Possible values |
---|---|---|
id | ID of the specific sensor | integer value |
sdate | Start of the time span (date and time) | yyyy-mm-dd-hh-mm-ss |
edate | End of the time span (date and time) | yyyy-mm-dd-hh-mm-ss |
avg | Average interval in seconds; use 0 to download raw data (= results of all single monitoring requests) | integer value |
width/height | Width and height of the graph in pixels | integer value |
graphstyling | baseFontSize='x' sets the size of the font, showLegend='x' enables (1) or disables (0) the graph legend | baseFontSize='x'%20showLegend='x' |
Historic Data Query Builder
The query builder tool allows you to experiment with API calls. The tool automatically builds and tests your desired queries. You can find the tool in the PRTG web interface under Setup | PRTG API | Historic Data, section Historic Data Query Builder.
Detailed HTTP API documentation
You can find detailed documentation on all HTTP API functions in the PRTG Manual: Application Programming Interface (API) Definition.
Automatic export
If you want to automatically export historic data of several sensors at once, you can use the CSVExport command-line tool. It allows you to export data into both .csv and .xml files. See PRTG Tools Family for more information.
Limitations of the PRTG API for historic data
There are some limitations to prevent potential server overload when you query historic sensor data via the PRTG API:
- Maximum 40 days of data for raw data requests
- Maximum 500 days of data per API request for averages. If you try to use a larger time span than 500 days, PRTG will reduce it to 365 days automatically.
- Maximum 5 API calls per minute
More
This article applies to PRTG Network Monitor Version 12 or later, as well as to previous (deprecated) versions
HowTo: Automatically Exporting PRTG's Raw Monitoring Data Into Daily CSV or XML Files
With PRTG Network Monitor, you can analyze your sensor data in various ways. Exhaustive reports for your whole network can be generated as well as historic data reports for single sensors. Still, there are people who just need the data of a sensor in a convenient format to do their own statistics in external programs or to use Excel to do additional computations based on the monitoring data. That is why we have included a XML and CSV export function in PRTG.
This function of the web interface is handy to export data every few days. But if you need daily data for one or more sensors an automatic solution is more comfortable. With the CSVExport command line tool finally there is a way to export data of many PRTG sensors with one single line of script! You can use it as an on-demand tool or combine it with Windows task scheduler. Don't be confused by the name - CSVExport is capable of both XML and CSV data export!
Getting Started
To try it out, download CSVExport from PRTG Tools Family and unpack it.
To run the tool you must supply following command line parameters:
- PRTG username (option -pu).
- PRTG password (option -pp).
- The IP address or hostname of the PRTG web interface (option -ps).
- The sensor ID (or a list of IDs) of the sensor(s) you want to export the data for (option -s). You can look up a sensor's ID under its detail overview page from within the PRTG web interface. The ID is the number written in parentheses behind the sensor name. By the way, the ID is also part of the sensor's webpage URL.
For example, a simple call may look like this:
csvexport -pu=prtgadmin -pp=prtgadmin -ps=192.168.0.10 -s=1001
This command line writes yesterday's data of the sensor "Probe Health" (ID 1001) into a CSV file in the directory where CSVExport is started. If a file already exists, it is not overwritten, but a number is appended to the file name. If you run this command once every day using scheduled tasks you will get a daily CSV file for the sensor 1001.
A big advantage of this tool is that you can export the data of many sensors with one single call. To do so, you only have to look up the IDs and enter them - separated by commas - behind the "-s" parameter. In this case, you will get a separate file for each sensor.
Advanced Options
With optional parameters, you can define a start and end date of the data you want to export or enter a different target file location and credentials, if necessary. You can also change file format to XML and even combine the data of multiple sensors into one file. Please see the manual that comes with the tool's download for a good description of all advanced options.
Notes
This tool was written by PRTG Tools Family (which is not associated with Paessler). Thanks for sharing it with the community! All Google Code tools have not been created and published by Paessler AG, so we are not able to support them officially.
More
If you have trouble opening the CSV files in Excel, please see The Comma and Semicolon Issue in Excel Due to Regional Settings for Europe
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.