Wednesday, September 22, 2021

Configure AWS CloudWatch Agent for memory metrics

 
Configure AWS CloudWatch Agent for memory metrics



In this tutorial we are going to configure AWS CloudWatch Agent service for EC2 memory logs.

Prerequisites:-

1) Ubuntu Operating System
2) I AM Role
3) cloudwatch-agent.deb Package


Step 1:
Launch an EC2 Instance with ubuntu OS.

Step 2:
Create an IAM role and attach with EC2 Instance
 


Create IAM role and attach permission CloudWatchAgentServerPolicy

  •  Attach IAM role with ec2 ( Action >> Security >> Modify IAM role )


Step 3:
Download the CloudWatch Agent Package

$ wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb

Step 4: Install the package:

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

Step 5) Update Packages & Install collectd

$ sudo apt-get update && apt-get install collectd

Step 6) Create the CloudWatch Agent Configuration File

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


On which OS are you planning to use the agent?
1. linux
2. windows
3. darwin
default choice: [1]:
1

Are you using EC2 or On-Premises hosts?
1. EC2
2. On-Premises
default choice: [2]:
1

Which user are you planning to run the agent?
1. root
2. cwagent
3. others
default choice: [1]:
1

Do you want to turn on StatsD daemon?
1. yes
2. no
default choice: [1]:
2

Do you want to monitor metrics from CollectD?
1. yes
2. no
default choice: [1]:
2

Do you want to monitor any host metrics? e.g. CPU, memory, etc.
1. yes
2. no
default choice: [1]:
1

Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply.
1. yes
2. no
default choice: [1]:
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
default choice: [1]:
2

Would you like to collect your metrics at high resolution (sub-minute resolution)? This enables sub-minute resolution for all metrics, but you can customize for specific metrics in the output json file.
1. 1s
2. 10s
3. 30s
4. 60s
default choice: [4]:
4

Which default metrics config do you want?
1. Basic
2. Standard
3. Advanced
4. None
default choice: [1]:
1

Are you satisfied with the above config? Note: it can be manually customized after the wizard completes to add additional items.
1. yes
2. no
default choice: [1]:
1

Do you have any existing CloudWatch Log Agent (http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html) configuration file to import for migration?
1. yes
2. no
default choice: [2]:
2

Do you want to monitor any log files?
1. yes
2. no
default choice: [1]:
2


The config file is also located at /opt/aws/amazon-cloudwatch-agent/bin/config.json (Edit it manually if needed.)


Do you want to store the config in the SSM parameter store?
1. yes
2. no
default choice: [1]:
2



Step 7)
Now check the status of Cloud-Watch Agent Service.

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


Step 8) By-default service Status is stopped now, so start it & check status after that.

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

Step 9) Check Custom Metrics in AWS CloudWatch.

CloudWatch >> Matrics >> CWAgent

Step 10) Check inside the host for viewing memory metrics:


No comments:

Post a Comment

testing