Objective:
Add custom dimensions to the metrics collected by the Amazon CloudWatch agent.
Using append_dimensions:
The append_dimensions field in the Amazon CloudWatch agent configuration file allows adding custom dimensions to the metrics collected.
Dimensions help categorize and filter metrics in CloudWatch for more granular insights.
Steps to Implement:
Step 1: Edit the Amazon CloudWatch agent configuration file (commonly located at /opt/aws/amazon-cloudwatch-agent/bin/config.json).
Step 2: Add the append_dimensions field under the desired metrics section, specifying the custom dimensions in key-value pairs:
{
"metrics": {
"append_dimensions": {
"InstanceId": "${aws:InstanceId}",
"CustomDimensionKey": "CustomDimensionValue"
}
}
}
Step 3: Restart the CloudWatch agent:
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
-a stop
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
-a start
AWS References:
Amazon CloudWatch Agent Configuration:CloudWatch Agent Configuration
Why Other Options Are Incorrect:
Option A: Writing a custom script is unnecessary as the CloudWatch agent natively supports appending dimensions.
Option B: EventBridge rules do not interact with CloudWatch metrics for adding dimensions.
Option C: AWS Lambda functions are not required for this use case.