How can I use CloudWatch Agent to monitor my Lightsail instance's disk and memory metrics?
Last updated: 2021-09-30
I have an Amazon Lightsail instance. How can I use Amazon CloudWatch Agent to monitor my instance's disk and memory metrics?
You can use CloudWatch to monitor your Lightsail instance's disk utilization and memory metrics. After setup and configuration, these metrics are available in the CloudWatch console, not in the Lightsail dashboard.
Note: It's a best practice to create a snapshot of your instance as a backup before making changes to your instance.
This resolution uses the AWS Command Line Interface. Amazon Linux 2 comes with the AWS CLI installed. For other distributions, you must install and configure the AWS CLI. If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI.
Set up CloudWatch Agent to monitor usage on your instance
1. Follow steps 1-4 in Monitoring memory usage in Lightsail instances.
2. Generate the CloudWatch configuration file. The CloudWatch configuration file is a JSON file that specifies the metrics and logs that the agent will collect, including custom metrics. There are two methods for doing this:
Method A: Generate the CloudWatch configuration file manually.
Method B: Generate the CloudWatch configuration file using the wizard.
Method A: Generate the CloudWatch configuration file manually
For instructions, see step 5. Create CloudWatch configuration file to collect memory usage metrics in Monitoring memory usage in Lightsail instances. The example shown is specific to capturing memory usage metrics.
For more information, see Manually create or edit the CloudWatch agent configuration file.
Method B: Generate the CloudWatch configuration file using the wizard
Run the following command:
$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
The wizard asks a series of questions. Select your answers based on your specific requirements. To set up instance monitoring, you can select the default answer for all of the questions with the exception of the following:
Are you using EC2 or On-Premises hosts? 1. EC2 2. On-Premises default choice: : 2 Do you want to turn on StatsD daemon? 1. yes 2. no default choice: : 2 Do you want to monitor metrics from CollectD? 1. yes 2. no default choice: : 2 Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply. 1. yes 2. no default choice: : 2 Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if the info is available? 1. yes 2. no 2 default choice: : 2 Do you want to monitor any log files? 1. yes 2. no 2 default choice: : 2 Do you want to store the config in the SSM parameter store? 1. yes 2. no default choice: : 2
3. Follow steps 6-8 in Monitoring memory usage in Lightsail instances.
Note: If you can't see the metrics on the Amazon CloudWatch console, then check the log file at /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log for authentication or credential errors. For more information about the log files and troubleshooting steps, see The CloudWatch Agent won't start.
Viewing metrics in CloudWatch
After completing the preceding steps, wait a few minutes. Then, open the CloudWatch dashboard in the CloudWatch console, switch to the correct Region, and view the Metrics section. View the section labeled CWAgent under Custom Namespaces. The disk_used_percent for root volume xvda1 in the device, fstype, host, and path section appear. Under the host section you can see the memory (RAM) utilization percent for your Lightsail instance.