# Using API get CPU and Memory of a host and all the host under an application

**URL:** <https://community.dynatrace.com/t/using-api-get-cpu-and-memory-of-a-host-and-all-the-host-under-an-application/31762>\
**Category:** Dynatrace API\
**Tags:** dynatrace-api\
**Created:** [June 10, 2021, 3:55am UTC](https://community.dynatrace.com/t/using-api-get-cpu-and-memory-of-a-host-and-all-the-host-under-an-application/31762 "2021-06-10T03:55:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shailandra](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@shailandra](https://community.dynatrace.com/u/shailandra)\
**Post date:** [June 10, 2021, 3:55am UTC](https://community.dynatrace.com/t/using-api-get-cpu-and-memory-of-a-host-and-all-the-host-under-an-application/31762/1 "2021-06-10T03:55:56Z")

</div>

hi,

i am trying to&nbsp;capture CPU and Memory of a host and all the host under an application for given time period, is this possible in DT

---

<div class="post-metadata">

**Author:** ![trevor\_masseng1](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/trevor_masseng1/32/2442_2.png) [@trevor\_masseng1](https://community.dynatrace.com/u/trevor_masseng1)\
**Post date:** [June 14, 2021, 6:52pm UTC](https://community.dynatrace.com/t/using-api-get-cpu-and-memory-of-a-host-and-all-the-host-under-an-application/31762/2 "2021-06-14T18:52:21Z")

</div>

Hi Shailandra,

Yes, this is possible.

Pulling metrics out of Dynatrace can be done with the Metrics API:

> **[Metrics API - GET metric data points](https://docs.dynatrace.com/docs/dynatrace-api/environment-api/metric-v2/get-data-points)**
>
> Read data points of one or multiple metrics via Metrics v2 API.

Depending on the type of host, there may be a different metric that is used for CPU or Memory, but all Host/Infrastructure metrics are listed here:

> **[Built-in classic metrics](https://docs.dynatrace.com/docs/analyze-explore-automate/metrics-classic/built-in-metrics)**
>
> Explore the complete list of built-in Dynatrace metrics.

Now as for grabbing all host metrics that serve a particular RUM Application, that requires a bit of configuration. You’ll either want to tag each host with the name of the application it serves, or create a management zone for them. After that, you can include the tag/management zone as a filter in your request to just pull those hosts.

The below requests should give you the results you want after you set up your tag or management zone (replace X with your tag/management zone name or change the metricSelector metric ID if you want to pull a different metric):

```markup
/api/v2/metrics/query?metricSelector=builtin:host.mem.usage&entitySelector=type(HOST),tag(X)

/api/v2/metrics/query?metricSelector=builtin:host.mem.usage&entitySelector=type(HOST),mzName(X)

```
