Custom Cloud watch Metrics for AWS EC2 Instance

Custom Cloud watch Metrics for AWS EC2 Instance

December 28, 2020 / Nirav Shah

Custom CloudWatch Metrics for AWS EC2 Instance

As more and more organisations adopt AWS cloud for its obvious benefits, it becomes a known fact that AWS resources need to be monitored. For the same purpose, the most efficient AWS service is CloudWatch.

We can monitor our services like Amazon Web Services like EBS volumes, EC2 instances and RDS instances.

Today we understand about EC2 Monitoring via CloudWatch.

There are two types of monitoring

  1. Basic Monitoring
  2. Detailed Monitoring

In CloudWatch default monitoring, it does not enable memory utilization or disk I/O of the instances if we want we need to apply custom metrics for this.

Enable AWS Custom Cloudwatch Metrics For EC2 Instance Step by step

In this blog, we cover how to enable custom detail monitoring and collect memory and disk metrics using AWS CloudWatch agent.

Let’s get started and go step by step.

Step 1: First, we need to create an IAM role with CloudwatchagentServerPolicy

Custom Cloud watch Metrics for AWS EC2 Instance

Custom Cloud watch Metrics for AWS EC2 Instance

Custom Cloud watch Metrics for AWS EC2 Instance

Step 2: Now we need to launch an EC2 Instance with this role. And allow the port for HTTP-80

Custom Cloud watch Metrics for AWS EC2 Instance

Custom Cloud watch Metrics for AWS EC2 Instance

Step 3: Now ssh the EC2 instance and Install httpd package.

    #yum install httpd
    #systemctl start httpd
    #system enable httpd

Custom Cloud watch Metrics for AWS EC2 Instance

Step 4: Install CloudWatch Agent

CloudWatch agent provides an automated way to send system log data to CloudWatch logs from the EC2 instance

The agent includes the following components:

  1. A plug-in to AWS CLI that pushes log data to CloudWatch logs.
  2. A Script that initiates the process to push data to Cloudwatch Logs.
  3. A cron job that ensures that the daemon is always running.

After installing Agent there are two configurations file created at /etc/awslogs or /var/awslogs/etc directory

  • awsligs.conf → Which logs to be captured
  • awscli.conf → To which ASS region the logs to be sent
#cd /tmp 
#wget https://s3.amazonaws.com/amazoncloudwatch-agent/linux/amd64/latest/AmazonCloudWatchAgent.zip 
#unzip AmazonCloudWatchAgent.zip 
#./install.sh

Custom Cloud watch Metrics for AWS EC2 Instance

Step 5: Configure Metrics

In this step, we need to describe the metrics that we want to collect and send to CloudWatch, AWS CloudWatch agent will read that info from a JSON file

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

Custom Cloud watch Metrics for AWS EC2 Instance

Step 6: Start Cloudwatch agent

#mkdir -p /usr/share/collectd
#touch /usr/share/collectd/types.db
#/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
# /bin/systemctl restart amazon-cloudwatch-agent.service
#/bin/systemctl status amazon-cloudwatch-agent.service

Step 7: Now Create Cloudwatch Dashboard

We can see memory utilization from here

Custom Cloud watch Metrics for AWS EC2 Instance

Custom Cloud watch Metrics for AWS EC2 Instance

Hit access webpage and see the log

Custom Cloud watch Metrics for AWS EC2 Instance

We can see our log here

Custom Cloud watch Metrics for AWS EC2 Instance

Custom Cloud watch Metrics for AWS EC2 Instance

Conclusion

By this, we can create a custom log for the AWS EC2 instance and the same method can be used with other AWS services to gather data and attain valuable insights.

Thanks!! and stay tuned for more blogs.

Also ReadHow To Start And Stop AWS EC2 Instance Using Lambda

FAQs:

  1. What can I measure with Amazon CloudWatch Metrics?
  2. What statistics can I view and graph in CloudWatch?
  3. What log monitoring does Amazon CloudWatch provide?

 

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let’s Talk About Your Needed AWS Infrastructure Management Services

    Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project