简体   繁体   English

将 DynamoDb 指标日志导出到 S3 或 CloudWatch

[英]Export DynamoDb metrics logs to S3 or CloudWatch

I'm trying to use DynamoDB metrics logs in an external observability tool.我正在尝试在外部可观察性工具中使用 DynamoDB 指标日志。

To do that, I'll need to get these log data from S3 or CloudWatch log groups (not from Insights or CloudTrail).为此,我需要从 S3 或 CloudWatch 日志组(而不是从 Insights 或 CloudTrail)中获取这些日志数据。

For this reason, if there isn't a way to use CloudWatch, I'll need to export these metric logs from DynamoDb to S3, and from there export to CloudWatch or try to get those data directly from S3.因此,如果无法使用 CloudWatch,我需要将这些指标日志从 DynamoDb 导出到 S3,然后从那里导出到 CloudWatch,或者尝试直接从 S3 获取这些数据。

Do you know this is possible?你知道这是可能的吗?

AWS puts DynamoDB metrics (table operation, table, and account) over CloudWatch metrics. AWS 将 DynamoDB 指标(表操作、表和账户)置于 CloudWatch 指标之上。 Also, you can create as many metrics as you need.此外,您可以根据需要创建任意数量的指标。 If you use Python, you can read it with boto3.如果你使用 Python,你可以用 boto3 读取。 The CloudWatch client has this method: get_metric_data CloudWatch 客户端有这个方法: get_metric_data

Try this with your metrics:用你的指标试试这个:

cloudwatch_client = boto3.client('cloudwatch')
yesterday = date.today() - timedelta(days=1)
today = date.today()
response = cloudwatch_client.get_metric_data(
    MetricDataQueries=[
        {
            'Id': 'some_request',
            'MetricStat': {
                'Metric': {
                    'Namespace': 'DynamoDB',
                    'MetricName': 'metric_name',
                    'Dimensions': []
                },
                'Period': 3600,
                'Stat': 'Sum',
            }
        },
    ],
    StartTime=datetime(yesterday.year, yesterday.month, yesterday.day),
    EndTime=datetime(today.year, today.month, today.day),
)
print(response)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM