I've created an ECS cluster like so:
this.cluster = new ecs.Cluster(this, 'Cluster', {
containerInsights: true,
vpc: ec2.Vpc.fromLookup(this, props.stage + 'Vpc', {isDefault: false})
});
I want to create a CW alarm based off my cluser like so:
const CPUHigh = new cw.Alarm(this, "CPUHigh", {
metric: this.cluster.metric("CPUUtilized"),
threshold: 50,
evaluationPeriods: 3,
period: cdk.Duration.seconds(60),
comparisonOperator: cw.ComparisonOperator.GREATER_THAN_THRESHOLD
})
But even though the metric matches the one created by Container Insights, it seems like it can't be referenced this way.
Does anyone know the way its supposed to be referenced?
CDK only has support for certain metrics baseline and container insight is not covered, but it's not a problem you can create your own metric object pretty easy. For container insights it looks like this:
Important here is the namespace, dimensionsMap, and the metricName.
You can get the information about the namespace and the dimensions from the metrics console and the last tab "source".