Creating a CloudWatch Dashboard for EC2 Instance

Ruchir B Pandya
5 min readJan 2, 2024

--

Introduction

CloudWatch dashboard provides a customizable, centralized view of your EC2 instance metrics. It is a tool provided by Amazon Web Services (AWS) that allows you to visualize and track metrics and alarms for your EC2 instances. In this blog, we will create an EC2 instance and attach it to CloudWatch dashboard. We will then add widgets to visualize the metrics we want to monitor.

Architecture Diagram

Courtsey: Whizlab

Task 1: Launch an EC2 instance

  1. Navigate to EC2 by clicking on the Services menu in the top, then click on EC2 in the Compute section.
  2. Navigate to Instances from the left side menu and click on Launch Instance.
  3. Enter Name as desired.
  4. Choose an Amazon Machine Image (AMI): Select Amazon Linux 2 AMI in the drop-down.
  5. Choose architecture as 64-bit(x86)

6. Choose an Instance Type: Select t2.micro.

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

  • Key pair name: your desired name
  • Key pair type: RSA
  • Private key file format: .pem

8. Select Create key pair Button.

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
  • Check Allow SSH from and Select Anywhere from dropdown
  • To add SSH

Choose Type: SSH and Source: Select Anywhere.

10. Leave the rest of the things as default.

11. Click on the Launch Instance.

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

13. Note the Public IPv4 Address and Instance ID of the EC2 instance. A sample is shown in the screenshot below.

Task 2: Creating a CloudWatch Dashboard

  1. Wait for 5–10 minutes for CloudWatch to gather metrics from EC2 Instance.
  2. Navigate to CloudWatch by clicking on the Services menu at the top of the page, then click on CloudWatch in the Management and Governance section.
  3. Click on Dashboards on the left panel.
  4. Click on Create Dashboard.
  5. Give a name to your dashboard.
  • Dashboard name: MyEC2
  • Click on Create dashboard button.

We have to select a widget type to configure and add to this dashboard. Select Line

Select Metrics as data source.

You will see a metric graph. Under All metrics, search and choose EC2 (since we are going to watch the metrics of EC2 which we created earlier).

Under EC2, choose Per-Instance Metrics.

Paste the copied Instance id in the search bar and select the CPUUtilization from the metrics and click on Create Widget button.

Note: If you don’t see the CPUUtilization metrics, wait for 5 minutes.

We have successfully created a Line widget for CPU Utilization.

Task 3: Creating different Widgets for same Metric

Stacked Area

  1. In the dashboard, click on the + button to Add widget and select Stacked area. Click on Metrics.
  2. You will see a metric graph. Under All metrics, search and choose EC2 (since we are going to watch the metrics of EC2 which we have created earlier).
  3. Under EC2, choose Per-Instance Metrics.
  4. Search and select the CPUUtilization from the metrics and click on Create Widget button.
  5. You have successfully created a Stacked Area widget for CPU Utilization.

Number

  1. In the dashboard, click on + button to Add widget and select Number.
  2. You can see a metric graph. Under All metrics, search and choose EC2 (since we are going to watch the metrics of EC2 which we have created earlier).
  3. Under EC2, choose Per-Instance Metrics.
  4. Search and select the CPUUtilization from the metrics and click on Create Widget button.
  5. You have successfully created a Number widget for CPU Utilization.

Click on Save Dashboard to save the widgets.

  • Refresh the page, until the metric value is shown.
  • Using these steps, you can use the widgets to create your own dashboard for metrics.

Note: The actual metric generated depends on the CPU Utilization.

Courtsey: Whizlab

Fun Fact: Do You know?

While CloudWatch dashboards are typically associated with a specific region, you can create cross-region dashboards. This allows you to aggregate metrics from EC2 instances across multiple regions into a single dashboard, providing a centralized view of your global infrastructure.CloudWatch dashboards support dynamic widgets that allow you to pass parameters and filter metrics based on runtime conditions.

Conclusion

  • We have successfully launched an EC2 Instance.
  • We have created a CloudWatch dashboard.
  • We have successfully created different widgets for the same metric.

I hope this short blog was helpful to gain basic understanding of creating CloudWatch dashbords using EC2 metrics

--

--