cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Grail query container data by namespace

Stephen1_Lee
Guide

Hi,

Can we retrieve the container data by container name and namespace?

timeseries memory=avg(dt.containers.memory.usage_percent), by:{dt.entity.container_group}
| filter contains(dt.entity.container_group,"CONTAINER_GROUP-0000339C0F0968B0")

This works if you know the id of a specific container.

But we have many containers in different namespaces.

 

4 REPLIES 4

Stephen1_Lee
Guide

mycontainer in TestNamespaceA

mycontainer in TestNamespaceB

 

each container will have its own usage and limits.

Philipp_Kastner
Dynatrace Pro
Dynatrace Pro

Hi @Stephen1_Lee ,

you can join the container group names and instance names and do filtering based on this.
For example, adding the container group name

timeseries memory=avg(dt.containers.memory.usage_percent), by:{dt.entity.container_group}
| lookup [fetch dt.entity.container_group], sourceField:dt.entity.container_group, lookupField:id

Filtering for container group instances

timeseries memory=avg(dt.containers.memory.usage_percent), by:{dt.entity.container_group_instance}
| lookup [fetch dt.entity.container_group_instance], sourceField:dt.entity.container_group_instance, lookupField:id
| filter startsWith(lookup.entity.name, "redhat") // your container group instance name


Kind regards, 
Philipp

Hi Philipp

Thanks for your answer.

Unfortuately we have many containers in different namespaces with the same name.

So running the query above gave me a large set of results which I know did not come from 1 namespace.

 

ie - 1 container - lookup.entity.name": "channels-ms-auth-5-2zqkl channels-ms-auth

another container  - lookup.entity.name": "channels-ms-auth-1-vrfr7 channels-ms-auth

 

I know these are actually 2 different deployments running in separate namespaces.

Is there any way to associate the container entity names to the namespaces?

Hi @Stephen1_Lee ,

with following query you can filter the metric by namespace. While the lookup command is already a first step to get more information to timeseries queries (e.g. the entity name as suggested by Philip), you additionally need to follow entity relationships to be able to filter by namespace name:

timeseries memory = avg(dt.containers.memory.usage_percent), by:{dt.entity.container_group}
| lookup [
// get the namespace for container groups by traversing the entity relationships
fetch dt.entity.container_group_instance
| fieldsAdd instanceOfContainerGroup = instance_of[dt.entity.container_group], belongsToNamespace = belongs_to[dt.entity.cloud_application_namespace]
| lookup [fetch dt.entity.container_group], sourceField:instanceOfContainerGroup, lookupField:id, prefix:"container_group."
| lookup [fetch dt.entity.cloud_application_namespace], sourceField:belongsToNamespace, lookupField:id, prefix:"namespace."
], sourceField:dt.entity.container_group, lookupField:container_group.id
| filter lookup.namespace.entity.name == "hipster-shop"
| fieldsRemove "lookup.*" // remove all lookup fields to have simpler series labels

There are improvements planned to simplify entity relationships in DQL, e.g. for such a filtering use-case like yours.

Let me know if that helps!

Featured Posts