CloudWatch Agent on Ubuntu: Difference between revisions

From Cramsession
Jump to navigationJump to search
✍️ Verified Author: MflavellClick to view professional profile & credentials
No edit summary
Line 28: Line 28:
  sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
  sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
Answer questions
Answer questions
* Make sure you select root as the user
* done save the configuration online


=Start the agent=
=Start the agent=

Revision as of 16:58, 17 July 2024

How to guide

install

wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
chmod 777 amazon-cloudwatch-agent.deb
sudo dpkg -i -E amazon-cloudwatch-agent.deb

Create IAM Role

  • Sign in to the IAM console
  • Select Roles, Create Role
  • Select AWS Service
  • Select EC2 common use case
  • Select Next
  • Find CloudWatchAgentServerPolicy
  • Click checkbox next to CloudWatchAgentServerPolicy
  • Click Next
  • Provide a Role Name
  • Click Create Role
  • Link IAM role to instance.
    • Select Insane > Actions > Security > Modify IAM Role
    • Add created IAM Role

Create an Access key

Create an access key for a server admin Save the key

Configure the agent

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

Answer questions

  • Make sure you select root as the user
  • done save the configuration online

Start the agent

Linx will save the configuration information here:

/opt/aws/amazon-cloudwatch-agent/etc

Run the command

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/etc/env-config.json

Example:

ubuntu@ip-10-0-0-4:/opt/aws/amazon-cloudwatch-agent/etc$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c  file:/opt/aws/amazon-cloudwatch-agent/etc/env-config.json 
****** processing amazon-cloudwatch-agent ******
I! Trying to detect region from ec2 D! [EC2] Found active network interface I! imds retry client will retry 1 timesSuccessfully fetched the config and saved in  /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_env-config.json.tmp
Start configuration validation...
2024/07/17 14:02:24 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_env-config.json.tmp ...
2024/07/17 14:02:24 I! Valid Json input schema.
2024/07/17 14:02:24 Configuration validation first phase succeeded
I! Detecting run_as_user...
I! Trying to detect region from ec2
D! [EC2] Found active network interface
I! imds retry client will retry 1 times
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -schematest -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml
Configuration validation second phase succeeded
Configuration validation succeeded

Check Status

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status