Amazon CloudWatch is like a watchdog that helps you monitor your resources in the Cloud. Amazon CloudWatch helps you to know the state of your resources in the cloud, CloudWatch gathers information (Metrics) about your services such as the state of the CPU, state of the memory and traffic, and display them in the dashboard.
CloudWatch notifies you when your EC2 server is overwhelmed.
CloudWatch detects issues and solve them immediately and ensures everything is fine with your Cloud resources.
In this article, you are going to learn how to create and set up CloudWatch to monitor your Cloud resources.
For you to use CloudWatch, you must have created an AWS resource. firstly, let create an EC2 instance.
1.Sign in to your AWS Console and type EC2 to the search bar and click EC2
2.Click Launch instance
3.Give the EC2 instance a name. In this article, we are going to name it BravoEC2
4.Scroll down a little to create Key pair
5.Give the Keypair a name and click create Keypair

6.Click Launch instance
7.You have successfully created an EC2 instance
8.Now, click connect to instance
9.Scroll down a little and click connect
10.You are now connected to your Amazon Linux image
11.Sudo su into the EC2 instance
12.Go to your AWS console, type CloudWatch and click CloudWatch from the options it shows
13.Click Metrics and select All metrics
14.Click EC2
15.Click per-instance metrics
16.Scroll down a little and click the small box in front of CPUUtiliztion
17.Go to the AWS search bar and SNS and select Simple Notification Service
18.Click Topic
19.Click create topic at the top right corner of your screen
20.Click Standard and give the topic a name
21.SCroll down and click Create topic
With what we have created, if anything happens to your EC2 instance, you will receive an alert but this is not complete without creating a subscription.
22.Create a subscription
Still on the alert page, click create Subscription
23.Click the dropdown arrow and select Email fill in your Email address into the endpoint and click Create Subscription. Note: you may choose other means of notification
Note: You need to confirm your subscription. Click confirm subscription, open the subscription message that was sent by AWS to your Email address, scroll down and click on confirm subscription
copy the url and paste it here.

Go to CloudWatch and create an alarm
24.Type CloudWatch to the search bar and select CloudWatch
25.Inside CloudWatch, click Alarms and Click All alarms
26.Click create alarm
27.Click select metrics
28.Click on EC2
29.Select per-instance metrics
30.Scroll down and click the small box in front of CPUUtilization
31.Click select metrics
Set the condition
32.If the CPUUtilization exceed 75% threshold for 5 minutes, it should send a message
33.Scroll down and click Next
34.Select an SNS ( Simple Notification Service )
35.Scroll down and click Next
36.Give the Alarm a name
37.Scroll down and click Next
38.Scroll down and click Create Alarm
You have successfully created an Alarm. A message is expected to be sent to the used Email address when the instance usage exceed 75% Threshold within 5 minutes.
39.Now, stress the instance in order to see the message that will be sent to the used Email address.
To stress the instance
Run this command to stress the instance
sudo yum install stress -y
When the installation of the stress is complete, run this command
stress --cpu 2 --timeout 300
This command increases the CPU usage by 2 which make the CPU utilization exceed the Threshold that is set in the CoudWatch alarm.
Check your box for the Email notification, a message showing high CPU usage should be sent.
40.This is the message showing high CPU usage







































Top comments (0)