Hi team,
I am running an application in AWS Fargate that consumes and processes messages from SQS queues.
I want to auto-scale the fargate service based on the queue length
Thsi is my CDK code
const service = new FargateService(this, "mySvc", {
cluster,
minHealthyPercent: 0,
taskDefinition: theTaskDef,
securityGroups: [
new ec2.SecurityGroup(this, "SG", {
securityGroupName: "SG_name",
vpc: cluster.vpc,
}),
],
});
//auto-scale
const scalingTarget = service.autoScaleTaskCount({
minCapacity: 2,
maxCapacity: 40,
});
scalingTarget.scaleOnMetric("queueDepth", {
metric: mySQSQueue.metricApproximateNumberOfMessagesVisible({
statistic: "Sum",
period: Duration.minutes(1),
}),
adjustmentType: AdjustmentType.CHANGE_IN_CAPACITY,
scalingSteps: [
{ upper: 0, change: 0 },
{ lower: 100, change: +1 },
{ lower: 151, change: +1 },
{ lower: 201, change: +1 },
{ lower: 251, change: +1 },
.....
],
//datapointsToAlarm:1,?
//evaluationPeriods:1,?
metricAggregationType: MetricAggregationType.MAXIMUM,
cooldown: Duration.minutes(1),
});
when I deployed this infrastructure and started testing, there is no data point at all for ApproximateNumberOfMessagesVisible metric
all other metrics of the queue have values except this: ApproximateNumberOfMessagesVisible
- Approximate Age Of Oldest Message
- Approximate Number Of Messages Not Visible
- Number Of Empty Receives
- Number Of Messages Deleted
- Number Of Messages Received
- Number Of Messages Sent
Sent Message Size
==> All those metrics graphs have values/data points except this one ==> Approximate Number Of Messages Visible which I'm using to auto-scale the number of tasks on the Fargate service
I'm not sure why there are no values on the Approximate Number Of Messages Visible metric, did I miss something in my CDK code?
why this alarm is not breaching and is empty: ApproximateNumberOfMessagesVisible always 0 for min, max, avg, sum, last value..
The metrics you are using seem fine. What happens if I set the default (5 minutes) for the duration of the metrics, etc.?
yes they are stored in the target SQS queue, otherwise, I will not see other metrics
I set it to 5 minutes
**still nothing on the ** Approximate Number Of Messages Visible
0 data points
Try to browse for the metric via the Metrics console, and compare that with the metric definition in the alarm. Maybe the Unit or Dimension definition on the alarm is wrong? If they don't match exactly, then CloudWatch would view it as a completely different (non existent) metric
I agree with Shahad_C. Are the correct SQS queue metrics selected?