Logs Metrics

Manage configuration of log-based metrics for your organization.

GET https://api.ap1.datadoghq.com/api/v2/logs/config/metricshttps://api.datadoghq.eu/api/v2/logs/config/metricshttps://api.ddog-gov.com/api/v2/logs/config/metricshttps://api.datadoghq.com/api/v2/logs/config/metricshttps://api.us3.datadoghq.com/api/v2/logs/config/metricshttps://api.us5.datadoghq.com/api/v2/logs/config/metrics

개요

Get the list of configured log-based metrics with their definitions. This endpoint requires the logs_read_config permission.

응답

OK

All the available log-based metric objects.

Expand All

항목

유형

설명

data

[object]

A list of log-based metric objects.

attributes

object

The object describing a Datadog log-based metric.

compute

object

The compute rule to compute the log-based metric.

aggregation_type

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

group_by

[object]

The rules for the group by.

path

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id

string

The name of the log-based metric.

type

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": [
    {
      "attributes": {
        "compute": {
          "aggregation_type": "distribution",
          "include_percentiles": true,
          "path": "@duration"
        },
        "filter": {
          "query": "service:web* AND @http.status_code:[200 TO 299]"
        },
        "group_by": [
          {
            "path": "@http.status_code",
            "tag_name": "status_code"
          }
        ]
      },
      "id": "logs.page.load.count",
      "type": "logs_metrics"
    }
  ]
}

Not Authorized

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

코드 사례

// Get all log-based metrics returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_logs_metrics::LogsMetricsAPI;

#[tokio::main]
async fn main() {
    let configuration = datadog::Configuration::new();
    let api = LogsMetricsAPI::with_config(configuration);
    let resp = api.list_logs_metrics().await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Instructions

First install the library and its dependencies and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run

POST https://api.ap1.datadoghq.com/api/v2/logs/config/metricshttps://api.datadoghq.eu/api/v2/logs/config/metricshttps://api.ddog-gov.com/api/v2/logs/config/metricshttps://api.datadoghq.com/api/v2/logs/config/metricshttps://api.us3.datadoghq.com/api/v2/logs/config/metricshttps://api.us5.datadoghq.com/api/v2/logs/config/metrics

개요

Create a metric based on your ingested logs in your organization. Returns the log-based metric object from the request body when the request is successful. This endpoint requires the logs_generate_metrics permission.

요청

Body Data (required)

The definition of the new log-based metric.

Expand All

항목

유형

설명

data [required]

object

The new log-based metric properties.

attributes [required]

object

The object describing the Datadog log-based metric to create.

compute [required]

object

The compute rule to compute the log-based metric.

aggregation_type [required]

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

default: *

group_by

[object]

The rules for the group by.

path [required]

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id [required]

string

The name of the log-based metric.

type [required]

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "id": "ExampleLogsMetric",
    "type": "logs_metrics",
    "attributes": {
      "compute": {
        "aggregation_type": "distribution",
        "include_percentiles": true,
        "path": "@duration"
      }
    }
  }
}

응답

OK

The log-based metric object.

Expand All

항목

유형

설명

data

object

The log-based metric properties.

attributes

object

The object describing a Datadog log-based metric.

compute

object

The compute rule to compute the log-based metric.

aggregation_type

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

group_by

[object]

The rules for the group by.

path

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id

string

The name of the log-based metric.

type

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "attributes": {
      "compute": {
        "aggregation_type": "distribution",
        "include_percentiles": true,
        "path": "@duration"
      },
      "filter": {
        "query": "service:web* AND @http.status_code:[200 TO 299]"
      },
      "group_by": [
        {
          "path": "@http.status_code",
          "tag_name": "status_code"
        }
      ]
    },
    "id": "logs.page.load.count",
    "type": "logs_metrics"
  }
}

Bad Request

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Authorized

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Conflict

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

코드 사례

