Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.

Commit 971985c

Browse files
committed
Fix CloudWatch Agent dimensions and alarms
1 parent faf04c3 commit 971985c

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

project/TASKS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
- [x] Give the instance profile permission to access the filesystem, if needed
3232
- [x] Update the EC2 instance terraform to mount the EFS filesystem
3333
- [x] Update env.example to include the correct mount path for EFS for LETS_ENCRYPT_CERTS_DIR
34-
- [ ] The CloudWatch Agent configuration in user-data.sh is wrong.
35-
- [ ] The mem_used_percent metric is appearing with a host dimension, with a name like "ip-10-0-1-200". We want "instance id" as the sole dimension.
36-
- [ ] The disk_used_percent metric is appearing with device, fstype, host, and path dimensions. We want "instance id" and "path" as the two dimensions.
37-
- [ ] Update the CloudWatch alarms accordingly; they are pointing at nonexistent metrics right now.
34+
- [x] The CloudWatch Agent configuration in user-data.sh is wrong.
35+
- [x] The mem_used_percent metric is appearing with a host dimension, with a name like "ip-10-0-1-200". We want "instance id" as the sole dimension.
36+
- [x] The disk_used_percent metric is appearing with device, fstype, host, and path dimensions. We want "instance id" and "path" as the two dimensions.
37+
- [x] Update the CloudWatch alarms accordingly; they are pointing at nonexistent metrics right now.

terraform/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ resource "aws_instance" "api" {
250250
iam_instance_profile = aws_iam_instance_profile.ec2_profile.name
251251
user_data_base64 = local.user_data
252252

253+
credit_specification {
254+
cpu_credits = "standard"
255+
}
256+
253257
tags = {
254258
Name = var.instance_name
255259
}
@@ -343,7 +347,7 @@ resource "aws_cloudwatch_metric_alarm" "disk_usage" {
343347

344348
dimensions = {
345349
InstanceId = aws_instance.api.id
346-
device = "/dev/root"
350+
device = "nvme0n1p1"
347351
fstype = "ext4"
348352
path = "/"
349353
}

terraform/user-data.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ cat > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json << EOF
4848
"/"
4949
]
5050
}
51+
},
52+
"append_dimensions": {
53+
"InstanceId": "\$${aws:InstanceId}"
5154
}
5255
}
5356
}

0 commit comments

Comments
 (0)