# Host name in services running on host dql

**URL:** <https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156>\
**Category:** DQL\
**Tags:** dql, dashboards\
**Created:** [June 18, 2025, 10:51am UTC](https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156 "2025-06-18T10:51:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pablo2](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@Pablo2](https://community.dynatrace.com/u/Pablo2)\
**Post date:** [June 18, 2025, 10:51am UTC](https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156/1 "2025-06-18T10:51:05Z")

</div>

I have a dql that relates me the services and the hosts on which it is running, but it only gives me the id of the hosts and I would like to have the name of the host instead of the id.

This is the dql:

fetch dt.entity.service  
| expand dt.entity.host=runs\_on[dt.entity.host]  
| fieldsAdd entityAttr(dt.entity.host, “tags”)  
| filter in(id, classicEntitySelector(concat(“type(service), tag(\“APP:”, $APPLICATION, “\”)”)))  
| filter in(id, classicEntitySelector(concat(“type(service), tag(\“ENVIRONMENT:”, $ENTORNO, “\”)”)))  
| dedup id  
| fields entity.name, serviceType, entity.customized\_name, id, runs\_on[dt.entity.host]

 ![Pablo2_0-1750243816491.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/6/567a43f65a478731e291266af939bbd66e1f5335.png)

I found this in the documentation but I’ve tried it and it doesn’t work for me.

> **[Query monitored entities in Grail](https://docs.dynatrace.com/docs/platform/grail/querying-monitored-entities)**
>
> Find out how to query monitored entities in Grail.

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [June 18, 2025, 11:13am UTC](https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156/2 "2025-06-18T11:13:27Z")

</div>

Hi Pablo,

Adding this instruction

_| lookup sourceField:runs\_on[dt.entity.host], lookupField:id, fields:{host.name = entity.name}, [fetch dt.entity.host]_

you can get the hostname instead of the hostid.

Try to change the DQL adding this line. Somethig like this maybe:

fetch dt.entity.service  
| expand dt.entity.host=runs\_on[dt.entity.host]

| lookup sourceField:runs\_on[dt.entity.host], lookupField:id, fields:{host.name = entity.name}, [fetch dt.entity.host]  
| fieldsAdd entityAttr(dt.entity.host, “tags”)  
| filter in(id, classicEntitySelector(concat(“type(service), tag(\“APP:”, $APPLICATION, “\”)”)))  
| filter in(id, classicEntitySelector(concat(“type(service), tag(\“ENVIRONMENT:”, $ENTORNO, “\”)”)))  
| dedup id  
| fields entity.name, serviceType, entity.customized\_name, id, runs\_on[dt.entity.host]

and check if you get the desired results.

Hope it helps.

Regards,

Elena.

---

<div class="post-metadata">

**Author:** ![Pablo2](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@Pablo2](https://community.dynatrace.com/u/Pablo2)\
**Post date:** [June 18, 2025, 1:00pm UTC](https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156/3 "2025-06-18T13:00:17Z")

</div>

I always get an empty field in host.name results, it doesnt work for me

---

<div class="post-metadata">

**Author:** ![marco\_irmer](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marco_irmer/32/3038_2.png) [@marco\_irmer](https://community.dynatrace.com/u/marco_irmer)\
**Post date:** [June 19, 2025, 10:07pm UTC](https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156/4 "2025-06-19T22:07:52Z")

</div>

You can use the entityName() function in place of the lookup function to get the host names. The other thing to account for is that the runs\_on[dt.entity.host] field is an Array field. This means we need to expand the array before we use the entityName function. We can then summarize to form an array of host names. The DQL for this looks as follows:

```javascript
fetch dt.entity.service
| expand dt.entity.host=runs_on[dt.entity.host]
| fieldsAdd host_name = entityName(dt.entity.host) // Add the host name
| summarize host_names = collectArray(host_name), by:{id,entity.name} // summarize to create a host_names array
| fieldsAdd entityAttr(dt.entity.host, "tags")
| filter in(id, classicEntitySelector(concat("type(service), tag(\"APP:", $APPLICATION, "\")")))
| filter in(id, classicEntitySelector(concat("type(service), tag(\"ENVIRONMENT:", $ENTORNO, "\")")))
// removed dedup command, as it is no longer needed after using the summarize command above

```

This should work, I hope.

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [July 3, 2025, 2:55pm UTC](https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156/5 "2025-07-03T14:55:45Z")

</div>

Hello&nbsp;[@marco\_irmer](https://community.dynatrace.com/user/19769)

Thanks for your inputs, I’ve tried the suggested DQL Query but it didn’t work, what might be the missing part.

fetch dt.entity.service  
| expand dt.entity.host=runs\_on[dt.entity.host]  
| fieldsAdd host\_name = entityName(dt.entity.host) // Add the host name  
| summarize host\_name = collectArray(host\_name), by:{id,entity.name} // summarize to create a host\_names array  
| fieldsAdd entityAttr(dt.entity.host, “tags”)  
| filter in(id, classicEntitySelector(concat(“type(service), tag(\“Env:” , abc”, \“)”)))  
| filter in(id, classicEntitySelector(concat(“type(service), tag(\“Env:” , xyz”, \“)”)))

BR,

Peter

---

<div class="post-metadata">

**Author:** ![CharlesPerez](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/charlesperez/32/26797_2.png) [@CharlesPerez](https://community.dynatrace.com/u/CharlesPerez)\
**Post date:** [July 11, 2025, 3:02am UTC](https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156/6 "2025-07-11T03:02:38Z")

</div>

Hi&nbsp;[@Peter\_Youssef](https://community.dynatrace.com/user/51369),

Try adding this:

| fieldsAdd dt.entity.host.name = entityAttr(dt.entity.host, “entity.name”)

Regards,  
Charles

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [July 15, 2025, 11:19am UTC](https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156/7 "2025-07-15T11:19:07Z")

</div>

Thanks&nbsp;[@CharlesPerez](https://community.dynatrace.com/user/72255)&nbsp;  
will try it out.

---

<div class="post-metadata">

**Author:** ![StrangerThing](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/strangerthing/32/12182_2.png) [@StrangerThing](https://community.dynatrace.com/u/StrangerThing)\
**Post date:** [July 15, 2025, 2:01pm UTC](https://community.dynatrace.com/t/host-name-in-services-running-on-host-dql/52156/8 "2025-07-15T14:01:21Z")

</div>

Just change your last line with the fields command to this:

```markup
| fields entity.name, serviceType, entity.customized_name, id, entityName(dt.entity.host)

```