// Create a log-based metric returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_logs_metrics::LogsMetricsAPI;
use datadog_api_client::datadogV2::model::LogsMetricCompute;
use datadog_api_client::datadogV2::model::LogsMetricComputeAggregationType;
use datadog_api_client::datadogV2::model::LogsMetricCreateAttributes;
use datadog_api_client::datadogV2::model::LogsMetricCreateData;
use datadog_api_client::datadogV2::model::LogsMetricCreateRequest;
use datadog_api_client::datadogV2::model::LogsMetricType;

#[tokio::main]
async fn main() {
    let body = LogsMetricCreateRequest::new(LogsMetricCreateData::new(
        LogsMetricCreateAttributes::new(
            LogsMetricCompute::new(LogsMetricComputeAggregationType::DISTRIBUTION)
                .include_percentiles(true)
                .path("@duration".to_string()),
        ),
        "ExampleLogsMetric".to_string(),
        LogsMetricType::LOGS_METRICS,
    ));
    let configuration = datadog::Configuration::new();
    let api = LogsMetricsAPI::with_config(configuration);
    let resp = api.create_logs_metric(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Instructions

First install the library and its dependencies and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run

GET https://api.ap1.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.eu/api/v2/logs/config/metrics/{metric_id}https://api.ddog-gov.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us3.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us5.datadoghq.com/api/v2/logs/config/metrics/{metric_id}

개요

Get a specific log-based metric from your organization. This endpoint requires the logs_read_config permission.

인수

경로 파라미터

이름

유형

설명

metric_id [required]

string

The name of the log-based metric.

응답

OK

The log-based metric object.

Expand All

항목

유형

설명

data

object

The log-based metric properties.

attributes

object

The object describing a Datadog log-based metric.

compute

object

The compute rule to compute the log-based metric.

aggregation_type

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

group_by

[object]

The rules for the group by.

path

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id

string

The name of the log-based metric.

type

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "attributes": {
      "compute": {
        "aggregation_type": "distribution",
        "include_percentiles": true,
        "path": "@duration"
      },
      "filter": {
        "query": "service:web* AND @http.status_code:[200 TO 299]"
      },
      "group_by": [
        {
          "path": "@http.status_code",
          "tag_name": "status_code"
        }
      ]
    },
    "id": "logs.page.load.count",
    "type": "logs_metrics"
  }
}

Not Authorized

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

코드 사례

// Get a log-based metric returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_logs_metrics::LogsMetricsAPI;

#[tokio::main]
async fn main() {
    // there is a valid "logs_metric" in the system
    let logs_metric_data_id = std::env::var("LOGS_METRIC_DATA_ID").unwrap();
    let configuration = datadog::Configuration::new();
    let api = LogsMetricsAPI::with_config(configuration);
    let resp = api.get_logs_metric(logs_metric_data_id.clone()).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Instructions

First install the library and its dependencies and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run

PATCH https://api.ap1.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.eu/api/v2/logs/config/metrics/{metric_id}https://api.ddog-gov.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us3.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us5.datadoghq.com/api/v2/logs/config/metrics/{metric_id}

개요

Update a specific log-based metric from your organization. Returns the log-based metric object from the request body when the request is successful. This endpoint requires the logs_generate_metrics permission.

인수

경로 파라미터

이름

유형

설명

metric_id [required]

string

The name of the log-based metric.

요청

Body Data (required)

New definition of the log-based metric.

Expand All

항목

유형

설명

data [required]

object

The new log-based metric properties.

attributes [required]

object

The log-based metric properties that will be updated.

compute

object

The compute rule to compute the log-based metric.

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

default: *

group_by

[object]

The rules for the group by.

path [required]

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

type [required]

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "type": "logs_metrics",
    "attributes": {
      "filter": {
        "query": "service:web* AND @http.status_code:[200 TO 299]-updated"
      }
    }
  }
}
{
  "data": {
    "type": "logs_metrics",
    "attributes": {
      "compute": {
        "include_percentiles": false
      }
    }
  }
}

응답

OK

The log-based metric object.

Expand All

항목

유형

설명

data

object

The log-based metric properties.

attributes

object

The object describing a Datadog log-based metric.

compute

object

The compute rule to compute the log-based metric.

