Monitoring Amazon EC2 with CloudWatch

Rashmi Bhardwaj | Blog,Cloud & Virtualization
Advertisements

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.

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.

Advertisements

Related – Launching AWS EC2 Instance

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
  • Setup an Alarm on CloudWatch
  • On the next screen, click Select Metric, Select EC2.
  • On the Next screen, Click Per-Instance Metric
  • Select the metric to be monitored by the Alarm, Click Select Metric
  • 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.
  • 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.
  • Add a description to your Alarm, Click Next, Review the Alarm and Click Create Alarm
  • Once the Alarm is created you will see it as Pending Confirmation.
  • On your e-mail box you will get a subscription confirmation mail as below, Click subscribe to subscribe for the Alarm.

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.

 

ABOUT THE AUTHOR


Leave a Comment

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

Shopping Cart