Install and Configure Amazon CloudWatch Agent On EC2 Instances
Install and Configure Amazon CloudWatch Agent On EC2 Instances
1. Prerequisites
2. Install the Amazon CloudWatch Agent on an EC2 instance
3. Configure the CloudWatch Agent
4. Verify Amazon CloudWatch Agent Configuration
Prerequisites
Before we get started with CloudWatch, you have to follow these steps in AWS:
Action: Install
Installation Type: Uninstall and Reinstall
Name: AmazonCloudWatchAgent
Version: Latest
Additional Arguments: No additional arguments needed
If you don't want to store the outputs of this command in an S3 document, you can just
uncheck Enable an S3 bucket under Output options.
Finally, click Run.
Once you click Run, you are redirected to a new page where you can monitor the
status of the running tasks.
Using this method for installing the CloudWatch agent is highly recommended for
instances on scale, where you can install the agent on all the instances at once. The
command document we used to install the CloudWatch agent is suitable for Linux,
Windows, and MacOS. So you don't have to worry about segregating the different
platforms while provisioning the agent.
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-
config-wizard
Windows:
agent-config-wizard.exe
Windows:
& 'C:\\Program Files\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-
ctl.ps1' -a fetch-config -m ec2 -s -c ssm:<Parameter\_Name\_in\_SSM>
If you're storing the configuration file locally, then you need to replace ssm with file in
the command and specify the file path, e.g., file:'C:\Program Files\Amazon\
AmazonCloudWatchAgent\config.json'
To do this with Run Command:
Navigate to Run Command the same way we did earlier.
In the Command document search bar, choose Document prefix name, then Equals,
and then specify the name of the document AmazonCloudWatch-ManageAgent.
image6
Action: configure
Mode: ec2
Optional Configuration Source: ssm
Optional Configuration Location: The name of the parameter that stores the
CloudWatch agent configuration
Optional Open Telemetry Collector Configuration Source: default
The rest of the sections are the same as in the command document we ran earlier.
image7
Logs: Navigate to the CloudWatch console and select Logs > Log groups.
Check whether the log groups you specified in the configuration file are there,
with streams inside them and logs pushed to these streams.
Metrics: Navigate to the CloudWatch console and select Metrics > All Metrics.
You should see it under Custom Namespaces. Open this namespace and see if
the metrics specified in the configuration file are being pushed.