
Installing and Configuring AWS CloudWatch agent on Ubuntu 18.04 LTS
Using CloudWatch for EC2 instances get you a lot of insight before trying
to use third party monitoring solutions. Since it is an integrated service,
setting up and make it available is a breeze. Lets see how to do that step
by step.

Prerequisites:
- IAM Role attached to the instance with required permissions
- "collectd" - A system information collection tool that collects and organize metrics of your instance
To make aws cloudwatch agent to push data from the instance, you need to
attach an IAM role. AWS provides a role by default called
But, if, you have an IAM role attached to the instance already, make sure you attach the following policy to the role.CloudWatchAgentServerRole
CloudWatchAgentServerPolicy
First thing first, update your ubuntu apt repository,
sudo apt-get update
I would always prefer to go into tmp directory to download materials,
so,
cd /tmp
Now, lets download the aws cloudwatch agent package
sudo wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
Installation is just a command away
sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
As part of installation, a service account called `cwagent` will be created
for the agent to use. We need to grant the read permission to this user to
read logs from various locations
sudo usermod -aG adm cwagent
At this time, the aws cloudwatch agent is just installed and it is
neither started nor configured.
We need to install "collectd" as specified in the prerequisites section.
Believe me, this is easy.
sudo apt-get install collectd collectd-utils
Once the installation is completed, you can enable / disable plugins in
"collectd" to collect metrics of your requirement.
sudo nano /etc/collectd/collectd.conf
Hostname "app_host"
If you have a real domain name configured, you can skip this and just leave
`FQDNLookup` so that the server will use the DNS system to get the proper
domain.
LoadPlugin apache
LoadPlugin cpu
LoadPlugin df
LoadPlugin entropy
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin processes
LoadPlugin rrdtool
LoadPlugin users
We have completed all the steps for the agent to collect metrics. Now we
need to configure the agent to complete the whole process. Surprisingly,
this is made super easy by just calling the wizard.
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
Once the wizard is completed, a config file is created automatically for
you and stored in,
/opt/aws/amazon-cloudwatch-agent/bin/config.json by default and you have to copy it to,
/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
I would do it simply by
sudo cp /opt/aws/amazon-cloudwatch-agent/bin/config.json /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
Now, lets start the cloudwatch agent by specifying its config file
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s
Let us also make sure the agent is enabled to start during boot,
sudo systemctl enable amazon-cloudwatch-agent.service
Check the status of the service, it should say active running
sudo service amazon-cloudwatch-agent status
Comments
Post a Comment