---
title: Get average CPU usage per host for an app
source: https://docs.newrelic.com/docs/apis/rest-api-v2/application-examples-v2/get-average-cpu-usage-host-app
---

You can use the New Relic REST API (v2) to get the average CPU usage for your application on a single host. This value appears on the [APM **Summary** page](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page) in the **Hosts** table, in the column labeled **CPU usage**.

> #### ⚠️ IMPORTANT
>
> While the examples utilize New Relic's REST API v2, we recommend using [NRQL functions](https://docs.newrelic.com/docs/nrql/get-started/introduction-nrql-new-relics-query-language/) for executing metric timeslice queries. Each API value can be mapped to an equivalent NRQL function. To learn how to create NRQL queries based on these API examples, refer to our [documentation](https://docs.newrelic.com/docs/apis/rest-api-v2/migrate-to-nrql/).

## Get CPU usage for a host

To get the average CPU usage for one of your app's hosts, use a single command to obtain the metric `names[]=CPU/User+Time` with `values[]=percent`. This example shows the time range for the [default time period](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/specifying-time-range-v2) (last 30 minutes):

```bash
curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/hosts/$HOST_ID/metrics/data.json" \
     -H "Api-Key:$API_KEY" -i \
     -d 'names[]=CPU/User+Time&values[]=percent&summarize=true'
```

-   Replace `$APP_ID` and `$API_KEY` with your [app ID](https://docs.newrelic.com/docs/apm/apis/requirements/identification-code) and your [API key](https://docs.newrelic.com/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2#api_key).
-   Replace the `$HOST_ID` with the [host id](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/listing-host-instance-application-server-ids#locating_host_id) of your target host.

For additional detail:

-   Remove `summarize=true` to obtain detailed [time series data.](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/calculating-average-metric-values-summarize)
-   Specify a different [time range](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/specifying-time-range-v2).

> #### 💡 TIP
>
> To get the same information from the [New Relic API Explorer (v2)](https://api.newrelic.com/docs), select [**Application Hosts > GET Metric Data**](https://api.newrelic.com/docs/#/Applications/get_applications__application_id__hosts__host_id__metrics_data_json), and include your [API key](https://docs.newrelic.com/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2#api_key). Add your [application ID](https://docs.newrelic.com/docs/apm/apis/requirements/identification-code), [host id](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/listing-host-instance-application-server-ids#locating_host_id), and the `names[]=CPU/User Time` and `values[]=percent` metrics in the appropriate fields.

## Get CPU usage for the entire app [#api-call]

To get the average CPU usage for your application, use a command similar to the one in the previous example but without the reference to the `host_id`:

```bash
curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.json" \
     -H "Api-Key:$API_KEY" -i \
     -d 'names[]=CPU/User+Time&values[]=percent&summarize=true'
```

-   Replace `$APP_ID` and `$API_KEY` with your [app ID](https://docs.newrelic.com/docs/apm/apis/requirements/identification-code) and your [API key](https://docs.newrelic.com/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2#api_key).

For additional detail:

-   Remove `summarize=true` to obtain detailed [time series data.](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/calculating-average-metric-values-summarize)
-   Specify a different [time range](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/specifying-time-range-v2).

> #### 💡 TIP
>
> To get the same information from the [New Relic API Explorer (v2)](https://api.newrelic.com/docs), select [**Applications > GET Metric Data**](https://api.newrelic.com/docs/#/Applications/get_applications__application_id__metrics_data_json), and include your [API key](https://docs.newrelic.com/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2#api_key). Add your [application ID](https://docs.newrelic.com/docs/apm/apis/requirements/identification-code), and the `names[]=CPU/User Time` and `values[]=percent` metrics in the appropriate fields.
