> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using CloudWatch for Resource Monitoring, Create CloudWatch Alarms and Dashboards

> Hands-on lab · 30m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab details

1. This lab guides you through the different features of CloudWatch that are used for monitoring resources.You will learn how to create CloudWatch alarms and dashboards, enabling you to effectively monitor your resources and set up notifications for important metrics.
2. Duration: **90 minutes**
3. AWS Region: **US East (N. Virginia) us-east-1**

### Architecture diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/iAkc8cvYvGsOYFCQ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/001.png?fit=max&auto=format&n=iAkc8cvYvGsOYFCQ&q=85&s=2df97dd9fe01c2530cd6520d7c144c5c" alt="" width="940" height="360" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/001.png" />

### Task details

1. Sign into the AWS Management Console.
2. Create an EC2 Instance.
3. SSH into EC2 Instance and install necessary Softwares.
4. Create SNS Topic.
5. Subscribe to an SNS Topic.
6. Check EC2 CPU Utilization Metrics in CloudWatch Metrics.
7. Create CloudWatch Alarm.
8. Testing CloudWatch Alarm by Stressing CPU Utilization.
9. Checking For an Email from the SNS Topic.
10. Checking the CloudWatch Alarm Graph.
11. Create a CloudWatch Dashboard.
12. Validation of the lab.

### Launching the lab environment

1. To launch the lab environment, Click on the **Launch lab** button.
2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
3. Once the Lab is started, you will be provided with **IAM user name**, **Password**, **Access** **Key**, and **Secret** **Access** **Key**.

## Lab guide

### Lab steps

#### Task 1: Sign in to AWS Management Console

1. Click on the **Open console** button, and you will get redirected to AWS Console in a new browser tab.
2. On the AWS sign-in page,

   * Leave the Account ID as default. Never edit/remove the 12 digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab.
   * Now copy your **User Name** and **Password** in the Lab Console to the **IAM Username and Password** in AWS Console and click on the **Sign in** button.
3. Once Signed In to the AWS Management Console, Make the default AWS Region as **US East (N. Virginia) us-east-1.**

#### Task 2: Launching an EC2 Instance

In this task, we are going to launch an EC2 Instance that will be used for checking various features in CloudWatch.

1. Make sure you are in the **N.Virginia** Region.
2. Navigate to **EC2** by clicking on the **Services** menu in the top, then click on **EC2** in the **Compute** section.
3. Navigate to **Instances** from the left side menu and click on **Launch instances** button.
4. Name : Enter **MyEC2Server**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/002.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=b9fdb505648a30f6e5902f312e62f62a" alt="" width="971" height="194" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/002.png" />

5. **For Amazon Machine Image (AMI):** Select **Amazon Linux** and the select **Amazon Linux 2023 AMI** from the drop-down.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/003.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=148f25b7605a7185f7470766c0bfe695" alt="" width="1222" height="796" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/003.png" />

6. For Instance Type: Select **t2.micro**

7. **For Key pair:** Select **Create a new key pair** Button

   * Key pair name: **MyEC2Key**
   * Key pair type: **RSA**
   * Private key file format: **.pem**

8. Select **Create key pair** Button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/004.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=85410374fecd22e988cd066a25ed4f7a" alt="" width="759" height="766" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/004.png" />

9. In Network Settings Click on **Edit** button:

* Auto-assign public IP: **Enable**
* Select **Create new Security group**
* Security group name : Enter **MyEC2Server\_SG**
* Description : Enter **Security Group to allow traffic to EC2**
* To add **SSH** :

  * Choose Type: Select **SSH**
  * Source: Select **Anywhere**

10. Keep Rest the things as Default and Click on **Launch Instance** Button.

11. Select **View all Instances** to View the Instance you created.

12. **Launch Status:** Your instance is now launching. Click on the instance ID and wait for complete initialization of the instance (until the status changes to running).

<Note>
  Select the instance and Copy the Instance-ID and save it for later, we need to search the metrics in CloudWatch based on this.
</Note>

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/005.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=8ab9449ca6347f7a593227495a58c541" alt="" width="1606" height="610" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/005.png" />

#### Task 3: SSH into EC2 Instance and install necessary Softwares

1. Follow the instructions provided in [SSH to EC2 instance](/aws-cp/support/ssh-into-ec2-instance) to SSH into the EC2 instance you created.
2. Once you are logged into the EC2 instance, switch to root user.

   ```
   sudo su
   ```
3. Update :

   ```
   dnf update -y
   ```
4. Stress Tool will be used for simulating EC2 metrics. Once we create the CloudWatch Alarm, we shall come back to SSH and trigger **CPUUtilization** using it.

   ```
   dnf install stress-ng -y
   ```

#### Task 4: Create SNS Topic

In this task, we are going to create a SNS Topic.

