How to monitor CPU usage by container in DQL?

Using the following DQL, I can get the names of containers in a container group:

fetch dt.entity.container_group_instance
| filter id == "CONTAINER_GROUP_INSTANCE-XXXXXXXXXX"
| fieldsAdd containerNames
| expand containerNames

I can also get the CPU usage user time of the container group instance in DQL:

timeseries { usage_user_time = avg(dt.containers.cpu.usage_user_time) }, filter: { dt.entity.container_group_instance == "CONTAINER_GROUP_INSTANCE-XXXXXXXXXX" }

Is there a way in DQL to get this metric by container?

@jmarbaix If its the CPU usage you are after , you can try the below

timeseries avg(dt.kubernetes.container.cpu_usage), 
by: { k8s.container.name, dt.entity.container_group_instance }, 
filter: { matchesValue(dt.entity.container_group_instance, "CONTAINER_GROUP_INSTANCE-xxxx") }
| fieldsAdd dt.entity.container_group_instance.name = entityName(dt.entity.container_group_instance)

If its “dt.containers.cpu.usage_user_time” metric, then

timeseries avg(dt.containers.cpu.usage_user_time), 
by: { k8s.container.name, dt.entity.container_group_instance }, 
filter: { matchesValue(dt.entity.container_group_instance, "CONTAINER_GROUP_INSTANCE-xxx") }
| fieldsAdd dt.entity.container_group_instance.name = entityName(dt.entity.container_group_instance)

We are not using k8s containers, but podman containers, so sadly enough your proposed solution doesn’t work.

@jmarbaix I think the second query should still be good with some modifications as its a container metric, can you please try below?

timeseries avg(dt.containers.cpu.usage_user_time), by: { dt.entity.container_group_instance },
filter: { matchesValue(dt.entity.container_group_instance, "CONTAINER_GROUP_INSTANCE-XXXX") }
| fieldsAdd dt.entity.container_group_instance.name = entityName(dt.entity.container_group_instance)

Hi @jmarbaix ,

The easiest way is to go to the Dynatrace UI, select the container for which you want to get the metric, open Data Explorer from there, and then open a notebook. This will show you the DQL running behind the scenes.

From there, you can adjust the query according to your needs.

Hope this helps?