DEV Community

Cover image for How To Create a CloudWatch Dashboard for EC2 and ELB
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

How To Create a CloudWatch Dashboard for EC2 and ELB

1. Create two EC2 by using User-Data-Amazon-Linux Script

  • Launch Two EC2 with Two Availability Zone

  • I will left information about vpc,subnet[public],security. Please configure with yours.

  • Attach IAM Instance role by using CloudWatchAgentServerPolicy

  • Add User Data and Click Launch Instance
  • Wait until 2/2 checks passed

2. Create LoadBalancer

  • Click Load Balancer

  • Click Create load balancers

  • Click Create of Application Load Balance

  • Write Load balancer name

  • Choose your vpc, select public subnet which route to IGW, security group

  • Click Create target group

  • Write Target group name and Click Next

  • Choose both EC2 and Click Include as pending below

  • Click Create Target Group

  • Choose LabTG

  • Click Create load balancer

3. Open Running Public IPv4 DNS in browser

  • Reload these links in browser a few times

  • Add /admin.php at the end of public ipv4 dns and reload in browser a few times

4. Create a metric filter for 404 errors

  • In the AWS Management Console, type CloudWatch and click this.

  • In the navigation pane, in Logs, select Log groups

  • Click access_log

  • In the Log streams tab, select the i-02a1487b82ba62ad7

• In Filter events, enter 404, and then press Enter.

  • Click Create metric filter

  • Filter name - LabServer1-Error404

  • Metric namespace - CloudwatchLab

  • Metric name - LabServer1-Error404

  • Metric value - 1

  • Default value - 0

  • Unit - Count

  • Click Create

  • Configure like this for i-0ab69fd72c3a5498c too but changes as 2 for Filter name and Metric name.

5. Create a custom CloudWatch dashboard

  • Click Dashboards

  • Click Create dashboard

  • Write name and Click Create dashboard

  • Click Next

  • Select Untitled graph, and then enter 404-Error-log

  • Click CloudwatchLab

  • Click Metrics with no dimensions

  • Select both EC2 and Click Create widget

  • Click +

  • Click Next

  • Select Untitled graph, and then enter Alb-Traffic-Log

  • Click ApplicationELB

  • Click Per AppELB Metrics

  • Choose the metric you want to monitor and Click Create widget

[!NOTE]
Choose your alb carefully if you have a lof of alb

  • Click +

  • Click Next

  • Select Untitled graph, and then enter Memory Usage

  • Type mem_used_percent and enter

  • Click ImageId, InstanceId, InstanceType

  • Select both EC2 and Click Create widget

  • Click +

  • Click Next

  • Select Untitled graph, and then enter CPU Usage

  • Type CPUUtilization and enter

  • Click Per-Instance Metrics

  • Select both EC2 and Click Create widget

  • Click Save


Status: Complete ✅

Congratulations on successfully completing this.


Related Resources


Top comments (0)