---
title: Scope alert thresholds to specific instances
source: https://docs.newrelic.com/docs/alerts/create-alert/examples/scope-alert-thresholds-specific-instances
---

You can set alert [thresholds](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary#alert-threshold) that trigger when they're breached by any of your Java app's instances. Scoping the condition to instances of your app is helpful for detecting anomalies that occur only in a subset of your app's instances.

These sorts of anomalies are easy to miss for apps that aggregate metrics across a large number of instances. By looking at each instance, you can more quickly identify where potential problems are originating.

## Example [#example]

In this example, you set up a policy for a Java app with three instances. You want to open an alert event when the condition's critical threshold for any instance's error rate is greater than .02% **for at least** five minutes.

During a five-minute time period the three instances have these error rates:

| **App instance** | **4:45pm** | **4:50pm** | **alert event opened?**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ---------------- | ---------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| A                | 0.00%      | 0.00%      | No. This instance remained below the target threshold the entire time.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| B                | 0.02%      | 0.03%      | Yes. The alert threshold exceeded the 0.02% threshold for this instance for at least five minutes.                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| C                | 0.10%      | 0.00%      | No. The threshold value must be breached for [at least five consecutive minutes](https://docs.newrelic.com/docs/alerts/new-relic-alerts/configuring-alert-policies/define-thresholds-trigger-alert#threshold-triggers) to open an alert event. However, if you had set the threshold for **at least once** in five minutes, then the threshold value must be breached [at least once](https://docs.newrelic.com/docs/alerts/new-relic-alerts/configuring-alert-policies/minimum-maximum-values#violation) during the five-minute period. |

## Create instance-based alert condition [#procedure]

/\*  \*/

To create a policy that triggers notifications for alert events by your app's individual instances:

1.  Follow the [basic workflow process](https://docs.newrelic.com/docs/alerts/new-relic-alerts/configuring-alert-policies/alert-policy-workflow#alert-policy-process) to set up a policy.
2.  When creating a [condition](https://docs.newrelic.com/docs/alerts/create-alert/create-alert-condition/alert-conditions) (step 2), select [**APM**](https://docs.newrelic.com/docs/alerts/new-relic-alerts/configuring-alert-policies/select-product-targets-alert-condition).
3.  Select **Application metric** as the type of condition.
4.  To evaluate alert threshold alert events **individually** for each of the app's selected instances, select **Scope to Java application instances**.
5.  Select **Next, select entities**, then identify one or more apps for this condition.
6.  Optional: Change the time when alerts will force-close the alert events (default is 24 hours).
7.  Use **By condition** or **By condition and signal** [alert event preference](https://docs.newrelic.com/docs/alerts/organize-alerts/specify-when-alerts-create-events).
8.  Continue the rest of the [policy workflow process (step 3)](https://docs.newrelic.com/docs/alerts/new-relic-alerts/configuring-alert-policies/alert-policy-workflow#alert-policy-process).

> #### 💡 TIP
>
> To open alert events based on the **average** of all instances for your apps, select **Scope to the application** instead of **Scope to Java application instances**.

## Use "By condition" alert event preference [#targets]

When setting the [alert event preference](https://docs.newrelic.com/docs/alerts/organize-alerts/specify-when-alerts-create-events) for policies containing instance-based conditions, we recommend that you select **By condition** instead of **By condition and signal**. Although apps are the selected entities for this condition, we evaluate each JVM as a separate entity.

If you set your **Alert event preference** to **By condition and signal**, a separate alert event will be opened for each JVM that breaches the critical threshold. When an app fails across multiple JVMs, this can lead to alert "fatigue" and frustration.

## Use REST API for instance alerts

To create instance-based [alert conditions with the New Relic REST API](https://docs.newrelic.com/docs/alerts/new-relic-alerts/rest-api-alerts/manage-entities-alerts-conditions), include these items with your REST API call:

-   Your [API key](https://docs.newrelic.com/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2#api_key).
-   The numeric [`entity_id`](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary#entity) for the [entity](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary#entity) being monitored
-   The [`condition_id`](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary#alert-condition) (available from the API Explorer: [**Alerts Conditions > GET > List**](https://api.newrelic.com/docs/#/Alerts%20Entity%20Conditions))
-   The `entity_type` (set to `"application"`)
-   The `condition_scope` (set to `"instance"` for a Java application instance or `"application"` for a Java app)

Here is an example of the API request format and JSON response.

**Instance alert API call**

Use this format for your API call:

````sh
curl -X PUT 'https://api.newrelic.com/v2/alerts_entity_conditions/12345.json' \
     -H 'X-Api-Key:$API_KEY' -i \
     -H 'Content-Type: application/json' \
     -G -d 'entity_type=application&condition_id=234567'
```

* Replace `$API_KEY` with your [API key](/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2#api_key).

````

**Instance alert JSON response**

The API returns the response as JSON.

````json
{
  "condition": [
    {
      "id": 234567,
      "type": "apm_app_metric",
      "name": "demo",
      "enabled": true,
      "entities": [
        12345
      ],
      "metric": "apdex",
      "condition_scope": "instance",  <---<<< scope indicator
      "violation_close_timer": 24,
      "terms": [
        {
          "duration": "5",
          "operator": "above",
          "priority": "critical",
          "threshold": "1",
          "time_function": "all"
        }
      ]
    }
  ]
}
```

````
