AWS cloudwatch agent setup

From Notes_Wiki
Revision as of 04:31, 18 April 2022 by Saurabh (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Home > Amazon web services > AWS cloudwatch agent setup

The following steps do not lead to working metric being captured in cloudwatch. One can use CentOS 8.x Zabbix instead of Cloudwatch to monitor memory, disk, etc. for various VMs / physical hosts

Create Role for cloudwatch agent

  1. Login into AWS management console
  2. Go to IAM
  3. Go to Roles -> Create Role
  4. Select type of trusted entity should be "AWS service"
  5. Under "Choose a use case" select "EC2" from Common use cases
  6. In permissions page search for and select "CloudWatchAgentServerPolicy"
  7. Click next.
  8. No need of any tags. Click next
  9. Give Role name such as "CloudWatchAgentServerRole" and similar description.
  10. Click create role

Refer:


Assign role to EC2 VM

  1. Log into AWS management console
  2. Go to EC2
  3. Right click on VM and go to Security -> "Modify IAM Role"
  4. Select the role created with CloudWatchAgentServicePolicy included
  5. Click Save.


Using CloudWatch agent on CentOS

Install Cloudwatch agent on CentOS VM

  1. Assuming required CloudWatch Agent role is already created and assigned to the VM
  2. Get root access using:
    sudo su -
  3. Based on OS and region get download link from: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-commandline-fleet.html
  4. Install wget and vim using:
    dnf -y install wget vim
  5. wget the link of agent rpm file
    wget https://s3.amazonaws.com/amazoncloudwatch-agent/centos/amd64/latest/amazon-cloudwatch-agent.rpm
  6. Install agent
    dnf -y localinstall ./amazon-cloudwatch-agent.rpm


Refer:



Create CloudWatch agent configuration file on CentOS

  1. Run the agent configuration file wizard using:
    sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
    For OS select
    (1) Linux
    Between EC2 and on-premise choose
    (1) EC2
    Which user are you planning to run the agent. Choose
    (1) root
    Do you want to turn on StatsD daemon
    Choose : (1) yes
    Which port do you want StatsD daemon to listen to
    Default 8125
    What is the collect interval for StatsD deamon
    1 (10s)
    What is the aggregate interval for StatsD daemon
    4 (60s)
    Do you want to monitor metrics from CollectD?
    (2 no)
    Do you want to monitor any host metrics? e.g. CPU, memory, etc.
    1 yes
    Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply.
    2 no
    Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if the info is available?
    1 yes
    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.
    4. 60 sec
    Which default metrics config do you want
    1. Basic
    See the reference link for difference between Basic, Standard and Advanced
    Are you satisfied with the above config? Note
    it can be manually customized after the wizard completes to add additional items. : 1 yes
    Do you have any existing CloudWatch Log Agent (http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html) configuration file to import for migration?
    2 no
    Do you want to monitor any log files?
    2 no
    Do you want to store the config in the SSM parameter store?
    2 no
  2. Edit the configuration file '/opt/aws/amazon-cloudwatch-agent/bin/config.json as root user and Optionally remove:
    "AutoScalingGroupName": "${aws:AutoScalingGroupName}"
    under append_dimensions


Refer:



Run Cloudwatch agent on CentOS EC2 Linux VM

  1. To run the cloudwatch agent use:
    sudo /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
  2. This creates service called "amazon-cloudwatch-agent". Later status can be checked using:
    systemctl status amazon-cloudwatch-agent
  3. If you modify config file then you must run
    sudo /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
    For changes to take effect. Restarting agent with systemctl will not help in config file changes taking effect.
  4. Logs are avaialble at: /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log. To get more detailed logs edit config and under agent add
    "debug": true
    After this again fetch-config as specified above

Refer:



Looking at metrics in cloudwatch

Go to cloudwatch and try to look at metrics for:

  • disk_used_percent
  • mem_used_percent

for EC2 instance with matching instance ID.

Unfortunately metric are not visible.


Troubleshooting metric not visible at cloudwatch



Home > Amazon web services > AWS cloudwatch agent setup