I’m trying to deploy a playbook to auto create alarm in cloudwatch using Ansible and SSM (through AWS-RunAnsiblePlaybook association)
I keep getting insufficient data in cloudwatch even though i’m seeing the metrics on the dashboards.
Here’s the part of my playbook that create the alarm, i’m running it on ec2 ubuntu 22.04 AMI. I’m gathering the variables with different shell command inside my playbook
- name: Create CloudWatch Alarm for memory usage
amazon.aws.cloudwatch_metric_alarm:
state: present
region: "{{ aws_region_id }}"
name: "High Memory utilization"
metric_name: "mem_used_percent"
namespace: "CWAgent"
statistic: Average
comparison: "GreaterThanOrEqualToThreshold"
threshold: 20 #90
period: 10 #300
evaluation_periods: 3
unit: "Percent"
description: "Trigger alarm when "
dimensions:
InstanceId: "{{ aws_instance_id }}"
alarm_actions:
- "arn:aws:sns:{{ aws_region_id }}:{{ aws_account_number }}:{{ aws_sns_topic }}"
here’s the cloudwatch agent configuration on my instance :
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"metrics_collected": {
"disk": {
"measurement": [
"used_percent"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
}
}
}
}
If you have any idea, where’s the problem is coming from.
Thanks 🙂
I tried to change CWAgent configuration and different key: value in the yaml playbook but didn’t work.
Clement.B42 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.