Reputation: 1
The following terraform resource creates AWS cloudwatch alarm, but remains in "insufficient data" state. I believe this is due to some of the dimension names I used (DevicePath, fstype) may not be correct. I know the names MountPath and InstanceID are correct but could not verify the other two (DevicePath, fstype). AWS call these dimensions as path, device, fstype and host respectively, however, could not find a reference what terraform calls these.
resource "aws_cloudwatch_metric_alarm" "Low_Disk_Space_For_root_drive" {
alarm_name = "Low_Disk_Space_For_root_drive"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "disk_used_percent"
namespace = "CWAgent"
dimensions {
MountPath = "/"
DevicePath = "/dev/xvda2"
fstype = "xfs"
InstanceId = "i-xxxxxxxxxxxxxxxxx"
}
period = "60"
statistics = "Maximum"
threshold = "90"
alarm_description = "Disk usage for / is high"
insufficient_data_actions = []
actions_enabled = true
alarm_actions = ["arn:aws:sns:xxxxxx"]
ok_actions = ["arn:aws:sns:xxxxxx"]
}
Upvotes: 0
Views: 2226
Reputation: 351
Main reason why is because what you put as device
Change "/dev/xvda2" to AWS the exact device like ("nvme1n1"). You can check that in CloudWatch Metrics.
Upvotes: 0
Reputation: 4055
In order to make this work you need to
MountPath
to path
DevicePath
and instead add device
ImageID
and InstanceType
Check out the updated dimensions
field below
(Note - substitute the values with your own values. You should be able to see them from the Cloudwatch Metrics CWAgent
section on the AWS console)
resource "aws_cloudwatch_metric_alarm" "Low_Disk_Space_For_root_drive" {
alarm_name = "Low_Disk_Space_For_root_drive"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "disk_used_percent"
namespace = "CWAgent"
dimensions {
InstanceId = "i-xxxxxxxxxxxxxxxxx"
ImageId = "your-image-id"
InstanceType = "your-instance-type"
path = "/"
device = "your-device"
fstype = "xfs"
}
period = "60"
statistics = "Maximum"
threshold = "90"
alarm_description = "Disk usage for / is high"
insufficient_data_actions = []
actions_enabled = true
alarm_actions = ["arn:aws:sns:xxxxxx"]
ok_actions = ["arn:aws:sns:xxxxxx"]
}
Upvotes: 1
Reputation: 11
Add TreatMissingData to resource body
resource "aws_cloudwatch_metric_alarm" "Low_Disk_Space_For_root_drive"{
alarm_name = "Low_Disk_Space_For_root_drive"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "disk_used_percent"
namespace = "CWAgent"
dimensions {
MountPath = "/"
DevicePath = "/dev/xvda2"
fstype = "xfs"
InstanceId = "i-xxxxxxxxxxxxxxxxx"
}
period = "60"
statistics = "Maximum"
threshold = "90"
alarm_description = "Disk usage for / is high"
insufficient_data_actions = []
**TreatMissingData = "notBreaching"**
actions_enabled = true
alarm_actions = ["arn:aws:sns:xxxxxx"]
ok_actions = ["arn:aws:sns:xxxxxx"]
}
Upvotes: 1