Interview Prep/AWS/CloudFormation, CloudWatch, KMS, Secrets and Cost

The CloudWatch agent is running, but no `mem_used_percent` or disk metrics appear in the `CWAgent` namespace.

IntermediateTroubleshootingCloudFormation, CloudWatch, KMS, Secrets and Cost
Answer

Likely causes → The agent was started with the default or no config, so the metrics section is missing. Other causes: the instance role has no CloudWatchAgentServerPolicy, or the agent cannot reach the CloudWatch endpoint (private subnet with no monitoring endpoint).

Diagnose →

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status
sudo tail -50 /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
aws cloudwatch list-metrics --namespace CWAgent --dimensions Name=InstanceId,Value=i-0abc

Fix →

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
  -a fetch-config -m ec2 -s -c ssm:AmazonCloudWatch-linux

Attach CloudWatchAgentServerPolicy, and add the monitoring and logs endpoints for private subnets.

Prevent → Store the agent config in SSM Parameter Store, and push it with State Manager to every instance.

aws All AWS questions Roadmap: Cloud cost & architecture

More on CloudFormation, CloudWatch, KMS, Secrets and Cost