Get average CPU percentages (v2)

Deprecated

New Relic Servers is no longer available. For infrastructure monitoring, please use New Relic Infrastructure. For how to switch to Infrastructure from Servers, see the transition guide.

Here are examples of how to use the New Relic REST API (v2) to obtain the average CPU percentages for your system and users for a specific server ID and API key. The examples show different time ranges.

The API calls use two metric names, System and User. Because there are multiple values, New Relic's REST API returns them in JSON or XML format. The examples here show XML.

When acquiring data, the values returned may be affected by the time period you specify and the way the data is stored. For more information, see Extracting metric timeslice data.

Example: Default time period

To get the average percent over the last 30 minutes (default) for your system and users, you do not need to specify the time range. For example:

curl -X GET "https://api.newrelic.com/v2/servers/servers/${SERVERID}/metrics/data.xml" \
     -H "X-Api-Key:${APIKEY}" -i \
     -d 'names[]=System/CPU/System/percent&names[]=System/CPU/User/percent&values[]=average_value&summarize=true'

You can also use API Explorer Servers > Metric Data to obtain the information in this example.

Example: Selected time period

To specify a different time range, change the from and to values. Here is an example of the same data, except it obtains the average value for a five minute period.

curl -X GET "https://api.newrelic.com/v2/servers/servers/${SERVERID}/metrics/data.xml" \
     -H "X-Api-Key:${APIKEY}" -i \
     -d 'names[]=System/CPU/System/percent&names[]=System/CPU/User/percent&values[]=average_value&from=2014-01-20T15:23:00+00:00&to=2014-01-20T15:28:00+00:00&summarize=true'

For more help

New Relic Servers is unavailable as of May 15, 2018. For more information: