# DQL database service response time split by ipAddress

**URL:** <https://community.dynatrace.com/t/dql-database-service-response-time-split-by-ipaddress/47152>\
**Category:** DQL\
**Tags:** dql, databases, dynatrace-managed, extensions\
**Created:** [August 14, 2024, 10:06am UTC](https://community.dynatrace.com/t/dql-database-service-response-time-split-by-ipaddress/47152 "2024-08-14T10:06:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![janne\_olkoniemi](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@janne\_olkoniemi](https://community.dynatrace.com/u/janne_olkoniemi)\
**Post date:** [August 14, 2024, 10:06am UTC](https://community.dynatrace.com/t/dql-database-service-response-time-split-by-ipaddress/47152/1 "2024-08-14T10:06:51Z")

</div>

I would appreciate if someone could lend a hand with my query.

So I trying to get our DB2 response times split by IP-address and my current query template looks like this.&nbsp;  
It currently splits the data by&nbsp;dt.entity.ipAddress and dt.entity.service but I would need the response time summarized by IP-address without the split on different database services.

Just couldn’t figure out by myself how to archive that one.

timeseries interval: 1h, response\_time = sum(dt.service.request.response\_time),  
by: { dt.entity.ipAddress, dt.entity.service },  
filter: { in(dt.entity.service, classicEntitySelector(“type(service),databaseVendor(\“DB2\”)”)) }  
| sort arraySum(response\_time) desc  
| fieldsAdd entityAttr(dt.entity.service, “ipAddress”)  
| limit 50

---

<div class="post-metadata">

**Author:** ![Radu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radu/32/23351_2.png) [@Radu](https://community.dynatrace.com/u/Radu)\
**Post date:** [November 21, 2024, 12:12pm UTC](https://community.dynatrace.com/t/dql-database-service-response-time-split-by-ipaddress/47152/2 "2024-11-21T12:12:36Z")

</div>

Hello. There are a couple of things wrong which I will try to explain.

First, let’s understand the Service entity. It does not actually have an attribute called “ipAddress” as we do not register IP Addresses against services. Going by relation, the closest entity that holds an IP Address is the Host entity. This means that you can “walk” the relationship from the Service to the Host (if the database has a monitored host). If your database only has a Service, extracting an IP Address is not possible.

Second, some of the DQL syntax is incorrect. The `dt.entity.` prefix only applies to entity types which ipAddress is not, so we cannot use `dt.entity.ipAddress`.

To extract the IP address from the Host, we’ll first get the Host IDs and then lookup their IP Addresses.

```auto
timeseries interval: 1h,
  ResponseTime = avg(dt.service.request.response_time),
  by: { ServiceId = dt.entity.service },
  filter: {
    // Adapt the selector to look for Services related to Hosts
    in(dt.entity.service, classicEntitySelector( """type("SERVICE"),databaseVendor("DB2"),fromRelationships.runsOnHost(type("HOST"))""" ))
}
// Add the service name (for readability) + Host IDs
| fieldsAdd ServiceName = entityName(ServiceId, type:"dt.entity.service")
// Service may run on multiple hosts so we need to 'expand' the array
| expand host = entityAttr(ServiceId, "runs_on", type:"dt.entity.service")[dt.entity.host]
// Now we can lookup each host's IP Addresses
| fieldsAdd IpAddresses = entityAttr(host, "ipAddress", type:"dt.entity.host")
// Remove unnecessary fields and keep result like this to see IPs per service instance
| fields timeframe, interval, ServiceId, ResponseTime, ServiceName, IpAddresses
// OR aggregate it to see IPs across all service instances
| summarize {
    ResponseTime = avg(ResponseTime[]),
    IpAddresses = arrayFlatten(collectArray(IpAddresses))
  },
  by: { timeframe, interval, ServiceId, ServiceName}

```

I hope this helps you out.

---

<div class="post-metadata">

**Author:** ![GerardJ](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gerardj/32/154_2.png) [@GerardJ](https://community.dynatrace.com/u/GerardJ)\
**Post date:** [November 26, 2024, 12:25pm UTC](https://community.dynatrace.com/t/dql-database-service-response-time-split-by-ipaddress/47152/3 "2024-11-26T12:25:47Z")

</div>

Hi&nbsp;[@Radu](https://community.dynatrace.com/user/22272)  
Very good and detailed explanation !  
Just a little addition, [entityAttr()](https://docs.dynatrace.com/docs/shortlink/general-functions#entityAttr) does exist and for example we could use it like this to avoid the second lookup :

```markup
| fieldsAdd IpAddress=entityAttr(svc.host, "ipAddress", type:"dt.entity.host")

```

---

<div class="post-metadata">

**Author:** ![Radu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radu/32/23351_2.png) [@Radu](https://community.dynatrace.com/u/Radu)\
**Post date:** [November 26, 2024, 12:43pm UTC](https://community.dynatrace.com/t/dql-database-service-response-time-split-by-ipaddress/47152/4 "2024-11-26T12:43:24Z")

</div>

Gerard, many thanks for pointing this out! It slipped my search completely.

I will rewrite my answer based on this as it simplified the query massively 🙂
