- [Morgan] In this video, I'm going to run through some of the features that Amazon CloudWatch has to offer. We've already deployed resources into our AWS account for the employee directory application. So to get a handle on what CloudWatch is and how it works, let's dive in to the AWS console and see what we can see. The end goal of this demo is to set up a dashboard that shows us the CPU utilization of the EC2 instance that we launched hosting our employee directory application. And then we also want to set up an alert that will be sent out if the CPU utilization of the instance goes over 60% for a period of time. Something to note about CloudWatch is that a lot of AWS services begin reporting metrics to CloudWatch automatically when you create the resources. So let's go ahead and hop in the AWS Console now, and let's explore what types of metrics are available from the resources we have already created in previous lessons. You can see that I'm already in the AWS Management Console. And what I want to do now is navigate to CloudWatch and select the service. And this brings me to the CloudWatch dashboard. And so now what I want to do to view the metrics that were created by the resources from previous lessons, I'm first going to create a dashboard. So I'm going to go ahead and click "Dashboards." A dashboard in CloudWatch is a customizable page in the console that you can use to monitor different types of resources in a single view. This includes resources that are spread across different regions. I want to create a dashboard that shows me the CPU utilization over time for the EC2 instance. So now what I'm going to do is I'm going to create a dashboard. We're going to click "Create dashboard." And then we'll name it "My Dashboard." And click "Create dashboard." Next, we then select what we want to add to this dashboard, and we call them widgets. So I want to add a line graph as a widget on this dashboard because I want to compare the CPU utilization over time. So a line is going to be good for this one. Then I'll click "Next." And then it asks, "From which data source would you like to create the widget?" You can select "Metrics" or "Logs." I'm going to go ahead and select "Metrics" in this case, and then we'll click "Configure." And now down here, it's listing all of the metrics, and it groups by service because, again, AWS resources do often automatically post metrics to CloudWatch when it's created. So I'm going to go ahead and select EC2 for the service. And then I want to select "Per instance metrics." And now I'm going to filter the instances in this account by the instance ID for our employee directory application, which I just had copied in my clipboard. And now we can scroll down and see all of the different metrics that are available for this CPU instance. I'm going to go ahead and select "CPU utilization" here, and then I'm going to select "Create widget." All right, so now we can see that we have this widget, this line graph, showing us the CPU utilization, and this gives us visibility into one aspect of the health of our EC2 instance. You can explore, in your own account, what other metrics are available to you through CloudWatch by default, but you also can report custom metrics to CloudWatch programmatically. This is good to know because with EC2 and CloudWatch, you only get visibility into the health of the instance by default, which doesn't really give you a holistic picture of the health of your application. The application running on the instance might not be operating correctly, but the CPU utilization could be fine. So keep in mind that you may choose to use custom metrics to get a more detailed and accurate view of health in these dashboards. So now, once a dashboard is created, you can then share it with others on your team, so that everybody can get a good view of the health of your application. So now that we we've created this dashboard, we're going to go ahead and click "Save dashboard," and that saves the widget here. And if you just hover, you can see the different data points and what the CPU utilization was. You can see we hit a spike, where we really maxed out our CPU for a couple of minutes here earlier today, and then it came back down. So this would have been indicative of some sort of operational event going on. So next thing we want to do is move on to another feature of CloudWatch, and that is Amazon CloudWatch Alarms. So now I'm going to go ahead and click "Alarms" here, and notice I have no alarms in this account. What I want to do is create a CloudWatch alarm that will notify me whenever the CPU utilization goes over a certain threshold. So just in general, CloudWatch Alarms allow you to create thresholds for the metrics that you are monitoring. And these thresholds can define normal boundaries for the values of the metrics. If a metric crosses a boundary for a period of time, then the alarm would be triggered. And you can then take a couple of different automated actions after an alarm is triggered. In our case, I just want to notify someone via an email when the CPU utilization spikes over 60% for some period of time, say five minutes. So let's create an alarm to do that. So now what we will do is click "Create alarm," and then we will select the metric for this alarm. We'll select "EC2," "Per-instance metrics," just as before, paste in that instance ID, and then select the CPU utilization metric, and click "Select metric." From here, you can give this a specific name, if you would like, and then you also have to select what type of statistic this is. We're going to leave it as average because we want to view the average CPU utilization over a time period. In this case, we are going to leave the time period to be five minutes. You want to make sure that you pick a reasonable time period, where you don't wait too long to respond, but you also don't respond to every short-lived uptick in CPU utilization. There is a balance to strike here, and it will be highly dependent on your specific situation and your desired outcome. Okay, so now I will scroll down, and I'm going to then type in "60" for the defined threshold here. And we are looking for the alarm to trigger when the metric crosses the threshold of 60% for more than five minutes. So now I'm going to go ahead and click "Next." And this brings us to the "Configure actions" page. And so for this one, you can now decide, "Okay, what are we going to do once this alarm is triggered?" For CloudWatch Alarms, there are three states an alarm can be in. Either in alarm, okay, or insufficient data. An alarm can trigger an action when it transitions between these three states. In our case, I want to have this send out an alert to an email address when it transitions from okay to in alarm. AWS has a service called Amazon Simple Notification Service, or SNS, which allows you to create a topic and then send out messages to subscribers of this topic. You can imagine a scenario where we have system admins or developers on call for our employee directory application. And if something goes wrong, we want to send them an email, paging them, letting them know that something is wrong with the app that they need to look into. So in order to make that happen, what we're going to do is we are going to select "Create new topic," and then we can give the topic a name. All we have to make sure here is make sure that it is unique. So I'm going to go ahead and name this, "Employee-App-CPU." And then we are going to select the email endpoint that will receive notification. In this case, I'm going to go ahead and just put my email address, and then we'll click "Create topic." Now that that is created, we will scroll down and then click "Next." We'll give this alarm a name. This will be "Employee App CPU Util." And then click "Next." And now we can preview this alarm. So notice the red line here. We set the alarm at 60%. We would have triggered an alarm earlier, but we didn't have anything in place, so we didn't know that anything was going on. After this, if it spikes again, we should be able to get an email sent out to our admin, which in this case is me. All right, so I'll scroll down and then just click "Create alarm," and there it is. This will remain in the insufficient data state for a little while until it gathers enough information about the CPU utilization to be able to correctly read if this is okay or if it is in alarm. All right, so what we've done now is we've created a dashboard that is monitoring the CPU utilization of our instance. And we've created a CloudWatch alarm that will send out an email, using Amazon SNS, whenever the metric crosses the threshold. There are also other actions that you can take when an alarm is triggered, and we will go over that in upcoming lessons. So that's it for now. We will continue to use CloudWatch in upcoming lessons to make our solution elastic through EC2 auto scaling. For now, you know the basics, and I encourage you to explore CloudWatch in your own account and create dashboards for your employee directory application.