aggregation_type

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

group_by

[object]

The rules for the group by.

path

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id

string

The name of the log-based metric.

type

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "attributes": {
      "compute": {
        "aggregation_type": "distribution",
        "include_percentiles": true,
        "path": "@duration"
      },
      "filter": {
        "query": "service:web* AND @http.status_code:[200 TO 299]"
      },
      "group_by": [
        {
          "path": "@http.status_code",
          "tag_name": "status_code"
        }
      ]
    },
    "id": "logs.page.load.count",
    "type": "logs_metrics"
  }
}

Bad Request

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Authorized

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

코드 사례

// Update a log-based metric returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_logs_metrics::LogsMetricsAPI;
use datadog_api_client::datadogV2::model::LogsMetricFilter;
use datadog_api_client::datadogV2::model::LogsMetricType;
use datadog_api_client::datadogV2::model::LogsMetricUpdateAttributes;
use datadog_api_client::datadogV2::model::LogsMetricUpdateData;
use datadog_api_client::datadogV2::model::LogsMetricUpdateRequest;

#[tokio::main]
async fn main() {
    // there is a valid "logs_metric" in the system
    let logs_metric_data_id = std::env::var("LOGS_METRIC_DATA_ID").unwrap();
    let body = LogsMetricUpdateRequest::new(LogsMetricUpdateData::new(
        LogsMetricUpdateAttributes::new().filter(
            LogsMetricFilter::new()
                .query("service:web* AND @http.status_code:[200 TO 299]-updated".to_string()),
        ),
        LogsMetricType::LOGS_METRICS,
    ));
    let configuration = datadog::Configuration::new();
    let api = LogsMetricsAPI::with_config(configuration);
    let resp = api
        .update_logs_metric(logs_metric_data_id.clone(), body)
        .await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
// Update a log-based metric with include_percentiles field returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_logs_metrics::LogsMetricsAPI;
use datadog_api_client::datadogV2::model::LogsMetricType;
use datadog_api_client::datadogV2::model::LogsMetricUpdateAttributes;
use datadog_api_client::datadogV2::model::LogsMetricUpdateCompute;
use datadog_api_client::datadogV2::model::LogsMetricUpdateData;
use datadog_api_client::datadogV2::model::LogsMetricUpdateRequest;

#[tokio::main]
async fn main() {
    // there is a valid "logs_metric_percentile" in the system
    let logs_metric_percentile_data_id = std::env::var("LOGS_METRIC_PERCENTILE_DATA_ID").unwrap();
    let body = LogsMetricUpdateRequest::new(LogsMetricUpdateData::new(
        LogsMetricUpdateAttributes::new()
            .compute(LogsMetricUpdateCompute::new().include_percentiles(false)),
        LogsMetricType::LOGS_METRICS,
    ));
    let configuration = datadog::Configuration::new();
    let api = LogsMetricsAPI::with_config(configuration);
    let resp = api
        .update_logs_metric(logs_metric_percentile_data_id.clone(), body)
        .await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Instructions

First install the library and its dependencies and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run

DELETE https://api.ap1.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.eu/api/v2/logs/config/metrics/{metric_id}https://api.ddog-gov.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us3.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us5.datadoghq.com/api/v2/logs/config/metrics/{metric_id}

개요

Delete a specific log-based metric from your organization. This endpoint requires the logs_generate_metrics permission.

인수

경로 파라미터

이름

유형

설명

metric_id [required]

string

The name of the log-based metric.

응답

OK

Not Authorized

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

항목

유형

설명

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

코드 사례

// Delete a log-based metric returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_logs_metrics::LogsMetricsAPI;

#[tokio::main]
async fn main() {
    // there is a valid "logs_metric" in the system
    let logs_metric_data_id = std::env::var("LOGS_METRIC_DATA_ID").unwrap();
    let configuration = datadog::Configuration::new();
    let api = LogsMetricsAPI::with_config(configuration);
    let resp = api.delete_logs_metric(logs_metric_data_id.clone()).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Instructions

First install the library and its dependencies and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run