|« PreviousNext »|
|Did this page help you? Yes | No | Tell us about it...|
Amazon CloudWatch is a web service that enables you to monitor, manage, and publish various metrics and to configure alarm actions based on those metrics.
With Amazon CloudWatch, you can collect, analyze, and view system and application metrics so that you can make operational and business decisions quickly and confidently. Amazon CloudWatch automatically collects metrics about your AWS resources, such as the performance of your Amazon EC2 instances. You can publish your own metrics directly to Amazon CloudWatch.
You can use Amazon CloudWatch to diagnose problems by looking at system performance before and after a problem occurs. Amazon CloudWatch helps you identify the cause and verify your fix by tracking performance in real time. For example, you can set up Amazon CloudWatch to send you email right away when your application slows down, so you can go back and discover, for example, that a particular database was being overloaded. When you have fixed the problem, you can use Amazon CloudWatch to watch response times return to normal. For more information about creating CloudWatch alarms, go to Creating CloudWatch Alarms in the Amazon CloudWatch Developer Guide.
A common use for Amazon CloudWatch is to keep your applications and services healthy and running efficiently. For example, you can use it to discover that your website runs best when network traffic to your Amazon EC2 instances remains below a certain threshold. You can then create an Auto Scaling policy to ensure that you always have the right number of instances to match the amount of traffic you have.
In the previous task, we created an Auto Scaling policy to add to the number of running instances. In this task, we’ll associate that policy with an alarm action. When the alarm is triggered, Auto Scaling is notified and makes the appropriate changes to your resources.
You'll create an alarm with the following characteristics:
The following diagram demonstrates how Amazon CloudWatch and Auto Scaling work together. The Amazon EC2 instance reports its NetworkOut metric to Amazon CloudWatch. Amazon CloudWatch fires an alarm if the specified threshold has been been exceeded and reports this to the Auto Scaling Group. The Auto Scaling group then takes action based on the policy that is set.
This topic walks you through creating a CloudWatch alarm to alert the application when the threshold is exceeded. To save time, we'll create just one alarm; however, you can apply the same procedure to create other alarms. For example, you could create another alarm to notify Auto Scaling that it needs to terminate an instance. For more information about Amazon CloudWatch, see the Amazon CloudWatch details page.
To create an Amazon CloudWatch alarm
Select a metric for your alarm:
Open the Amazon CloudWatch console at https://console.aws.amazon.com/cloudwatch/.
In the top navigation bar, click US East (N. Virginia) in the region selector.
In the left navigation pane, click Alarm.
In the details pane, click Create Alarm.
In the Create Alarm Wizard, on the Select Metric page, in the Viewing list, select EC2: Aggregated by Auto Scaling Group.
Click the MyAutoScalingGroup/NetworkOut row, and then click Continue.
It can take up to 15 minutes for the Auto Scaling group to appear in the list. If you do not see your Auto Scaling group, wait up to 15 minutes, and then try again.
Define the alarm:
On the Define Alarm page of the Create Alarm wizard, do the following, and then click Continue:
In the Name box, type
In the Description box, type a description.
In the Define Alarm Threshold section, click
6000000 in the first
5 in the minutes box. For your own application,
you can do some load testing to see what values make the most sense.
Define your actions:
On the Configure Actions page of the Create Alarm wizard, do the following, and then click Add Action.
Under When Alarm state is, click ALARM.
Under the Take Action list, click Auto Scaling Policy.
In the Auto Scaling Group list, click MyAutoScalingGroup.
In the Policy list, click MyScaleUpPolicy (Add 1 instance).
Do the following, and then click Continue.
In the new row that is created, under When Alarm state is, click ALARM.
Under the Take Action list, click Send Notification.
In the Topic box, click Create New Email Topic and then type a topic name.
In the Email(s) box, type an email address where notifications will be sent.
On the Review page, review the settings. If everything is all right, click Create Alarm.
On the confirmation page, click Close.
On the dashboard page of the Amazon CloudWatch console, your new alarm now appears in the list.
If you create a MyScaleDownPolicy, you can create another alarm using the same steps.
Here's where you are in building your architecture.
Congratulations! You have successfully deployed your web application to EC2 using the some of the essential building blocks of AWS. To verify that everything is working as it should, do the following:
Refresh your browser. You should no longer be able to access your website, because you updated your security group to allow access only through your Elastic Load Balancer.
Type the public DNS address of your Elastic Load Balancer which you recorded in Step 7: Create an Elastic Load Balancer, to verify that you can see your application. Remember to append /dotnetnuke to the DNS address.
Because we deployed SQL Express on each Amazon EC2 instance, each instance is running its own local copy of the database. When you view your website, you may see different content. There are several ways you could change this architecture to keep your data in sync across instances, including using Amazon Relational Database Service (Amazon RDS). For more information about deploying your web application using Amazon RDS, go to Step 10: Add Amazon RDS in the Getting Started Guide AWS Web Application Hosting for Microsoft Windows.
In this tutorial, you learned how to deploy your web application by using the following AWS products:
Amazon EC2 to run your application
Elastic Load Balancing to load balance traffic across your running instances
Auto Scaling to automatically add and terminate instances according to policies that you set
Amazon CloudWatch to monitor your instances and to notify you when thresholds you specify are exceeded
When you have a better understanding of the AWS services and how you want to use them, there is an easier way you can deploy your application. AWS CloudFormation helps you deploy resources in AWS without worrying about the order in which AWS services need to be provisioned or the subtleties of how to make those dependencies work. To learn how to build sample template using the services we used in this tutorial, go to Auto Scaling Group with LoadBalancer, Auto Scaling Policies, and CloudWatch Alarms in the AWS CloudFormation User Guide.
If you are finished using your AWS resources, you can terminate them so that you are no longer billed. Move on to Step 11: Clean Up.