How to setup cloudwatch agent on EC2 instance running with ubuntu

0

Currently, we are in the process of implementing a CloudWatch agent in our EC2 instance which is having ubuntu 22.04. We have been referring to the documentation provided by AWS, which outlines two approaches – an old method using a Python script (now deprecated due to compatibility constraints with Python versions 2.6 to 3.5) and a new approach involving 'yum install.'

https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/QuickStartEC2Instance.html

Unfortunately, our instance runs Python version 3.10, rendering the old approach unusable for us. As we attempted to proceed with the new method, we encountered challenges with the absence of 'yum' in our instance. Our attempts to install 'yum' have been unsuccessful.

Could you please outline the correct approach to install the cloud watch agent on ubuntu machine?

Thank you in advance.

1 Answer
1
Accepted Answer

Hello.

The document you shared is how to install the CloudWatch Logs Agent, not the CloudWatch Agent.
CloudWatch Logs Agent is an older agent and is now deprecated.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/QuickStartEC2Instance.html

The older logs agent is deprecated. CloudWatch includes a unified agent that can collect both logs and metrics from EC2 instances and on-premises servers. For more information, see Getting started with CloudWatch Logs.

For information about migrating from the older CloudWatch Logs agent to the unified agent, see Create the CloudWatch agent configuration file with the wizard.

The older logs agent supports only versions 2.6 to 3.5 of Python. Additionally, the older CloudWatch Logs agent doesn't support Instance Metadata Service Version 2 (IMDSv2). If your server uses IMDSv2, you must use the newer unified agent instead of the older CloudWatch Logs agent.

The rest of this section explains the use of the older CloudWatch Logs agent for customers who are still using it.

Therefore, please install it by following the steps in the document below.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-commandline-fleet.html

# If the CPU architecture is x86-64
wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb

# If the CPU architecture is ARM64
wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/arm64/latest/amazon-cloudwatch-agent.deb

sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

Please refer to the following document when creating the configuration file.
For example, for memory usage, the configuration file should look like the one below.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html

{
    "agent": {
        "metrics_collection_interval": 60,
        "run_as_user": "root"
    },
    "metrics": {
        "append_dimensions": {
            "InstanceId": "${aws:InstanceId}"
        },
        "metrics_collected": {
            "collectd": {
                "metrics_aggregation_interval": 60
            },
            "mem": {
                "measurement": [
                    "mem_used_percent"
                ],
                "metrics_collection_interval": 60
            }
        }
    }
}

Once the configuration file is created, run the following command to start it.

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:configuration-file-path

You can also configure the settings interactively.

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

There seems to be a problem where collectd cannot be found, in which case please install it using the command below.
https://bugs.launchpad.net/ubuntu/+source/collectd/+bug/1971093

wget https://launchpad.net/ubuntu/+archive/primary/+files/collectd-core_5.12.0-11_amd64.deb
sudo apt install ./collectd-core_5.12.0-11_amd64.deb
profile picture
EXPERT
answered 4 months ago
profile pictureAWS
EXPERT
reviewed 4 months ago
  • Thank you so much for immediate response. I can able to setup the agent.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions