How do I use the CloudWatch agent to monitor my Lightsail instance's disk and memory metrics?

3 minute read
1

I have an Amazon Lightsail instance, and I want to use the Amazon CloudWatch agent to monitor my instance's disk and memory metrics.

Resolution

This resolution uses the AWS Command Line Interface (AWS CLI). Amazon Linux 2 comes with the AWS CLI installed. For other distributions, you must install and configure the AWS CLI.

Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

Configure the CloudWatch agent

Note: Before you make changes in your instance, it's a best practice to create a snapshot of your instance as a backup.

To configure the CloudWatch agent to monitor you instance's usage, first complete steps 1-4 in Monitoring memory usage in Lightsail instances.

Then, create the CloudWatch configuration file that specifies the metrics and logs for the agent to collect, including custom metrics. You can either manually create the configuration file, or use the wizard.

Manually create the CloudWatch configuration file

To manually create the configuration file, see the Create CloudWatch configuration file to collect memory usage metrics section in Monitoring memory usage in Lightsail instances. The example specifies how to capture memory usage metrics. For more information, see Manually create or edit the CloudWatch agent configuration file.

Use the wizard to create the CloudWatch configuration file

To use the wizard to create the configuration file, run the following command:

$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

Select the answers to the wizard's questions based on your requirements. To set up instance monitoring, you can select the default choice for each answer. However for the following questions, choose the answer that's appropriate for your use case:

  • Are you using EC2 or On-Premises hosts?
  • Do you want to turn on StatsD daemon?
  • Do you want to monitor metrics from CollectD?
  • Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply.
  • Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if the info is available?
  • Do you want to monitor any log files?
  • Do you want to store the config in the SSM parameter store?

Finally, complete steps 6-8 in Monitoring memory usage in Lightsail instances.

Note: If you can't see the metrics on the 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, see The CloudWatch Agent won't start.

After you configure the CloudWatch agent, you can find the metrics in the CloudWatch console, but not in the Lightsail dashboard.

View metrics in CloudWatch

To view the CloudWatch metrics, complete the following steps:

  1. Open the CloudWatch dashboard in the CloudWatch console.
  2. Choose the AWS Region of your Lightsail instance, and then choose the Metrics section.
  3. Under Custom Namespaces, choose the CWAgent section. Under host, you can see the memory (RAM) utilization percent for your Lightsail instance.

Related information

Connect to your Lightsail Linux or Unix instances

Create IAM users to use with the CloudWatch agent on on-premises servers

Download and configure the CloudWatch agent using the command line

Create the CloudWatch agent configuration file

AWS OFFICIAL
AWS OFFICIALUpdated 9 months ago