# Metrics API to get container groups

**URL:** <https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073>\
**Category:** Dynatrace API\
**Tags:** dynatrace-managed\
**Created:** [March 29, 2023, 12:14pm UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073 "2023-03-29T12:14:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenje](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@stephenje](https://community.dynatrace.com/u/stephenje)\
**Post date:** [March 29, 2023, 12:14pm UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073/1 "2023-03-29T12:14:24Z")

</div>

I am looking to get the CPU and memory from a particular container instance…

I can find the container details using

builtin:kubernetes.containers

and filter for the one I need

I ideally want to run

builtin:containers.cpu.usageMilliCores but in order to get the right container I need the&nbsp;container\_group\_instance value

I am not sure how to find out this information, can anyone assist?

---

<div class="post-metadata">

**Author:** ![paolo\_fumanelli](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/paolo_fumanelli/32/1037_2.png) [@paolo\_fumanelli](https://community.dynatrace.com/u/paolo_fumanelli)\
**Post date:** [March 29, 2023, 1:25pm UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073/2 "2023-03-29T13:25:34Z")

</div>

Not sure what you want to get,&nbsp;builtin:containers.cpu.usageMilliCores also accepts container as filter condition. Can you please further explain your need?

BR

---

<div class="post-metadata">

**Author:** ![stephenje](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@stephenje](https://community.dynatrace.com/u/stephenje)\
**Post date:** [March 29, 2023, 2:44pm UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073/3 "2023-03-29T14:44:40Z")

</div>

Hey thanks for the response… we have multiple containers with the same name as they are in different environments…

So I am using this query

builtin:containers.cpu.usageMilliCores:filter(eq(Container,vehicle-ohs)):names:parentsthis gives me multiple results…But I only want to use the container returned with this querybuiltin:kubernetes.containers:filter(eq(“k8s.deploymentconfig.name”,“vehicle-ohs”),eq(“k8s.namespace.name”,“vrm-e2e”),eq(“container\_state”,“running”)):names:parentsBut I cannot find out which container group this is in?

---

<div class="post-metadata">

**Author:** ![DanielS](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@DanielS](https://community.dynatrace.com/u/DanielS)\
**Post date:** [March 29, 2023, 4:45pm UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073/4 "2023-03-29T16:45:22Z")

</div>

Hi[@stephenje](https://community.dynatrace.com/user/23732) you can tag the container on creation to be able to identify it.

---

<div class="post-metadata">

**Author:** ![stephenje](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@stephenje](https://community.dynatrace.com/u/stephenje)\
**Post date:** [March 30, 2023, 6:06am UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073/5 "2023-03-30T06:06:00Z")

</div>

Thanks&nbsp;[@DanielS](https://community.dynatrace.com/user/35788)&nbsp;can those tags be used in a filter?

---

<div class="post-metadata">

**Author:** ![paolo\_fumanelli](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/paolo_fumanelli/32/1037_2.png) [@paolo\_fumanelli](https://community.dynatrace.com/u/paolo_fumanelli)\
**Post date:** [March 30, 2023, 6:41am UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073/6 "2023-03-30T06:41:32Z")

</div>

Hi, if you want to filter only a single container of a specific namespace you can leverage on relationships like this:

builtin:containers.cpu.usageMilliCores  
:filter(in(“dt.entity.container\_group\_instance”, entitySelector(“type(~“CONTAINER\_GROUP\_INSTANCE~”),fromRelationships.isCgiOfNamespace(type(CLOUD\_APPLICATION\_NAMESPACE),entityName.equals( **\<NAMESPACE\_NAME\>** ))”)))  
:splitBy():sort(value(auto,descending)):limit(20)

or by referencing the namespace by id

builtin:containers.cpu.usageMilliCores  
:filter(in(“dt.entity.container\_group\_instance”, entitySelector(“type(~“CONTAINER\_GROUP\_INSTANCE~”),fromRelationships.isCgiOfNamespace(type(CLOUD\_APPLICATION\_NAMESPACE),entityId( **\<NAMESPACE\_entityId\>** ))”)))  
:splitBy():sort(value(auto,descending)):limit(20)

In general usage of relationships when dealing with k8s entities is very useful.

See:

[Monitored entities API - GET all entity types | Dynatrace Docs](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/entity-v2/get-all-entity-types)

[Environment API v2 - Entity selector | Dynatrace Docs](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/entity-v2/entity-selector)

Hope this helps

Paolo

---

<div class="post-metadata">

**Author:** ![stephenje](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@stephenje](https://community.dynatrace.com/u/stephenje)\
**Post date:** [March 30, 2023, 6:57am UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073/7 "2023-03-30T06:57:26Z")

</div>

Awesome thanks&nbsp;[@paolo\_fumanelli](https://community.dynatrace.com/user/19328)&nbsp;that has worked… mucg appreciated

---

<div class="post-metadata">

**Author:** ![DanielS](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@DanielS](https://community.dynatrace.com/u/DanielS)\
**Post date:** [March 30, 2023, 11:48am UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073/8 "2023-03-30T11:48:49Z")

</div>

Yes, you can reference it by using, type(“CONTAINER\_GROUP\_INSTANCE~”),tag(“[context]key1:value-1”,“key2:value-2”,“value-3”)

---

<div class="post-metadata">

**Author:** ![stephenje](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@stephenje](https://community.dynatrace.com/u/stephenje)\
**Post date:** [March 30, 2023, 12:21pm UTC](https://community.dynatrace.com/t/metrics-api-to-get-container-groups/39073/9 "2023-03-30T12:21:36Z")

</div>

Thanks&nbsp;[@DanielS](https://community.dynatrace.com/user/35788)
