# Container CPU via REST API

**URL:** <https://community.dynatrace.com/t/container-cpu-via-rest-api/20751>\
**Category:** Dynatrace API\
**Tags:** openshift, kubernetes, dynatrace-api\
**Created:** [November 6, 2020, 7:00pm UTC](https://community.dynatrace.com/t/container-cpu-via-rest-api/20751 "2020-11-06T19:00:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alessandro\_panz](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alessandro\_panz](https://community.dynatrace.com/u/alessandro_panz)\
**Post date:** [November 6, 2020, 7:00pm UTC](https://community.dynatrace.com/t/container-cpu-via-rest-api/20751/1 "2020-11-06T19:00:23Z")

</div>

Hi,

I need to get via REST API the metric “ **Container group instances --\> CPU usage % of limit** ” that I’m able to successfully get from dashboard:

 ![27242-metric-to-get.png](https://global.discourse-cdn.com/dynatrace/original/3X/3/c/3c7a8dc841ccb944a6f3b41dabc186836d9e62cd.png)

I built this REST API call:

[https://dynatrace.domain.com/e/9o04760a-3eec-48f1-876d-98ecfd8136hq/api/v2/metrics/query?metricSelector=builtin%3Acontainers.cpu\_usage2:names:avg:filter(eq(Container\_name,mycontainer))&resolution=Inf&from=now-2h&mzId(812622435820523696)&Api-Token=y-d7gYZQQbxtxqYtAxiLQ](https://dynatrace.domain.com/e/9o04760a-3eec-48f1-876d-98ecfd8136hq/api/v2/metrics/query?metricSelector=builtin%3Acontainers.cpu%5C_usage2:names:avg:filter(eq(Container%5C_name,mycontainer))&resolution=Inf&from=now-2h&mzId(812622435820523696)&Api-Token=y-d7gYZQQbxtxqYtAxiLQ)

but it returns empty “data”:[]:

{“totalCount”:4846,“nextPageKey”:“\_\_\_a7acX3q0AAAAGAQBXYnVpbHRpbjpjb250YWluZXJzLmNwdV91c2FnZTI6bmFtZXM6YXZnOmZpbHRlcihlcShDb250YWluZXIsY29yZS1zZWN1cml0eS13Zm1sb2dpbi12MSkpAQAAAAAAAABkAQAAAXWe5wjdAAABdZ55K90AAAF1nucI3QEBAAABAEB2dTlOUlZSUzNxMEFoQWRrQUFFQUdFeHNWV1JaYlhVMVV6Sk9NRXh6SzNOS1EzaDFlVTVyUGI3dlRVVlVVdDZ0\_\_\_a7acX3q0”,“result”:[{“metricId”:“builtin:containers.cpu\_usage2:names:avg:filter(eq(Container,mycontainer))”,“data”:[]}]}

What’s wrong with the API REST call?

---

<div class="post-metadata">

**Author:** ![Joe\_Hoffman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/joe_hoffman/32/30752_2.png) [@Joe\_Hoffman](https://community.dynatrace.com/u/Joe_Hoffman)\
**Post date:** [November 9, 2020, 4:51pm UTC](https://community.dynatrace.com/t/container-cpu-via-rest-api/20751/2 "2020-11-09T16:51:37Z")

</div>

Is your container really named ‘mycontainer’?

Have you tried playing with the API Explorer and see what it takes to return valid data. This is a very helpful tool in this type of exploration. The API Explorer can be found under Settings → Integration → Dynatrace API then click on Dynatrace API Explorer at the top of the page.

---

<div class="post-metadata">

**Author:** ![Joe\_Hoffman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/joe_hoffman/32/30752_2.png) [@Joe\_Hoffman](https://community.dynatrace.com/u/Joe_Hoffman)\
**Post date:** [November 9, 2020, 4:54pm UTC](https://community.dynatrace.com/t/container-cpu-via-rest-api/20751/3 "2020-11-09T16:54:54Z")

</div>

One approach could be to remove the filter you’ve applied to see if you even get any data back. If you do, then at least you know it’s your filter that’s causing no data. Or try a different metric with the same data. Try a larger timeframe. Try removing resolution. Explore a simpler command to determine what’s limiting your data returned.
