Monitoring Amazon EC2 with CloudWatch

Rashmi Bhardwaj | Blog,Cloud & Virtualization
Google ADs

In this post we will learn how to setup an Amazon EC2 CloudWatch monitoring and will setup a CloudWatch Alarm which will trigger when the CPU on the EC2 instance spikes.

Steps to Monitor Amazon EC2 with CloudWatch

Step 1: Login and create an EC2 instance

Login and create an EC2 instance with the CloudWatch Monitoring enabled. By default we have the CloudWatch Monitor the EC2 instance every 300 seconds which is covered under the AWS Free Tier. In order to have your EC2 instance monitored by CloudWatch every 60 seconds you need to enable detailed CloudWatch monitoring. Detailed CloudWatch monitoring isn’t enabled by default but can be explicitly enabled on EC2 instance.

MONITORING AMAZON EC2 WITH CLOUDWATCH 1

Step 2: Status Checks

We have our EC2 instance setup with the free tier’s basic monitoring enabled. We also see the status checks passed. Status checks are done for the underlying system & instance reachability and can be seen as passed.

Google ADs

Related – Launching AWS EC2 Instance

MONITORING AMAZON EC2 WITH CLOUDWATCH 2
MONITORING AMAZON EC2 WITH CLOUDWATCH 3

Step 3: Setup a CloudWatch Alarm

In this step we will setup a CloudWatch Alarm which will trigger once the threshold defined by user is breached.

  • Browse to the AWS CloudWatch Service
MONITORING AMAZON EC2 WITH CLOUDWATCH 4
  • Setup an Alarm on CloudWatch
MONITORING AMAZON EC2 WITH CLOUDWATCH 5
  • On the next screen, click Select Metric, Select EC2.
MONITORING AMAZON EC2 WITH CLOUDWATCH 6
MONITORING AMAZON EC2 WITH CLOUDWATCH 7
  • On the Next screen, Click Per-Instance Metric
MONITORING AMAZON EC2 WITH CLOUDWATCH 8
  • Select the metric to be monitored by the Alarm, Click Select Metric
MONITORING AMAZON EC2 WITH CLOUDWATCH 9
  • On the Next screen, select metric name, period of monitoring, & threshold value. We configured a threshold value of 60 above which the Alarm will trigger.
MONITORING AMAZON EC2 WITH CLOUDWATCH 10
  • On the next screen Select Action, Create topic, then we define an e-mail address to receive notification when the Alarm is breached. Click Next.
MONITORING AMAZON EC2 WITH CLOUDWATCH 11
  • Add a description to your Alarm, Click Next, Review the Alarm and Click Create Alarm
MONITORING AMAZON EC2 WITH CLOUDWATCH 12
  • Once the Alarm is created you will see it as Pending Confirmation.
MONITORING AMAZON EC2 WITH CLOUDWATCH 13
  • On your e-mail box you will get a subscription confirmation mail as below, Click subscribe to subscribe for the Alarm.
MONITORING AMAZON EC2 WITH CLOUDWATCH 14
MONITORING AMAZON EC2 WITH CLOUDWATCH 15

Once the subscription is confirmed, let’s log into the EC2 instance and put a process under loop to raise the CPU and generate an Alert.

Console to the EC2 instance and elevate your privilege to Root using ‘sudo –i’.

Then run the script ‘while true; do echo; done’ to put your EC2 in loop and raise the CPU.

Wait for 5 minutes and you will be able to get an Alert on your mail ID.

MONITORING AMAZON EC2 WITH CLOUDWATCH 16

 

ABOUT THE AUTHOR


Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart