Skip to main content

Metrics cost optimizer API

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​

To authenticate requests, create a customized API key with the Metrics TCOPolicies role preset assigned to it. Alternatively, selectively add the following permissions to your key:

DescriptionAction
View metrics TCO policiesMETRICS.TCO:READ
Manage metrics TCO policiesMETRICS.TCO:UPDATEPOLICIES

Find out more about customized API keys here.

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.

-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​

APIDescription
com.coralogix.metrics.metrics_blocking_rules.MetricsBlockingRulesService.BlockBlocks the specified metric
com.coralogix.metrics.metrics_blocking_rules.MetricsBlockingRulesService.ListRetrieves a list of all blocked metrics
com.coralogix.metrics.metrics_blocking_rules.MetricsBlockingRulesService.AllowUnblocks (allows) the specified metric

Examples​

The following section presents an array of sample requests.

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​

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​

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​

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

Error CodeDescriptionMethod
200SuccessAll Methods
500Internal Server ErrorAll Methods
401UnauthorizedAll Methods
403ForbiddenAll Methods
404Metric or Rule ID not foundAllow Method
422Invalid Rule Expression or ID FormatBlock/Allow Method
409Metric Already BlockedBlock Method
400Bad RequestBlock Method
Last updated on
On this page
Was this page helpful?