Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Relic Solution: Exporting Linux Server Monitor Data Using the REST API

restapi
explorer
linuxservermonitor

#1

If you are looking to store a local copy of the metric data for the Linux Server Monitor, you might be looking for a way to export the charts from the Server UI. Unfortunately it is not possible to export data from any of the charts in the Servers UI.

Instead, you might consider using the REST API to pull data and then recombine the results on your end. Please note that the level of detail returned depends on the amount of data queried, and the age of the data at the time it is queried. To see the exact specifications, please see the links below:

This means that to get the highest level of detail and the largest timewindow, you would want to query the API every 3 hours to collect the last 3 hours of data. To be on the safe side, you might actually run it every 2 hours and 55 minutes, but collect the last 3 hours of data, then unique the data locally based on the timestamp as there will be about 5 minutes of overlap. Note than on a lite account (not paying for any New Relic services) data is aggregated after 2 hours so this query should be run every 1 hour 55 minutes to query the last 2 hours of data.

If you are at this moment gathering all the data for the last 3 months, please be aware that the highest detail for data at the end of this timeframe is one datapoint every hour, rather than 1 every minute. This is regardless of the size of the time window queried.

For more information please see:


REST API Explorer

The easiest way to get started will be to use the REST API Explorer to build a curl request. First obtain your API key by going to the URL below, inserting your account ID where indicated:

https://rpm.newrelic.com/accounts/{$ACCOUNT_ID}/integrations?page=api_keys

Next go to the explorer:
https://rpm.newrelic.com/api/explore

Scroll down the left sidebar until you find the Servers section. You’ll want to pull the metric data, but in order to do so you’ll need the metric names. In the Server Metric Names section, enter the API key and the Server ID to query the database for metric names. Choose the ones you would like to collect data for.

Next go to the metric data section. Enter the API key, server ID, and metric names (each on their own line). You’ll likely want the average_value, so enter it in the values[] section. Set the desired time frame, keeping in mind that it is in UTC time and a 24 hour format. Set summarize to false to see all the available datapoints for the selected timeframe. When you run the query, the response is shown below.

Most importantly, if you scroll back up to the top, it shows the curl request needed to acquire this data. Copy and save this so that you can run it locally. For example if I wanted the metric data for the CPU Usage System Percent for 3 hours ending at 2:30 pm (PST) on 7 July 2017, I would run the request below. Note that the API key and Server ID have been redacted.

curl -X GET 'https://api.newrelic.com/v2/servers/{$SERVER_ID}/metrics/data.json' \
     -H 'X-Api-Key:{$API_KEY}' -i \
     -G -d 'names[]=System/CPU/System/percent&values[]=average_value&from=2017-07-07T28:30:00+00:00&to=2017-07-07T21:30:00+00:00&summarize=false' 

#2