Application Hosts

newrelic_api.application_hosts

class newrelic_api.application_hosts.ApplicationHosts(api_key=None)

An interface for interacting with the New Relic Application Hosts API.

__init__(api_key=None)
Parameters:api_key (str) – The API key. If no key is passed, the environment variable NEW_RELIC_API_KEY is used.
Raises:If the api_key parameter is not present, and no environment variable is present, a newrelic_api.exceptions.ConfigurationException is raised.
list(application_id, filter_hostname=None, filter_ids=None, page=None)

This API endpoint returns a paginated list of hosts associated with the given application.

Application hosts can be filtered by hostname, or the list of application host IDs.

Parameters:
  • application_id (int) – Application ID
  • filter_hostname (str) – Filter by server hostname
  • filter_ids (list of ints) – Filter by application host ids
  • page (int) – Pagination index
Return type:

dict

Returns:

The JSON response of the API, with an additional ‘pages’ key if there are paginated results

{
    "application_hosts": [
        {
            "id": "integer",
            "application_name": "string",
            "host": "string",
            "language": "integer",
            "health_status": "string",
            "application_summary": {
                "response_time": "float",
                "throughput": "float",
                "error_rate": "float",
                "apdex_score": "float"
            },
            "end_user_summary": {
                "response_time": "float",
                "throughput": "float",
                "apdex_score": "float"
            },
            "links": {
                "application": "integer",
                "application_instances": [
                    "integer"
                ],
                "server": "integer"
            }
        }
    ],
    "pages": {
        "last": {
            "url": "https://api.newrelic.com/v2/applications/{application_id}/hosts.json?page=2",
            "rel": "last"
        },
        "next": {
            "url": "https://api.newrelic.com/v2/applications/{application_id}/hosts.json?page=2",
            "rel": "next"
        }
    }
}
metric_data(application_id, host_id, names, values=None, from_dt=None, to_dt=None, summarize=False)

This API endpoint returns a list of values for each of the requested metrics. The list of available metrics can be returned using the Metric Name API endpoint. Metric data can be filtered by a number of parameters, including multiple names and values, and by time range. Metric names and values will be matched intelligently in the background. You can also retrieve a summarized data point across the entire time range selected by using the summarize parameter.

Note All times sent and received are formatted in UTC. The default time range is the last 30 minutes.

Parameters:
  • application_id (int) – Application ID
  • host_id (int) – Application Host ID
  • names (list of str) – Retrieve specific metrics by name
  • values (list of str) – Retrieve specific metric values
  • from_dt (datetime) – Retrieve metrics after this time
  • to_dt (datetime) – Retrieve metrics before this time
  • summarize (bool) – Summarize the data
Return type:

dict

Returns:

The JSON response of the API

{
    "metric_data": {
        "from": "time",
        "to": "time",
        "metrics": [
            {
                "name": "string",
                "timeslices": [
                    {
                        "from": "time",
                        "to": "time",
                        "values": "hash"
                    }
                ]
            }
        ]
    }
}
metric_names(application_id, host_id, name=None, page=None)

Return a list of known metrics and their value names for the given resource.

Parameters:
  • application_id (int) – Application ID
  • host_id (int) – Application Host ID
  • name (str) – Filter metrics by name
  • page (int) – Pagination index
Return type:

dict

Returns:

The JSON response of the API, with an additional ‘pages’ key if there are paginated results

{
    "metrics": [
        {
            "name": "string",
            "values": [
                "string"
            ]
        }
    ],
    "pages": {
        "last": {
            "url": "https://api.newrelic.com/v2/applications/{application_id}/hosts/{host_id}/metrics.json?page=2",
            "rel": "last"
        },
        "next": {
            "url": "https://api.newrelic.com/v2/applications/{application_id}/hosts/{host_id}/metrics.json?page=2",
            "rel": "next"
        }
    }
}
show(application_id, host_id)

This API endpoint returns a single application host, identified by its ID.

Parameters:
  • application_id (int) – Application ID
  • host_id (int) – Application host ID
Return type:

dict

Returns:

The JSON response of the API

{
    "application_host": {
        "id": "integer",
        "application_name": "string",
        "host": "string",
        "language": "integer",
        "health_status": "string",
        "application_summary": {
            "response_time": "float",
            "throughput": "float",
            "error_rate": "float",
            "apdex_score": "float"
        },
        "end_user_summary": {
            "response_time": "float",
            "throughput": "float",
            "apdex_score": "float"
        },
        "links": {
            "application": "integer",
            "application_instances": [
                "integer"
            ],
            "server": "integer"
        }
    }
}