1. Make sure you are in the **N.Virginia** Region.
2. Navigate to **Simple Notification Service** by clicking on the **Services** menu available under the **Application Integration** section.
3. Click on **Topics** in the left panel and then click on **Create topic** button.
4. Under **Details**:

   * Type: Select **Standard**
   * Name: Enter **MyServerMonitor**
   * Display name: Enter **MyServerMonitor**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/006.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=298d3f4881b41db51fe8a4b14fad5626" alt="" width="1108" height="635" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/006.png" />

5. Leave other options as default and click on **Create topic** button. A SNS topic will be created.

> Note : Please ignore if below error message appears.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/007.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=965268af0883eb046b5477444b3b3395" alt="" width="2312" height="234" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/007.png" />

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/008.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=4dffa29676d724e11ae7b06308834673" alt="" width="1415" height="264" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/008.png" />

#### Task 5: Subscribe to an SNS Topic

1. Once SNS topic is created, click on SNS topic **MyServerMonitor.**
2. Click on **Create subscription** button.
3. Under Details:

   * Protocol : Select **Email**
   * Endpoint : Enter your email address
   * **Note:** Make sure you give proper email address as this is where your notification will be delivered.
4. You will receive a subscription confirmation to your email address

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/009.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=c55cba2e22b9b44343cfbd4ec327d9a7" alt="" width="809" height="218" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/009.png" />

5. Click on **Confirm subscription**.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/010.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=7aae93ad41dfe2d207562ba2eacd5703" alt="" width="723" height="424" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/010.png" />

6. Your email address is now subscribed to SNS Topic **MyServerMonitor**.

#### Task 6: Using CloudWatch to Check EC2 CPU Utilization Metrics in CloudWatch Metrics

1. Navigate to **CloudWatch** by clicking on the **Services** menu available under the **Management & Governance** section.
2. Click on **All metrics** under **Metrics** in the Left Panel.
3. You should be able to see **EC2** under **All Metrics.** If EC2 is not visible, please wait for 5-10 minutes, CloudWatch usually takes around 5-10 minutes after the creation of EC2 to start fetching metric details.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/011.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=35a111dde6f14a2ca60a4ed0ab1c72c2" alt="" width="1019" height="360" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/011.png" />

4. Click on **EC2**. Select **Per-Instance Metrics.**
5. Here you can see various metrics. Select the CPUUtilization metric to see the graph.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/012.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=83b7139d5b3e65879898a875d1c61cbd" alt="" width="1009" height="222" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/012.png" />

6. Now at the top of the screen, you can see the CPU Utilization graph (which is at zero since we have not stressed the CPU yet).

#### Task 7: Create CloudWatch Alarm

CloudWatch alarms are used to watch a single CloudWatch metric or the result of a math expression based on CloudWatch metrics.

1. Click on **In alarms** under **Alarms** in the left panel of the CloudWatch dashboard.

2. Click on **Create alarm** available on the top right corner.

3. In the **Specify metric and conditions** page:

   * Click on **Select metric**. It will open the **Select Metrics** page.
   * Scroll down and Select **EC2**.
   * Select **Per-Instance Metrics**
   * Enter your **EC2** **Instance-ID** in the search bar to get metrics for **MyEC2Server**
   * Choose the **CPUUtilization** metric.
   * Click on **Select metric** button.

4. Now, configure the alarm with the following details:

   * Under **Metrics**

     * Period: Select **1 Minute**
   * Under **Conditions**

     * Threshold type: Choose **Static**
     * Whenever CPUUtilization is… : Choose **Greater**
     * than: Enter **30**
   * Leave other values as **default** and click on **Next** button.

5. In **Configure actions** page:

   * Under **Notification**

     * Alarm state trigger: Choose **In Alarm**
     * Select an SNS topic: Choose **Select an existing SNS topic**
     * Send a notification to… : Choose **MyServerMonitor** SNS topic which was created earlier.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/013.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=f05fcd8c381fcb80092f8c0312de2a4e" alt="" width="1022" height="682" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/013.png" />

* Leave other fields as default. Click on **Next** button.

6. **In the Add a description** page, (under Name and Description):

* Name: Enter the Name **MyServerCPUUtilizationAlarm**
* Click on **Next** button.

7. A preview of the Alarm will be shown. Scroll down and click on **Create alarm** button.

8. A new CloudWatch Alarm is now created.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/014.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=bdd5a8213d264b2bba734388eedc40ac" alt="" width="915" height="203" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/014.png" />

* Whenever the CPU Utilization goes above **30** for **more than 1 minute**, an SNS Notification will be triggered and you will receive an email.

#### Task 8: Testing CloudWatch Alarm by Stressing CPU Utilization

1. SSH back into the EC2 instance - **MyEC2Server**.

2. The stress tool has already been installed. Lets run a command to increase the CPU Utilization manually.

   ```
   sudo stress-ng --cpu 10 -v --timeout 400s
   ```

