POST https://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/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.
The definition of the new log-based metric.
Field
Type
Description
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
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 [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
{
"data": {
"attributes": {
"compute": {
"aggregation_type": "distribution",
"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"
}
}
OK
The log-based metric object.
Field
Type
Description
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
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
{
"data": {
"attributes": {
"compute": {
"aggregation_type": "distribution",
"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.
{
"errors": [
"Bad Request"
]
}
Not Authorized
API error response.
{
"errors": [
"Bad Request"
]
}
Conflict
API error response.
{
"errors": [
"Bad Request"
]
}
Too many requests
API error response.
{
"errors": [
"Bad Request"
]
}
# Curl command
curl -X POST "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v2/logs/config/metrics" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_CLIENT_APP_KEY}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"aggregation_type": "distribution"
},
"group_by": [
{
"path": "@http.status_code"
}
]
},
"id": "logs.page.load.count",
"type": "logs_metrics"
}
}
EOF
package main
import (
"context"
"encoding/json"
"fmt"
"os"
datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog"
)
func main() {
ctx := context.WithValue(
context.Background(),
datadog.ContextAPIKeys,
map[string]datadog.APIKey{
"apiKeyAuth": {
Key: os.Getenv("DD_CLIENT_API_KEY"),
},
"appKeyAuth": {
Key: os.Getenv("DD_CLIENT_APP_KEY"),
},
},
)
if site, ok := os.LookupEnv("DD_SITE"); ok {
ctx = context.WithValue(
ctx,
datadog.ContextServerVariables,
map[string]string{"site": site},
)
}
body := *datadog.NewLogsMetricCreateRequest(*datadog.NewLogsMetricCreateData(*datadog.NewLogsMetricCreateAttributes(*datadog.NewLogsMetricCompute(datadog.LogsMetricComputeAggregationType("count"))), "logs.page.load.count", datadog.LogsMetricType("logs_metrics"))) // LogsMetricCreateRequest | The definition of the new log-based metric.
configuration := datadog.NewConfiguration()
api_client := datadog.NewAPIClient(configuration)
resp, r, err := api_client.LogsMetricsApi.CreateLogsMetric(ctx).Body(body).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.CreateLogsMetric``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `CreateLogsMetric`: LogsMetricResponse
response_content, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from LogsMetricsApi.CreateLogsMetric:\n%s\n", response_content)
}
First install the library and its dependencies and then save the example to main.go
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
go "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v2.client.ApiClient;
import com.datadog.api.v2.client.ApiException;
import com.datadog.api.v2.client.Configuration;
import com.datadog.api.v2.client.auth.*;
import com.datadog.api.v2.client.model.*;
import com.datadog.api.v2.client.api.LogsMetricsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure the Datadog site to send API calls to
HashMap<String, String> serverVariables = new HashMap<String, String>();
String site = System.getenv("DD_SITE");
if (site != null) {
serverVariables.put("site", site);
defaultClient.setServerVariables(serverVariables);
}
// Configure API key authorization:
HashMap<String, String> secrets = new HashMap<String, String>();
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
defaultClient.configureApiKeys(secrets);
LogsMetricsApi apiInstance = new LogsMetricsApi(defaultClient);
LogsMetricCreateRequest body = new LogsMetricCreateRequest(); // LogsMetricCreateRequest | The definition of the new log-based metric.
try {
LogsMetricResponse result = apiInstance.createLogsMetric()
.body(body)
.execute();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling LogsMetricsApi#createLogsMetric");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
First install the library and its dependencies and then save the example to Example.java
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v2 import ApiClient, ApiException, Configuration
from datadog_api_client.v2.api import logs_metrics_api
from datadog_api_client.v2.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()
# Defining the site is optional and defaults to datadoghq.com
if "DD_SITE" in os.environ:
configuration.server_variables["site"] = os.environ["DD_SITE"]
# Configure API key authorization: apiKeyAuth
configuration.api_key['apiKeyAuth'] = os.getenv('DD_CLIENT_API_KEY')
# Configure API key authorization: appKeyAuth
configuration.api_key['appKeyAuth'] = os.getenv('DD_CLIENT_APP_KEY')
# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = logs_metrics_api.LogsMetricsApi(api_client)
body = LogsMetricCreateRequest(
data=LogsMetricCreateData(
attributes=LogsMetricCreateAttributes(
compute=LogsMetricCompute(
aggregation_type=LogsMetricComputeAggregationType("distribution"),
path="@duration",
),
filter=LogsMetricFilter(
query="service:web* AND @http.status_code:[200 TO 299]",
),
group_by=[
LogsMetricGroupBy(
path="@http.status_code",
tag_name="status_code",
),
],
),
id="logs.page.load.count",
type=LogsMetricType("logs_metrics"),
),
) # LogsMetricCreateRequest | The definition of the new log-based metric.
# example passing only required values which don't have defaults set
try:
# Create a log-based metric
api_response = api_instance.create_logs_metric(body)
pprint(api_response)
except ApiException as e:
print("Exception when calling LogsMetricsApi->create_logs_metric: %s\n" % e)
First install the library and its dependencies and then save the example to example.py
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
python3 "example.py"
require 'time'
require 'datadog_api_client'
DatadogAPIClient::V2.configure do |config|
# Defining the site is optional and defaults to datadoghq.com
config.server_variables['site'] = ENV["DD_SITE"] if ENV.key? 'DD_SITE'
# setup authorization
# Configure API key authorization: apiKeyAuth
config.api_key['apiKeyAuth'] = ENV["DD_CLIENT_API_KEY"]
# Configure API key authorization: appKeyAuth
config.api_key['appKeyAuth'] = ENV["DD_CLIENT_APP_KEY"]
end
api_instance = DatadogAPIClient::V2::LogsMetricsApi.new
body = DatadogAPIClient::V2::LogsMetricCreateRequest.new({data: DatadogAPIClient::V2::LogsMetricCreateData.new({attributes: DatadogAPIClient::V2::LogsMetricCreateAttributes.new({compute: DatadogAPIClient::V2::LogsMetricCompute.new({aggregation_type: DatadogAPIClient::V2::LogsMetricComputeAggregationType::COUNT})}), id: 'logs.page.load.count', type: DatadogAPIClient::V2::LogsMetricType::LOGS_METRICS})}) # LogsMetricCreateRequest | The definition of the new log-based metric.
begin
# Create a log-based metric
result = api_instance.create_logs_metric(body)
p result
rescue DatadogAPIClient::V2::ApiError => e
puts "Error when calling LogsMetricsApi->create_logs_metric: #{e}"
end
First install the library and its dependencies and then save the example to example.rb
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
rb "example.rb"
DELETE 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}
Delete a specific log-based metric from your organization.
Name
Type
Description
metric_id [required]
string
The name of the log-based metric.
OK
Not Authorized
API error response.
{
"errors": [
"Bad Request"
]
}
Not Found
API error response.
{
"errors": [
"Bad Request"
]
}
Too many requests
API error response.
{
"errors": [
"Bad Request"
]
}
# Path parameters
export metric_id="CHANGE_ME"
# Curl command
curl -X DELETE "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v2/logs/config/metrics/${metric_id}" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_CLIENT_APP_KEY}"
package main
import (
"context"
"fmt"
"os"
datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog"
)
func main() {
ctx := context.WithValue(
context.Background(),
datadog.ContextAPIKeys,
map[string]datadog.APIKey{
"apiKeyAuth": {
Key: os.Getenv("DD_CLIENT_API_KEY"),
},
"appKeyAuth": {
Key: os.Getenv("DD_CLIENT_APP_KEY"),
},
},
)
if site, ok := os.LookupEnv("DD_SITE"); ok {
ctx = context.WithValue(
ctx,
datadog.ContextServerVariables,
map[string]string{"site": site},
)
}
metricId := "metricId_example" // string | The name of the log-based metric.
configuration := datadog.NewConfiguration()
api_client := datadog.NewAPIClient(configuration)
r, err := api_client.LogsMetricsApi.DeleteLogsMetric(ctx, metricId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.DeleteLogsMetric``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
}
First install the library and its dependencies and then save the example to main.go
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
go "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v2.client.ApiClient;
import com.datadog.api.v2.client.ApiException;
import com.datadog.api.v2.client.Configuration;
import com.datadog.api.v2.client.auth.*;
import com.datadog.api.v2.client.model.*;
import com.datadog.api.v2.client.api.LogsMetricsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure the Datadog site to send API calls to
HashMap<String, String> serverVariables = new HashMap<String, String>();
String site = System.getenv("DD_SITE");
if (site != null) {
serverVariables.put("site", site);
defaultClient.setServerVariables(serverVariables);
}
// Configure API key authorization:
HashMap<String, String> secrets = new HashMap<String, String>();
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
defaultClient.configureApiKeys(secrets);
LogsMetricsApi apiInstance = new LogsMetricsApi(defaultClient);
String metricId = "metricId_example"; // String | The name of the log-based metric.
try {
apiInstance.deleteLogsMetric(metricId)
.execute();
} catch (ApiException e) {
System.err.println("Exception when calling LogsMetricsApi#deleteLogsMetric");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
First install the library and its dependencies and then save the example to Example.java
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v2 import ApiClient, ApiException, Configuration
from datadog_api_client.v2.api import logs_metrics_api
from datadog_api_client.v2.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()
# Defining the site is optional and defaults to datadoghq.com
if "DD_SITE" in os.environ:
configuration.server_variables["site"] = os.environ["DD_SITE"]
# Configure API key authorization: apiKeyAuth
configuration.api_key['apiKeyAuth'] = os.getenv('DD_CLIENT_API_KEY')
# Configure API key authorization: appKeyAuth
configuration.api_key['appKeyAuth'] = os.getenv('DD_CLIENT_APP_KEY')
# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = logs_metrics_api.LogsMetricsApi(api_client)
metric_id = "metric_id_example" # str | The name of the log-based metric.
# example passing only required values which don't have defaults set
try:
# Delete a log-based metric
api_instance.delete_logs_metric(metric_id)
except ApiException as e:
print("Exception when calling LogsMetricsApi->delete_logs_metric: %s\n" % e)
First install the library and its dependencies and then save the example to example.py
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
python3 "example.py"
require 'time'
require 'datadog_api_client'
DatadogAPIClient::V2.configure do |config|
# Defining the site is optional and defaults to datadoghq.com
config.server_variables['site'] = ENV["DD_SITE"] if ENV.key? 'DD_SITE'
# setup authorization
# Configure API key authorization: apiKeyAuth
config.api_key['apiKeyAuth'] = ENV["DD_CLIENT_API_KEY"]
# Configure API key authorization: appKeyAuth
config.api_key['appKeyAuth'] = ENV["DD_CLIENT_APP_KEY"]
end
api_instance = DatadogAPIClient::V2::LogsMetricsApi.new
metric_id = 'metric_id_example' # String | The name of the log-based metric.
begin
# Delete a log-based metric
api_instance.delete_logs_metric(metric_id)
rescue DatadogAPIClient::V2::ApiError => e
puts "Error when calling LogsMetricsApi->delete_logs_metric: #{e}"
end
First install the library and its dependencies and then save the example to example.rb
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
rb "example.rb"
GET 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}
Get a specific log-based metric from your organization.
Name
Type
Description
metric_id [required]
string
The name of the log-based metric.
OK
The log-based metric object.
Field
Type
Description
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
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
{
"data": {
"attributes": {
"compute": {
"aggregation_type": "distribution",
"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.
{
"errors": [
"Bad Request"
]
}
Not Found
API error response.
{
"errors": [
"Bad Request"
]
}
Too many requests
API error response.
{
"errors": [
"Bad Request"
]
}
# Path parameters
export metric_id="CHANGE_ME"
# Curl command
curl -X GET "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v2/logs/config/metrics/${metric_id}" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_CLIENT_APP_KEY}"
package main
import (
"context"
"encoding/json"
"fmt"
"os"
datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog"
)
func main() {
ctx := context.WithValue(
context.Background(),
datadog.ContextAPIKeys,
map[string]datadog.APIKey{
"apiKeyAuth": {
Key: os.Getenv("DD_CLIENT_API_KEY"),
},
"appKeyAuth": {
Key: os.Getenv("DD_CLIENT_APP_KEY"),
},
},
)
if site, ok := os.LookupEnv("DD_SITE"); ok {
ctx = context.WithValue(
ctx,
datadog.ContextServerVariables,
map[string]string{"site": site},
)
}
metricId := "metricId_example" // string | The name of the log-based metric.
configuration := datadog.NewConfiguration()
api_client := datadog.NewAPIClient(configuration)
resp, r, err := api_client.LogsMetricsApi.GetLogsMetric(ctx, metricId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.GetLogsMetric``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `GetLogsMetric`: LogsMetricResponse
response_content, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from LogsMetricsApi.GetLogsMetric:\n%s\n", response_content)
}
First install the library and its dependencies and then save the example to main.go
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
go "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v2.client.ApiClient;
import com.datadog.api.v2.client.ApiException;
import com.datadog.api.v2.client.Configuration;
import com.datadog.api.v2.client.auth.*;
import com.datadog.api.v2.client.model.*;
import com.datadog.api.v2.client.api.LogsMetricsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure the Datadog site to send API calls to
HashMap<String, String> serverVariables = new HashMap<String, String>();
String site = System.getenv("DD_SITE");
if (site != null) {
serverVariables.put("site", site);
defaultClient.setServerVariables(serverVariables);
}
// Configure API key authorization:
HashMap<String, String> secrets = new HashMap<String, String>();
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
defaultClient.configureApiKeys(secrets);
LogsMetricsApi apiInstance = new LogsMetricsApi(defaultClient);
String metricId = "metricId_example"; // String | The name of the log-based metric.
try {
LogsMetricResponse result = apiInstance.getLogsMetric(metricId)
.execute();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling LogsMetricsApi#getLogsMetric");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
First install the library and its dependencies and then save the example to Example.java
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v2 import ApiClient, ApiException, Configuration
from datadog_api_client.v2.api import logs_metrics_api
from datadog_api_client.v2.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()
# Defining the site is optional and defaults to datadoghq.com
if "DD_SITE" in os.environ:
configuration.server_variables["site"] = os.environ["DD_SITE"]
# Configure API key authorization: apiKeyAuth
configuration.api_key['apiKeyAuth'] = os.getenv('DD_CLIENT_API_KEY')
# Configure API key authorization: appKeyAuth
configuration.api_key['appKeyAuth'] = os.getenv('DD_CLIENT_APP_KEY')
# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = logs_metrics_api.LogsMetricsApi(api_client)
metric_id = "metric_id_example" # str | The name of the log-based metric.
# example passing only required values which don't have defaults set
try:
# Get a log-based metric
api_response = api_instance.get_logs_metric(metric_id)
pprint(api_response)
except ApiException as e:
print("Exception when calling LogsMetricsApi->get_logs_metric: %s\n" % e)
First install the library and its dependencies and then save the example to example.py
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
python3 "example.py"
require 'time'
require 'datadog_api_client'
DatadogAPIClient::V2.configure do |config|
# Defining the site is optional and defaults to datadoghq.com
config.server_variables['site'] = ENV["DD_SITE"] if ENV.key? 'DD_SITE'
# setup authorization
# Configure API key authorization: apiKeyAuth
config.api_key['apiKeyAuth'] = ENV["DD_CLIENT_API_KEY"]
# Configure API key authorization: appKeyAuth
config.api_key['appKeyAuth'] = ENV["DD_CLIENT_APP_KEY"]
end
api_instance = DatadogAPIClient::V2::LogsMetricsApi.new
metric_id = 'metric_id_example' # String | The name of the log-based metric.
begin
# Get a log-based metric
result = api_instance.get_logs_metric(metric_id)
p result
rescue DatadogAPIClient::V2::ApiError => e
puts "Error when calling LogsMetricsApi->get_logs_metric: #{e}"
end
First install the library and its dependencies and then save the example to example.rb
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
rb "example.rb"
GET https://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/metrics
Get the list of configured log-based metrics with their definitions.
OK
All the available log-based metric objects.
Field
Type
Description
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
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
{
"data": [
{
"attributes": {
"compute": {
"aggregation_type": "distribution",
"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.
{
"errors": [
"Bad Request"
]
}
Too many requests
API error response.
{
"errors": [
"Bad Request"
]
}
# Curl command
curl -X GET "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v2/logs/config/metrics" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_CLIENT_APP_KEY}"
package main
import (
"context"
"encoding/json"
"fmt"
"os"
datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog"
)
func main() {
ctx := context.WithValue(
context.Background(),
datadog.ContextAPIKeys,
map[string]datadog.APIKey{
"apiKeyAuth": {
Key: os.Getenv("DD_CLIENT_API_KEY"),
},
"appKeyAuth": {
Key: os.Getenv("DD_CLIENT_APP_KEY"),
},
},
)
if site, ok := os.LookupEnv("DD_SITE"); ok {
ctx = context.WithValue(
ctx,
datadog.ContextServerVariables,
map[string]string{"site": site},
)
}
configuration := datadog.NewConfiguration()
api_client := datadog.NewAPIClient(configuration)
resp, r, err := api_client.LogsMetricsApi.ListLogsMetrics(ctx).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.ListLogsMetrics``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `ListLogsMetrics`: LogsMetricsResponse
response_content, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from LogsMetricsApi.ListLogsMetrics:\n%s\n", response_content)
}
First install the library and its dependencies and then save the example to main.go
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
go "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v2.client.ApiClient;
import com.datadog.api.v2.client.ApiException;
import com.datadog.api.v2.client.Configuration;
import com.datadog.api.v2.client.auth.*;
import com.datadog.api.v2.client.model.*;
import com.datadog.api.v2.client.api.LogsMetricsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure the Datadog site to send API calls to
HashMap<String, String> serverVariables = new HashMap<String, String>();
String site = System.getenv("DD_SITE");
if (site != null) {
serverVariables.put("site", site);
defaultClient.setServerVariables(serverVariables);
}
// Configure API key authorization:
HashMap<String, String> secrets = new HashMap<String, String>();
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
defaultClient.configureApiKeys(secrets);
LogsMetricsApi apiInstance = new LogsMetricsApi(defaultClient);
try {
LogsMetricsResponse result = apiInstance.listLogsMetrics()
.execute();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling LogsMetricsApi#listLogsMetrics");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
First install the library and its dependencies and then save the example to Example.java
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v2 import ApiClient, ApiException, Configuration
from datadog_api_client.v2.api import logs_metrics_api
from datadog_api_client.v2.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()
# Defining the site is optional and defaults to datadoghq.com
if "DD_SITE" in os.environ:
configuration.server_variables["site"] = os.environ["DD_SITE"]
# Configure API key authorization: apiKeyAuth
configuration.api_key['apiKeyAuth'] = os.getenv('DD_CLIENT_API_KEY')
# Configure API key authorization: appKeyAuth
configuration.api_key['appKeyAuth'] = os.getenv('DD_CLIENT_APP_KEY')
# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = logs_metrics_api.LogsMetricsApi(api_client)
# example, this endpoint has no required or optional parameters
try:
# Get all log-based metrics
api_response = api_instance.list_logs_metrics()
pprint(api_response)
except ApiException as e:
print("Exception when calling LogsMetricsApi->list_logs_metrics: %s\n" % e)
First install the library and its dependencies and then save the example to example.py
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
python3 "example.py"
require 'time'
require 'datadog_api_client'
DatadogAPIClient::V2.configure do |config|
# Defining the site is optional and defaults to datadoghq.com
config.server_variables['site'] = ENV["DD_SITE"] if ENV.key? 'DD_SITE'
# setup authorization
# Configure API key authorization: apiKeyAuth
config.api_key['apiKeyAuth'] = ENV["DD_CLIENT_API_KEY"]
# Configure API key authorization: appKeyAuth
config.api_key['appKeyAuth'] = ENV["DD_CLIENT_APP_KEY"]
end
api_instance = DatadogAPIClient::V2::LogsMetricsApi.new
begin
# Get all log-based metrics
result = api_instance.list_logs_metrics
p result
rescue DatadogAPIClient::V2::ApiError => e
puts "Error when calling LogsMetricsApi->list_logs_metrics: #{e}"
end
First install the library and its dependencies and then save the example to example.rb
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
rb "example.rb"
PATCH 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}
Update a specific log-based metric from your organization. Returns the log-based metric object from the request body when the request is successful.
Name
Type
Description
metric_id [required]
string
The name of the log-based metric.
New definition of the log-based metric.
Field
Type
Description
data [required]
object
The new log-based metric properties.
attributes [required]
object
The log-based metric properties that will be updated.
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 [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
{
"data": {
"attributes": {
"filter": {
"query": "service:web* AND @http.status_code:[200 TO 299]"
},
"group_by": [
{
"path": "@http.status_code",
"tag_name": "status_code"
}
]
},
"type": "logs_metrics"
}
}
OK
The log-based metric object.
Field
Type
Description
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
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
{
"data": {
"attributes": {
"compute": {
"aggregation_type": "distribution",
"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.
{
"errors": [
"Bad Request"
]
}
Not Authorized
API error response.
{
"errors": [
"Bad Request"
]
}
Not Found
API error response.
{
"errors": [
"Bad Request"
]
}
Too many requests
API error response.
{
"errors": [
"Bad Request"
]
}
# Path parameters
export metric_id="CHANGE_ME"
# Curl command
curl -X PATCH "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v2/logs/config/metrics/${metric_id}" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_CLIENT_APP_KEY}" \
-d @- << EOF
{
"data": {
"attributes": {
"group_by": [
{
"path": "@http.status_code"
}
]
},
"type": "logs_metrics"
}
}
EOF
package main
import (
"context"
"encoding/json"
"fmt"
"os"
datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog"
)
func main() {
ctx := context.WithValue(
context.Background(),
datadog.ContextAPIKeys,
map[string]datadog.APIKey{
"apiKeyAuth": {
Key: os.Getenv("DD_CLIENT_API_KEY"),
},
"appKeyAuth": {
Key: os.Getenv("DD_CLIENT_APP_KEY"),
},
},
)
if site, ok := os.LookupEnv("DD_SITE"); ok {
ctx = context.WithValue(
ctx,
datadog.ContextServerVariables,
map[string]string{"site": site},
)
}
metricId := "metricId_example" // string | The name of the log-based metric.
body := *datadog.NewLogsMetricUpdateRequest(*datadog.NewLogsMetricUpdateData(*datadog.NewLogsMetricUpdateAttributes(), datadog.LogsMetricType("logs_metrics"))) // LogsMetricUpdateRequest | New definition of the log-based metric.
configuration := datadog.NewConfiguration()
api_client := datadog.NewAPIClient(configuration)
resp, r, err := api_client.LogsMetricsApi.UpdateLogsMetric(ctx, metricId).Body(body).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.UpdateLogsMetric``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `UpdateLogsMetric`: LogsMetricResponse
response_content, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from LogsMetricsApi.UpdateLogsMetric:\n%s\n", response_content)
}
First install the library and its dependencies and then save the example to main.go
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
go "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v2.client.ApiClient;
import com.datadog.api.v2.client.ApiException;
import com.datadog.api.v2.client.Configuration;
import com.datadog.api.v2.client.auth.*;
import com.datadog.api.v2.client.model.*;
import com.datadog.api.v2.client.api.LogsMetricsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure the Datadog site to send API calls to
HashMap<String, String> serverVariables = new HashMap<String, String>();
String site = System.getenv("DD_SITE");
if (site != null) {
serverVariables.put("site", site);
defaultClient.setServerVariables(serverVariables);
}
// Configure API key authorization:
HashMap<String, String> secrets = new HashMap<String, String>();
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
defaultClient.configureApiKeys(secrets);
LogsMetricsApi apiInstance = new LogsMetricsApi(defaultClient);
String metricId = "metricId_example"; // String | The name of the log-based metric.
LogsMetricUpdateRequest body = new LogsMetricUpdateRequest(); // LogsMetricUpdateRequest | New definition of the log-based metric.
try {
LogsMetricResponse result = apiInstance.updateLogsMetric(metricId)
.body(body)
.execute();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling LogsMetricsApi#updateLogsMetric");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
First install the library and its dependencies and then save the example to Example.java
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v2 import ApiClient, ApiException, Configuration
from datadog_api_client.v2.api import logs_metrics_api
from datadog_api_client.v2.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()
# Defining the site is optional and defaults to datadoghq.com
if "DD_SITE" in os.environ:
configuration.server_variables["site"] = os.environ["DD_SITE"]
# Configure API key authorization: apiKeyAuth
configuration.api_key['apiKeyAuth'] = os.getenv('DD_CLIENT_API_KEY')
# Configure API key authorization: appKeyAuth
configuration.api_key['appKeyAuth'] = os.getenv('DD_CLIENT_APP_KEY')
# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = logs_metrics_api.LogsMetricsApi(api_client)
metric_id = "metric_id_example" # str | The name of the log-based metric.
body = LogsMetricUpdateRequest(
data=LogsMetricUpdateData(
attributes=LogsMetricUpdateAttributes(
filter=LogsMetricFilter(
query="service:web* AND @http.status_code:[200 TO 299]",
),
group_by=[
LogsMetricGroupBy(
path="@http.status_code",
tag_name="status_code",
),
],
),
type=LogsMetricType("logs_metrics"),
),
) # LogsMetricUpdateRequest | New definition of the log-based metric.
# example passing only required values which don't have defaults set
try:
# Update a log-based metric
api_response = api_instance.update_logs_metric(metric_id, body)
pprint(api_response)
except ApiException as e:
print("Exception when calling LogsMetricsApi->update_logs_metric: %s\n" % e)
First install the library and its dependencies and then save the example to example.py
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
python3 "example.py"
require 'time'
require 'datadog_api_client'
DatadogAPIClient::V2.configure do |config|
# Defining the site is optional and defaults to datadoghq.com
config.server_variables['site'] = ENV["DD_SITE"] if ENV.key? 'DD_SITE'
# setup authorization
# Configure API key authorization: apiKeyAuth
config.api_key['apiKeyAuth'] = ENV["DD_CLIENT_API_KEY"]
# Configure API key authorization: appKeyAuth
config.api_key['appKeyAuth'] = ENV["DD_CLIENT_APP_KEY"]
end
api_instance = DatadogAPIClient::V2::LogsMetricsApi.new
metric_id = 'metric_id_example' # String | The name of the log-based metric.
body = DatadogAPIClient::V2::LogsMetricUpdateRequest.new({data: DatadogAPIClient::V2::LogsMetricUpdateData.new({attributes: DatadogAPIClient::V2::LogsMetricUpdateAttributes.new, type: DatadogAPIClient::V2::LogsMetricType::LOGS_METRICS})}) # LogsMetricUpdateRequest | New definition of the log-based metric.
begin
# Update a log-based metric
result = api_instance.update_logs_metric(metric_id, body)
p result
rescue DatadogAPIClient::V2::ApiError => e
puts "Error when calling LogsMetricsApi->update_logs_metric: #{e}"
end
First install the library and its dependencies and then save the example to example.rb
and run following commands:
export DD_SITE="https://api.datadoghq.euhttps://api.ddog-gov.comhttps://api.datadoghq.comhttps://api.us3.datadoghq.com"
rb "example.rb"