03 Jul 2025
03:31 PM
- last edited on
04 Jul 2025
07:24 AM
by
MaciejNeumann
Hi all,
I am working on a Dynatrace dashboard and I need to get the average CPU consumption of the ProcessGroups instances associated to the selected service in a dashboard variable. I am using the following DQL script to achieve this:
timeseries avg(dt.process.cpu.usage), by: { dt.entity.process_group_instance, dt.entity.process_group }
| fieldsAdd
dt.entity.process_group_instance.name = entityName(dt.entity.process_group_instance),
dt.entity.process_group.name = entityName(dt.entity.process_group),
value.CPU = arrayAvg(`avg(dt.process.cpu.usage)`)
| lookup [
fetch dt.entity.service
| fields entity.name, id, runs_on
| fieldsFlatten runs_on
], sourceField: dt.entity.process_group, lookupField: runs_on.dt.entity.process_group
| fieldsAdd monitor_tags = toString(entityAttr(dt.entity.process_group_instance, "tags"))
| filter contains(monitor_tags, "ENVIRONMENT:PRO")
| filter lookup.entity.name == $Service
What I expect the DQL do:
The DQL works correctly for some services, but for others it returns “no data”. However, by manually inspecting the service in question, I can see that it has ProcessGroups and instances that should be generating CPU data. There are even ProcessGroups identical to those of services that do work correctly with the script.
This makes me think that there may be some problem with how the relationship between the entities is done (for example, in the lookup step) or with the filtering.
I have tested the following:
I have made sure that the service selected in $Service has links to ProcessGroups that generate CPU data and I have tested the script with multiple different services to confirm that it is not a global problem but it happens without a clear pattern.
Works:
Doesn't work:
Any help or suggestions would be greatly appreciated, thank you very much in advance!
Victor
09 Jul 2025 11:56 PM
There's a simpler way to do this that I hope will work for you. The query happens in three steps:
The DQL comes out like this:
timeseries avg(dt.process.cpu.usage), by: { dt.entity.process_group_instance, dt.entity.process_group }
| fieldsAdd
dt.entity.process_group_instance.name = entityName(dt.entity.process_group_instance),
dt.entity.process_group.name = entityName(dt.entity.process_group),
value.CPU = arrayAvg(`avg(dt.process.cpu.usage)`),
services = entityAttr(dt.entity.process_group_instance,"runs")[dt.entity.service]
| filter in(services,$Service)
Here's a snapshot of the output when filtered down to a single service ID: