Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdeveloper-portal%2Fapis%2Fdata-management%2Fmetrics-cost-optimizer-api.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdeveloper-portal%2Fapis%2Fdata-management%2Fmetrics-cost-optimizer-api.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# Metrics cost optimizer API

## Overview[​](#overview "Direct link to Overview")

The **Metrics Optimizer API** allows you to drop irrelevant metrics even after ingestion. This API can be used to block or unblock specific metrics and retrieve a list of blocked metrics.

## Authentication[​](#authentication "Direct link to Authentication")

To authenticate requests, create a [customized API key](https://coralogixstg.wpengine.com/docs/api-keys/) with the **Metrics TCOPolicies** role preset assigned to it. Alternatively, selectively add the following permissions to your key:

| Description                   | Action                       |
| ----------------------------- | ---------------------------- |
| `View metrics TCO policies`   | `METRICS.TCO:READ`           |
| `Manage metrics TCO policies` | `METRICS.TCO:UPDATEPOLICIES` |

Find out more about customized API keys [here](https://coralogixstg.wpengine.com/docs/api-keys/).

### Using `grpcurl`[​](#using-grpcurl "Direct link to using-grpcurl")

Use your customized API key in the Authorization request header to successfully connect.

```
grpcurl -H "Authorization: Bearer API_KEY_HERE"
```

Then select the endpoint associated with your Coralogix [domain](https://docs-docusaurus.kinsta.page/user-guides/account-management/account-settings/coralogix-domain/.md).

```
-d @ api.eu2.coralogix.com:443
```

For the Metrics Cost Optimizer API, the service name is `MetricsBlockingRulesService`.

```
com.coralogix.metrics.metrics_blocking_rules.MetricsBlockingRulesService
```

The complete request should look like this:

```
grpcurl -H "Authorization: Bearer API_KEY_HERE" \\

    -d <parameters>

    api.eu2.coralogix.com:443 \\

    com.coralogix.metrics.metrics_blocking_rules.MetricsBlockingRulesService.<method>
```

## Supported APIs[​](#supported-apis "Direct link to Supported APIs")

| API                                                                                  | Description                             |
| ------------------------------------------------------------------------------------ | --------------------------------------- |
| com.coralogix.metrics.metrics\_blocking\_rules.MetricsBlockingRulesService.**Block** | Blocks the specified metric             |
| com.coralogix.metrics.metrics\_blocking\_rules.MetricsBlockingRulesService.**List**  | Retrieves a list of all blocked metrics |
| com.coralogix.metrics.metrics\_blocking\_rules.MetricsBlockingRulesService.**Allow** | Unblocks (allows) the specified metric  |

## Examples[​](#examples "Direct link to Examples")

The following section presents an array of sample requests.

### Block a metric by name[​](#block-a-metric-by-name "Direct link to Block a metric by name")

This method blocks the specified metric. You can block a single metric or multiple metrics at once. To send multiple metrics by name send a array with comma separated metric names. For a single metric, using an array is optional.

**Example: Blocking a single metric**

```
{

  "ruleExpressions": {

    "byMetricName": {

      "name": "block_metric"

    }

  }

}
```

**Example: Blocking multiple metrics**

```
{

  "ruleExpressions": [{

    "byMetricName": {

      "name": "block_metric1"

    },

    "byMetricName": {

      "name": "block_metric2"

    },

    "byMetricName": {

      "name": "block_metric3"

    }

  }]

}
```

**Example: API call**

```
grpcurl -H "Authorization: <..>" \

    -d '{

            "ruleExpression":[{

                "byMetricName":{

                    "name":"blocked_metric"

                 }

             }]

        }' \

    api.eu2.coralogix.com:443 \

    com.coralogix.metrics.metrics_blocking_rules.MetricsBlockingRulesService.Block
```

### List blocked metrics[​](#list-blocked-metrics "Direct link to List blocked metrics")

Retrieve a list of all blocked metrics, including their ruleId, expressions, and metric names. This method can be used to identify metrics that need to be unblocked.

**Sample API call**

```
grpcurl -H "Authorization: <..>" api.eu2.coralogix.com:443 \

    com.coralogix.metrics.metrics_blocking_rules.MetricsBlockingRulesService.List
```

**Sample response**

```
{

  "rules": [

    {

      "ruleId": "3",

      "ruleExpression": {

        "byMetricName": {

          "name": "code:prometheus_http_requests_total:sum1"

        }

      }

    },

    {

      "ruleId": "4",

      "ruleExpression": {

        "byMetricName": {

          "name": "code:prometheus_http_requests_total:sum2"

        }

      }

    },

    {

      "ruleId": "6",

      "ruleExpression": {

        "byMetricName": {

          "name": "test_metric"

        }

      }

    },

    {

      "ruleId": "36",

      "ruleExpression": {

        "byMetricName": {

          "name": "go_gc_duration_seconds_count"

        }

      }

    },

    {

      "ruleId": "37",

      "ruleExpression": {

        "byMetricName": {

          "name": "go_gc_duration_seconds_sum"

        }

      }

    },

    {

      "ruleId": "39",

      "ruleExpression": {

        "byMetricName": {

          "name": "blocked_metric1"

        }

      }

    }

  ]

}
```

### Unblock a metric with `ruleId`[​](#unblock-a-metric-with-ruleid "Direct link to unblock-a-metric-with-ruleid")

This method removes a blocking rule, unblocking the specified metric.

You can unblock a single metric or multiple metrics at once. To send multiple metrics by ruleId, send an array with comma-separated ruleIds. For a single metric, using an array is optional.

**Example: Allowing a single metric**

```
{

  -d '{"ruleIds":39}'

}
```

**Example: Allowing multiple metrics**

```
{

  -d '{"ruleIds":[3,4,6,36]}

}
```

**Example: API call**

```
grpcurl -H "Authorization: <..>" \

    -d '{"ruleIds":[36]} \

    api.eu2.coralogix.com:443 \

    com.coralogix.metrics.metrics_blocking_rules.MetricsBlockingRulesService.Allow
```

## **Response handling**[​](#response-handling "Direct link to response-handling")

The APIs return standardized responses, including the following error codes:

| **Error Code** | **Description**                      | **Method**         |
| -------------- | ------------------------------------ | ------------------ |
| 200            | Success                              | All Methods        |
| 500            | Internal Server Error                | All Methods        |
| 401            | Unauthorized                         | All Methods        |
| 403            | Forbidden                            | All Methods        |
| 404            | Metric or Rule ID not found          | Allow Method       |
| 422            | Invalid Rule Expression or ID Format | Block/Allow Method |
| 409            | Metric Already Blocked               | Block Method       |
| 400            | Bad Request                          | Block Method       |