3. This command shall monitor the process created by the stress tool(which we triggered manually). It will run for **6 minutes and 40 seconds**. It will monitor CPU utilization, which should remain very near 100% for that amount of time.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/015.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=d811cc2b1d01dacc2f1a2b986d393256" alt="" width="1890" height="1112" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/015.png" />

4. Open another Terminal on your local machine and SSH back in EC2 instance - **MyEC2Server**.

5. Run this command to see the CPU utilization if you are a MAC or Linux User. For Windows User, you can navigate to Task manager.

   ```
   top
   ```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/016.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=de13814924230b28037ed9a22b2d29e3" alt="" width="632" height="520" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/016.png" />

6. You can now see that **%Cpu(s)** is **100**. By running this stress command, we have manually increased the CPU utilization of the EC2 Instance.
7. After 400 Seconds, the %Cpu will reduce back to **0**.

#### Task 9 : Checking For an Email from the SNS Topic

1. Navigate to your mailbox and refresh it. You should see a new email notification for **MyServerCPUUtilizationAlarm**.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/017.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=4e85f59004d59a23e1782026b60955f5" alt="" width="1050" height="648" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/017.png" />

2. We can see that mail we received contains details about our CloudWatch Alarm,(name of the alarm, when it was triggered, etc.).

#### Task 10: Checking the CloudWatch Alarm Graph

1. Navigate back to CloudWatch page, Click on Alarms.
2. Click on **MyServerCPUUtilizationAlarm**.
3. On the Graph, you can see places where CPUUtilization has gone above the 30% threshold.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/018.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=82daa1ec1845da8709222df4f95fe034" alt="" width="1043" height="425" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/018.png" />

4. We can trigger CPUUtilization multiple times to see the spike on the graph.
5. You have successfully triggered a CloudWatch Alarm for CPUUtilzation.

#### Task 11: Create a CloudWatch Dashboard

We can create a simple Cloudwatch dashboard to see the CPUUtilization and various other metric widgets.

1. Click on Dashboard in the left panel of the CloudWatch page.
2. Click on **Create dashboard** button.

   * Dashboard name: Enter **MyEC2ServerDashboard**
   * Click on **Create dashboard**
   * Add widget: Select **Line** Graph.
   * Click on **Next** button.
   * Select **Metrics**. Click on **Next** button.
   * On the next page, Choose **EC2** under the **Metrics** tab. Choose **Per-Instance Metrics**.
   * In the search bar, **enter your EC2 Instance ID**. Select **CPUUtilization**.

* Click on **Create Widget** button.

3. Depending on how many times you triggered the stress command, you will see different spikes in the timeline.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/019.png?fit=max&auto=format&n=kVc8M-Pi2Bf1BmgZ&q=85&s=2a16b0f198137cf790db86a19960a05e" alt="" width="254" height="286" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/019.png" />

4. Now click on the **Save** button.
5. You can also add multiple Widgets to the same Dashboard by clicking on **Add widget** button.

<Tip>
  **Do you know?**

  CloudWatch offers advanced features such as anomaly detection, which uses machine learning algorithms to automatically identify abnormal behavior in your metrics. This helps you to detect and investigate unusual patterns or potential performance bottlenecks in your resources.
</Tip>

#### Task 12 : Validation Test

1. Once the lab steps are completed, please click on the **Check my work** button on the left side panel.
2. This will validate the resources in the AWS account and shows you whether you have completed this lab successfully or not.
3. Sample output :

<img src="https://mintcdn.com/ip-cloud-architect-pathway/kVc8M-Pi2Bf1BmgZ/images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/020.gif?s=f76451583b9c275c99729365bdf66571" alt="" width="1000" height="445" data-path="images/labs/using-cloudwatch-for-resource-monitoring-create-cloudwatch-alarms-and-dashboards/020.gif" />

### Completion and conclusion

1. You have created an EC2 Instance for which CloudWatch Monitoring will be carried out.
2. You have successfully created an Amazon SNS Topic used by CloudWatch.
3. You have successfully subscribed to SNS topic using your email address.
4. You have used CloudWatch to see CPUUtilization Metrics using CloudWatch Metrics.
5. You have successfully created and triggered a CloudWatch Alarm based on the CPUUtilzation Metric.

### End lab

1. Sign out of AWS Account.
2. You have successfully completed the lab.
3. Once you have completed the steps, click on **End lab** button in the IP Lab Portal.

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Launch an EC2 Instance** — Check whether an EC2 Instance is launched or not.
* **Launch EC2 AMI type Amazon Linux** — Check whether the EC2 instance is launched using an Amazon AMI.
* **Create an Amazon SNS Topic** — Check If SNS Topic created or not
* **Check CloudWatch Alarm Creation** — Check whether at least one CloudWatch alarm exists or not.
* **Check Log Group** — Check whether a CloudWatch log group exists.

## Related help

* [FAQs and Troubleshooting](/aws-cp/support/faqs-and-troubleshooting)
* [SSH into EC2 Instance](/aws-cp/support/ssh-into-ec2-instance)
