Metrics 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:
| Description | Action |
|---|---|
View metrics TCO policies | METRICS.TCO:READ |
Manage metrics TCO policies | METRICS.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
| 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
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 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 |