我正在编写 CDK 来创建我漂亮的 Cloudwatch 仪表板。我弄清楚了如何使用 Lambda 函数创建具有 metrics 的小部件。但我找不到为 Dynamodb 表创建指标的方法。
Lambda 函数有自己的指标属性
lambdaFunction.metricErrors()
lambdaFunction.metricInvocations()
因此,我可以将 lambdaFunction 的指标添加到我的 Cloudwatch 仪表板中 const 仪表板 = new 仪表板(this, '仪表板', { 仪表板名称:'ImageMetadataServiceCloudWatch' })
const widget = new cloudwatch.GraphWidget({
title: title,
left: [
lambdaFunction.metricErrors(),
lambdaFunction.metricInvocations()
],
right: [
lambdaFunction.metricDuration()
]
});
dashboard.add(widget);
但我不知道如何获取 Dynamodb 表的指标。
private metricForDynamoDBTable(table: dynamodb.Table, metricName: string, options: cloudwatch.MetricOptions = { }): cloudwatch.Metric {
return new cloudwatch.Metric({
metricName,
namespace: 'AWS/DynamoDB',
dimensions: {
TableName: table.tableName
},
unit: cloudwatch.Unit.COUNT,
label: metricName,
...options
});
}
config_table_dashboard = aws_cloudwatch.Dashboard(self, "id", dashboard_name="provisionedthroughtput")
dynamodb_metrics = []
dynamodb_WCU_throughput = aws_cloudwatch.Metric(
metric_name="ConsumedWriteCapacityUnits",
namespace="AWS/DynamoDB",
dimensions={"TableName": "table-name"},
statistic="Average",
unit=aws_cloudwatch.Unit.COUNT,
period=core.Duration.minutes(amount=5))
dynamodb_metrics.append(dynamodb_WCU_throughput)
config_table_dashboard.add_widgets(aws_cloudwatch.GraphWidget(title="Dynamodb table provision", left=dynamodb_metrics))