NerdGraph tutorial: View entity data
Entities at New Relic refer to anything we monitor that generates or contains telemetry. Entities help you find the data you want to track in New Relic, and if you understand their relationships with other entities, you can get even more insights into your data. Here are a few examples of entities:
- Applications monitored byAPM.
- Cloud integrations, services, and hosts monitored by ourinfrastructure monitoring.
You can work with entities right in our UI (seeLearn about New Relic entities), or you can follow the steps here about working with entities through our NerdGraph API. If you need help getting started with NerdGraph, see ourIntroduction to New Relic NerdGraph.
Important
To work with an entity's golden metrics and tags, see thegolden metrics API tutorial.
Before you get started
Before working with entities, we recommend readingLearn about entities.
When working with entities, some important things to keep in mind:
- A unique GUID identifies an entity (
entity.guidorentityGuid). - An entity exists in New Relic for aspecific time period.
- An entity provides a useful entry point for exploring data about specific metrics and events or for contextualizing data related to other entities.
Search for entities
New Relic searches for entities by their attributes, primarily their name, but also by type of entity and other values. The search returns basic data about entities matching the search criteria. Then, from the basic query results, you can query a specific entity by its GUID.
BesidesdomainType, other common entity attributes are:
idaccountIdnamedomainIdalertSeverityreporting
You can filter by any of the above attributes. Additionally, you can usetags for filtering.
Caution
You cannot filter by custom, root-level entity properties. Custom properties are only retrieved as part of the entity's metadata in the actual search response. To filter by a custom field, transform it into an entity tag.
You can craft a query in one of two ways:
- Use the
queryBuilderargument to help you craft a query. - Use the freeform
queryargument to build your own search.
To use NerdGraph to query one or more entities, you can search by attribute or GUID.
Tip
NerdGraph sets the total number of entities that can be returned in one query to 200. If you need to retrieve all entities for a query, use cursor pagination as explained in the examples.
In addition tothe examples below, we recommend that you experiment with the API using theNerdGraph explorer. It has inline documentation that will help you construct your queries and mutations.
Search withqueryBuilder
ThequeryBuilder argument is useful to construct simple queries. It allows you to add filters to your query from a predefined list of attributes, and their typical values. For more advanced queries, use thequery argument instead.
Go to the NerdGraphGraphiQL explorer.
Run a basic query to find entities that match your search criteria. For example:
{actor{entitySearch(queryBuilder:{domain:APM,type:APPLICATION}){queryresults{entities{nameentityTypeguid}}}}}
Search with freeformquery
This is useful to craft more complex queries.
Go to the NerdGraphGraphiQL explorer.
Run a basic query to find entities that match your search criteria. For example:
query($query:String!){actor{entitySearch(query:$query){countresults{entities{nameentityTypeguid}}}}}Add the followingvariables to theQuery variables section in NerdGraph:
{"query":"name LIKE 'nerd-graph' AND domainType IN ('APM-APPLICATION')"}
Fetch entities by GUID
When you know the GUID of the entity you want to fetch, you can just use theentity attribute:
{actor{entity(guid:"ENTITY_GUID"){nameentityType}}}This can also be written as a search query:
{actor{entitySearch(query:"id = 'ENTITY_GUID'"){queryresults{entities{nameentityType}}}}}Or, to fetch multiple entities at the same time, you can use theentities attribute:
{actor{entities(guids:["ENTITY_GUID_1","ENTITY_GUID_2"]){nameentityType}}}Otherwise, use a search query:
{actor{entitySearch(query:"id IN ('ENTITY_GUID_1', 'ENTITY_GUID_2')"){queryresults{entities{nameentityType}}}}}Example queries
Queries are requests that are intended to only fetch data (and don't have any other effect). NerdGraph queries are not static, meaning that you can ask for more or less data depending on your needs. For each query, you can specify exactly what data you want to retrieve, as long as it's supported by the schema.
Entities in NerdGraph rely onGraphQL interfaces, a concept that allows objects to share common fields. Interfaces are used to provide data for specific entity types, as you will see in many of these NerdGraph query examples.
Create or delete entity relationships
An entity may have a relationship with another entity. Some relationships arecreated automatically by New Relic, but you can also use mutations to create or delete custom relationships. We have some explanations below about how to do this, but if you need help understanding the various relationship types at New Relic, take a look atEntity relationships.
Before you manually create additional relationships or delete them, keep the following in mind:
- Two entities can have multiple relationships, one for each relationship type.
- Two entities can hold a relationship IF they belong to the same trusted account.
- For each entity, you can manually define up to 2000 relationships. When the limit is reached, the API will return a
LIMIT_EXCEEDEDerror. - Each mutation can fail if you don't have access to one of the two entities (source/target).
List relationships of an entity
You can use therelatedEntities field to see how pairs of entities interact and how they're related. This can help you troubleshoot upstream and downstream services and understand how minor issues may have larger repercussions, similar to howservice maps can be used.
The following example shows how to query an entity by its specific GUID:
query{actor{entity(guid:"ENTITY_GUID"){namerelatedEntities{results{source{entity{guidname}}target{entity{guidname}}type}}}}}Create or replace relationships
Create or replace entity relationships using the mutationentityRelationshipUserDefinedCreateOrReplace. As its name suggests, it allows you to create a relationship between two entities with a given type. If the relationship already exists between the two entities, it will be added again with the updated given values (the creation time and the creator user id):
mutation{entityRelationshipUserDefinedCreateOrReplace(sourceEntityGuid:"SOURCE_ENTITY_GUID"targetEntityGuid:"TARGET_ENTITY_GUID"type:BUILT_FROM){errors{messagetype}}}Delete relationships
Delete entity relationships using the mutationentityRelationshipUserDefinedDelete. The source and target are mandatory, but the type isn't. If you execute the mutation without type, all the relationships between the two entities are removed.
mutation{entityRelationshipUserDefinedDelete(sourceEntityGuid:"SOURCE_ENTITY_GUID"targetEntityGuid:"TARGET_ENTITY_GUID"type:BUILT_FROM){errors{messagetype}}}Delete entities
You can manually delete any entity in your account by using the NerdGraph API in theNerdGraph GraphiQL explorer.
To deleteEXT-SERVICE andREF-REPOSITORY entities, run this mutation with the entity's GUID:
mutation{entityDelete(guids:["ENTITY_GUID_1","ENTITY_GUID_2"]){deletedEntitiesfailures{guidmessage}}}Important
After running theentityDelete mutation, you may see a deleted entity in your UI if a New Relic agent reindexes it again.
To deleteAPM,BROWSER andMOBILE entities, run this mutation with the entity's GUID:
mutation{agentApplicationDelete(guid:"ENTITY_GUID"){success}}Important
- The
agentApplicationDeletemutation requires that the New Relic agent must not have reporting data for 12 hours before deletion. - Currently, you can only remove the followingentity types using the Nerdgraph API:
APM-APPLICATION,EXT-SERVICE, andREF-REPOSITORY. - You may see a deleted entity in your UI if a New Relic agent reindexes it again.
On this page
Was this doc helpful?