---
title: NerdGraph tutorial: Managing the Metric Normalization Rules
source: https://docs.newrelic.com/docs/apis/nerdgraph/examples/nerdgraph-metric-normalization-rule
---

> #### 💡 PREVIEW
>
> We're still working on this feature, but we'd love for you to try it out!
> This feature is currently provided as part of a preview program pursuant to our [pre-release policies](https://docs.newrelic.com/docs/licenses/license-information/referenced-policies/new-relic-pre-release-policy).

You can use [NerdGraph](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph/) mutations to manage [metric normalization rules](https://docs.newrelic.com/docs/new-relic-solutions/new-relic-one/ui-data/metric-normalization-rules) in New Relic. By leveraging these mutations, you can create, edit, enable, and disable these rules directly from your New Relic account. This provides a streamlined and programmatic approach to resolve [Metric Grouping Issues (MGIs).](https://docs.newrelic.com/docs/new-relic-solutions/solve-common-issues/troubleshooting/metric-grouping-issues)

The metric normalization rules are used to:

-   Group or filter out [metric timeslice data](https://docs.newrelic.com/docs/data-apis/understand-data/new-relic-data-types/#timeslice-data).
-   Manage high cardinality metrics by renaming, dropping, or transforming them before they're ingested into New Relic.
-   Prevent [MGIs](https://docs.newrelic.com/docs/new-relic-solutions/solve-common-issues/troubleshooting/metric-grouping-issues) to ensure that your metrics are well-organized and meaningful.
-   Reduce the number of unique metric names reported to New Relic.

## Prerequisites [#prerequisites]

-   A [New Relic account](https://newrelic.com/signup), and with that account, you can access your API user key that you need to include with [queries and mutations](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph).

-   User type and assigned roles can affect your NerdGraph permissions. For more details, see [Factors affecting access](https://docs.newrelic.com/docs/accounts/accounts-billing/account-structure/factors-affecting-access-features-data#user-permissions).

> #### 💡 TIP
>
> You can also create metric normalization rule by using the New Relic platform. For more information, refer to [Metric normalization rules](https://docs.newrelic.com/docs/new-relic-solutions/new-relic-one/ui-data/metric-normalization-rules).

## Retrieve the metric normalization rules [#nerdgraph-query]

Use the `metricNormalizationRules` query to retrieve all metric normalization rules associated with your account. This query provides a comprehensive overview of the existing rules, including their status and configuration.

### Input parameters

| Attribute name | Data type | Description                                                   |
| -------------- | --------- | ------------------------------------------------------------- |
| `accountId`    | String    | (Required) The account ID associated with the rule.           |
| `enable`       | Boolean   | (Required) If set to `true`, only enabled rules are returned. |

### Sample query

```graphql

    {
        actor {
            user {
            name
            }
            account(id: xxxxxx) {
            metricNormalization {
                metricNormalizationRules(enabled: true) {
                action
                applicationGuid
                applicationName
                createdAt
                enabled
                evalOrder
                id
                matchExpression
                notes
                replacement
                terminateChain
                }
            }
            }
        }
    }

```

## Mutations [#nerdgraph-mutations]

Manage your metric normalization rules with the following [NerdGraph mutations](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph/#terminology):

**Create a metric normalization rule**

Use the `metricNormalizationCreateRule` mutation to create a new metric normalization rule in New Relic.

### Input parameters

| Attribute name  | Data type | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| --------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| accountId       | String    | (Required) The account ID associated with the rule.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| action          | String    | (Required) Select one of the following action: - `REPLACE`: Replace the metrics that match the `matchExpression` with the value defined in the `replacement` field. - `IGNORE`: Block any metrics from reporting to New Relic that match `matchExpression`. - `DENY_NEW_METRICS`: Prevent the creation of new metric names that match the `matchExpression`, while allowing existing metric names to continue reporting.                                                                          |
| applicationGuid | String    | (Optional) The unique GUID for the application in New Relic. If left blank, this becomes an account-wide rule.                                                                                                                                                                                                                                                                                                                                                                                    |
| enabled         | Boolean   | (Required) To enable the rule, set to `true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| evalOrder       | Integer   | (Required) Specify the order in which the rule is applied relative to other rules. The lower the number, the higher the evaluated priority. Recommend value is `2000`.                                                                                                                                                                                                                                                                                                                            |
| matchExpression | String    | (Required) Accepts a [regular expression](https://regexone.com/) pattern that matches the metrics to be normalized. This field must start with a `^` and end with a `$`. It defines a pattern to identify which metrics should be affected by the normalization rule. For example: `^WebTransaction/Uri/RESTfulExample/users/username/[a-zA-Z0-9]+$` The pattern `^[a-zA-Z0-9]+$` matches any string composed of lowercase characters `(a-z)`, uppercase characters `(A-Z)`, and numbers `(0-9)`. |
| notes           | String    | Additional notes or comments about the normalization rule.                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| replacement     | String    | This field is only required when the `REPLACE` option is selected from the `action` drop-down list. It replaces any metric name that matches `matchExpression`. For example: `WebTransaction/Uri/RESTfulExample/users/username/{username}$`                                                                                                                                                                                                                                                       |
| terminateChain  | Boolean   | (Required) If set to `true`, no further rules will apply on the matched metrics.                                                                                                                                                                                                                                                                                                                                                                                                                  |

### Sample query

```graphql

    mutation {
        metricNormalizationCreateRule(
            accountId: xxxxxx
            rule: {action: REPLACE, applicationGuid: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", enabled: false, evalOrder: 2000, matchExpression: "^WebTransaction/Uri/MGIGenerator_war_exploded/api/MGI/pattern/[a-f0-9]+$", notes: "rules to replace", replacement: "WebTransaction/Uri/MGIGenerator_war_exploded/api/MGI/pattern/{guid}", terminateChain: true}
        ) {
            errors {
                message
                type
            }
            rule {
                action
                applicationGuid
                applicationName
                createdAt
                enabled
                evalOrder
                id
                matchExpression
                notes
                replacement
                terminateChain
            }
        }
    }

```

### Sample response

```graphql

    {
        "data": {
            "metricNormalizationCreateRule": {
                "errors": [],
                "rule": {
                    "action": "REPLACE",
                    "applicationGuid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                    "applicationName": "MetricGroupingIssue",
                    "createdAt": 1743641443000,
                    "enabled": false,
                    "evalOrder": 2000,
                    "id": 29205,
                    "matchExpression": "^WebTransaction/Uri/MGIGenerator_war_exploded/api/MGI/pattern/[a-f0-9]+$",
                    "notes": "rules to replace",
                    "replacement": "WebTransaction/Uri/MGIGenerator_war_exploded/api/MGI/pattern/{guid}",
                    "terminateChain": true
                }
            }
        }
    }

```

**Edit a metric normalization rule**

Use the `metricNormalizationEditRule` mutation to update the value of the existing rule using the `ruleId` parameters. It provides flexibility to adjust the rule as per the new insights or changing requirements. You can fetch `ruleId` information using [`Retrieve the metric normalization rules`](#nerdgraph-query) query.

### Input parameters

| Attribute name  | Data type | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| --------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| accountId       | String    | (Required) The account ID associated with the rule.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| action          | String    | (Required) Select one of the following action: - `REPLACE`: Replace the metrics that match the `matchExpression` with the value defined in the `replacement` field. - `IGNORE`: Block any metrics from reporting to New Relic that match `matchExpression`. - `DENY_NEW_METRICS`: Prevent the creation of new metric names that match the `matchExpression`, while allowing existing metric names to continue reporting.                                                                          |
| applicationGuid | String    | (Optional) The unique GUID for the application in New Relic. If left blank, this becomes an account-wide rule.                                                                                                                                                                                                                                                                                                                                                                                    |
| enabled         | Boolean   | (Required) To enable the rule, set to `true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| evalOrder       | Integer   | (Required) Specify the order in which the rule is applied relative to other rules. The lower the number, the higher the evaluated priority. Recommend value is `2000`.                                                                                                                                                                                                                                                                                                                            |
| id              | String    | (Required) The `ruleId` of the metric rule for which you want to update the value.                                                                                                                                                                                                                                                                                                                                                                                                                |
| matchExpression | String    | (Required) Accepts a [regular expression](https://regexone.com/) pattern that matches the metrics to be normalized. This field must start with a `^` and end with a `$`. It defines a pattern to identify which metrics should be affected by the normalization rule. For example: `^WebTransaction/Uri/RESTfulExample/users/username/[a-zA-Z0-9]+$` The pattern `^[a-zA-Z0-9]+$` matches any string composed of lowercase characters `(a-z)`, uppercase characters `(A-Z)`, and numbers `(0-9)`. |
| notes           | String    | Additional notes or comments about the normalization rule.                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| replacement     | String    | This field is only required when the `REPLACE` option is selected from the `action` drop-down list. It replaces any metric name that matches `matchExpression`. For example: `WebTransaction/Uri/RESTfulExample/users/username/{username}$`                                                                                                                                                                                                                                                       |
| terminateChain  | Boolean   | (Required) If set to `true`, no further rules will apply on the matched metrics.                                                                                                                                                                                                                                                                                                                                                                                                                  |

### Sample query

```graphql

    mutation {
        metricNormalizationEditRule(
            accountId: xxxxx
            rule: {id: 29205, notes: "rules to replace", matchExpression: "^WebTransaction/Uri/MGIGenerator_war_exploded/api/MGI/pattern/[a-f0-9]+$", action: REPLACE, enabled: false, replacement: "WebTransaction/Uri/MGIGenerator_war_exploded/api/MGI/pattern/{guid}"}
        ) {
            errors {
                message
                type
            }
            rule {
                action
                applicationGuid
                applicationName
                createdAt
                enabled
                evalOrder
                id
                matchExpression
                notes
                replacement
                terminateChain
            }
        }
    }

```

**Enable a metric normalization rule**

Use the `metricNormalizationEnableRule` mutation to enable a previously disabled rule using the `accountId` and `ruleId` parameters. You can fetch these parameters using [`Retrieve the metric normalization rules`](#nerdgraph-query) query.

### Input Parameters

| Attribute name | Data type | Description                                         |
| -------------- | --------- | --------------------------------------------------- |
| accountId      | String    | (Required) The account ID associated with the rule. |
| ruleId         | String    | (Required) The `ruleId` of the metric rule.         |

### Example query

```graphql

    mutation {
        metricNormalizationEnableRule(accountId: xxxxxx, ruleId: 29205) {
            errors {
                message
                type
            }
            rule {
                action
                applicationGuid
                applicationName
                createdAt
                enabled
                evalOrder
                id
                matchExpression
                notes
                replacement
                terminateChain
            }
        }
    }

```

**Disable a metric normalization rule**

Use `metricNormalizationDisableRule` mutation to disables a previously enabled rule using the `accountId` and `ruleId` parameters. You can fetch these parameters using [`Retrieve the metric normalization rules`](#nerdgraph-query) query.

### Input Parameters

| Attribute name | Data type | Description                                         |
| -------------- | --------- | --------------------------------------------------- |
| accountId      | String    | (Required) The account ID associated with the rule. |
| ruleId         | String    | (Required) The `ruleId` of the metric rule.         |

### Example query

```graphql

    mutation {
        metricNormalizationDisableRule(accountId: xxxxxx, ruleId: 29205) {
            errors {
                message
                type
            }
            rule {
                action
                applicationGuid
                applicationName
                createdAt
                enabled
                evalOrder
                id
                matchExpression
                notes
                replacement
                terminateChain
            }
        }
    }

```
