CloudWatch Agent
Hello Everyone
Welcome to CloudAffaire and this is Debjeet
In the last blog post, we have discussed CloudWatch Dashboard and created our 1st Dashboard.
https://cloudaffaire.com/cloudwatch-dashboard/
In this blog post, we are going to discuss CloudWatch Agent. We are also going to configure CloudWatch Agent in an EC2 instance hosting Amazon Linux 2.
CloudWatch Agent:
AWS provides CloudWatch Agent that can be used to collect and publish metrics and logs from both EC2 instances hosted in AWS and on-premises servers.
The unified CloudWatch agent enables you to do the following:
- Collect more system-level metrics from Amazon EC2 instances, including in-guest metrics, in addition to the metrics for EC2 instances. The additional metrics are listed in Metrics Collected by the CloudWatch Agent.
- Collect system-level metrics from on-premises servers. These can include servers in a hybrid environment as well as servers not managed by AWS.
- Collect logs from Amazon EC2 instances and on-premises servers, running either Linux or Windows Server.
- Retrieve custom metrics from your applications or services using the StatsD and collected protocols. StatsD is supported on both Linux servers and servers running Windows Server. collected is supported only on Linux servers.
You can store and view the metrics you collect with the CloudWatch agent in CloudWatch just as you can with any other CloudWatch metrics. The default namespace for metrics collected by the CloudWatch agent is CWAgent, although you can specify a different namespace when you configure the agent. The logs collected by the unified CloudWatch agent are processed and stored in CloudWatch Logs, just like logs collected by the older CloudWatch Logs agent. Metrics collected by the CloudWatch agent are billed as custom metrics.
The CloudWatch agent is supported on the following operating systems:
- Amazon Linux version 2014.03.02 or later
- Amazon Linux 2
- Ubuntu Server version 16.04 and 14.04
- CentOS version 7.0 and 6.5
- Red Hat Enterprise Linux (RHEL) version 7.5, 7.4, 7.0, and 6.5
- Debian 8.0
- SUSE Linux Enterprise Server (SLES) 12 or later
- 64-bit versions of Windows Server 2016, Windows Server 2012, and Windows Server 2008.
Prerequisite for CloudWatch Agent:
- Running EC2 instance with the supported OS for CloudWatch Agent.
- Instance configured with AWS CLI and IAM role for CloudWatch Agent.
We have already created the EC2 instance with the proper role and AWS CLI configuration.
Next, we are going to install and configure CloudWatch Agent.
Step 1: Connect to your EC2 instance and download the CloudWatch Agent package.
1 |
wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm |
Step 2: Install the CloudWatch Agent
1 |
sudo rpm -U ./amazon-cloudwatch-agent.rpm |
Files created in default installation directory
1 |
sudo ls -l /opt/aws/amazon-cloudwatch-agent/ |
Step 3: Configure CloudWatch Agent using the configuration wizard
1 |
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard |
Note: Provide answers as per your requirement. Once the configuration wizard completes one .josn fil will be created containing CloudWatch Agent configuration details. You can also create the configuration file manually.
To view the configuration file
1 |
sudo head /opt/aws/amazon-cloudwatch-agent/bin/config.json |
Step 4: Start the CloudWatch Agent with the configuration file
1 2 |
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config \ -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s |
Note: If you get an error related to types.db, create an empty file
sudo mkdir /usr/share/collectd
sudo touch /usr/share/collectd/types.db
Step 5: Check the status of the CloudWatch Agent.
1 |
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status |
Once the Agent is started, it will publish CloudWatch Metrics as per configuration details in the configuration file. You can check the metrics in CloudWatch console under CWAgent Namespace.
Hope you have enjoyed this article. In the next blog post, we are going to discuss CloudWatch Alarm.
To get more details on CloudWatch, please refer below AWS documentation
https://docs.aws.amazon.com/cloudwatch/index.html