Here are examples of how to use the New Relic REST API (v2) to get the list of instance IDs and host IDs for an application. The list shows any that have reported for approximately the last hour.
List current IDs by application name
You can also use the REST API Explorer's Applications > List to list the ID details. Enter the correct application name.
To list all the instance and host IDs reporting in the last hour with an application name containing ${APP_NAME}
, use the following command. This provides the current Summary data followed by the ID lists for instances and hosts for the applications with ${APP_NAME}
in their name, in the account associated with the ${API_KEY}
.
$curl -X GET 'https://api.newrelic.com/v2/applications.json' \> -H "X-Api-Key:${API_KEY}" -i \> -d "filter[name]=${APP_NAME}"
List current IDs by application ID
You can also use the REST API Explorer's Applications > List or Applications > List to list the ID details. Enter the correct application name.
To list all the IDs reporting in the last hour when you know the application's ${APP_ID}
, use this command:
$curl -X GET "https://api.newrelic.com/v2/applications/${APP_ID}.json" \> -H "X-Api-Key:${API_KEY}" -i
You can also use filter[id]
:
$curl -X GET "https://api.newrelic.com/v2/applications.json" \> -H "X-Api-Key:${API_KEY}" -i \> -d "filter[id]=${APP_ID}"
List current IDs for all applications
You can also use the REST API Explorer's Applications > List or Applications > List to list the ID details. Enter the correct application name.
For all the applications, list all the instance IDs and host IDs reporting in the last hour by using the following command. This provides the current summary data followed by the ID lists for instances and hosts for all the applications in the account associated with the ${API_KEY}
.
$curl -X GET "https://api.newrelic.com/v2/applications.json" \> -H "X-Api-Key:${API_KEY}" -i
Example host ID and instance ID lists
Here is an example of how the lists of IDs appear in JSON format:
...{ "links": { "application_instances": [ <---<<<< {INSTANCE_ID} list 21790, 24810, 27948, 35120, 35121, 35122, 186288, 247253, 247254, 247255, 247256 ], "application_hosts": [ <---<<<< {HOST_ID} list 21788, 24808, 34966, 186283, 247245, 286551 ] }}...