Amazon CloudWatch monitors your resources on Amazon Web Service (AWS) cloud. As we know that AWS offers over 140 services in its cloud that powers hundreds and thousands of businesses worldwide. And each of the services has a number of resources in it. So, there is a need to centralize the monitoring system with extended capability. AWS CloudWatch solves this problem and can virtually monitor almost every resource on AWS cloud.
Only monitoring isn’t sufficient in Cloud-based application. Amazon CloudWatch not just offers resource monitoring, it also comes with alarms, notifications, and actions. You can take certain actions based on your monitoring metrics. This reduces human and manual monitoring & actions which are very crucial for big deployments.
What is Amazon CloudWatch?
You might have started understanding the Amazon CloudWatch. It’s a service on AWS which monitors all your resources and application that you use or run. You can virtually monitor every resource, service, and application with Amazon CloudWatch.
Amazon CloudWatch allows you to create Dashboards which will display metrics as per your monitoring needs. You can also create Alarms and take actions based on the thresholds. Notifications for the same can be triggered which can send emails to your mailbox.
Why Amazon CloudWatch?
There are so many tools and software available for monitoring different platforms and applications. Almost, each platform and software offers monitoring tools with it. But the root problem is that when you are using a handful of services, applications, and software then it becomes nearly impossible to install and manage different monitoring tools.
Here Amazon CloudWatch comes in picture. You don’t need to install and manage different monitoring tools for the service that you use. You have almost all metrics available starting from HTTP error codes to CPU usage.
How Amazon CloudWatch Works?
Amazon Cloud watch is a service just like any other service on AWS. It stores all the monitoring related data and displays that data. In simple words, it’s a metrics repository. All of the services on AWS puts the monitoring data to this repository.
The statistics data can be presented in forms of various graphs which you can use in creating metrics and display on the Dashboards.
You can also link the EC2 scalability decision to the Amazon CloudWatch. Based on the threshold it can scale up and down the EC2 instances.
Amazon CloudWatch also allows you to create custom metrics which can be stored to metrics repository and retrieve the statistics data.
Let’s understand the terminology and concepts of Amazon CloudWatch:
Metrics are the core of Amazon CloudWatch fundamentals. Metrics contains the data points stored by the various services of the AWS cloud. For Example: Below is the metrics of CPU credit usage of an EC2 machine running on t2 series (Learn more about Amazon EC2). See the example metrics below from AWS CloudWatch:
Each data point in metrics stores a timestamp when it was recorded. Timestamps are DateTime objects, with the date, hours, minutes, and seconds (for example, 2019-09-12T11:55:24Z).
Metrics data points are associated with the retention policy as well. Retention means that when this data would not be retained.
Data points with a period of:
- fewer than 60 seconds are available for 3 hours.
- 60 seconds (1 minute) are available for 15 days
- 300 seconds (5 minutes) are available for 63 days
- 3600 seconds (1 hour) are available for 455 days (15 months)
If you are a programmer then you might know the concept of namespaces. In Amazon CloudWatch, namespaces are used to isolate the different metrics. These are basically the containers of metrics.
Statistics are the aggregations of data points for a certain time period. We already know that the metrics store the data point with the timestamp. AWS CloudWatch provides some predefined statistics for your metrics.
The available statistics are:
- Minimum – Minimum value observed during the specified time period.
- Maximum – Maximum value observed during the specified time period.
- Sum – Sum of the valuea during the specified time period.
- Average – Sum/Count during the specified time period.
- SampleCount – The count of statistical data pointss
Alarms in Amazon CloudWatch are used to initiate automated actions when a threshold has been breached. Alarms keep watching the metrics over a specified time period. If the threshold defined by you have been breached then it can take action like scale the EC2 instance or send an SNS topic etc.
Dimensions help you to decide the structure of statistics plan. A dimension is a name/value pair that is part of the identity of a metric. You can assign up to 10 dimensions to a metric.
For example, Server=Prod, Domain-Rio.
Get Started with Amazon CloudWatch
Let’s get started with Amazon CloudWatch:
- Go to the Amazon EC2 console at https://console.aws.amazon.com/.
- Go to Service tab and search for “CloudWatch”.
- You will see the default dashboard of CloudWatch. See the below screenshot:
Amazon CloudWatch allows you to create your own dashboards. Dashboards are customizable which you can use to monitor your resources on AWS Cloud.
Click on the menu “Dashboards” in the left section of CloudWatch home page and you will see the below screen.
You have used metrics and created your own dashboard. Now, let’s create an alarm on metrics.
To create an alarm, click on “Alarms” and you will see an empty page below.
Click on “Create Alarm” and you will be asked to fill the below details.
Choose a metric from the list of available metrics. Enter the name of the alarm and add a condition in whenever section. See the samples below:
You can take actions if the alarm triggered and breached the threshold as explained above. There are a number of actions that you take:
- Notfications: You can send notification to the email list whenever the alarm state is insifficient.
Note: You can add more than one notifications as well.
- AutoScaling Action: You can autoscale the service that you want as an action of the alarm. See below:
Note: This is just for information, to do the autoscaling, you need to know scaling and how to scale a software or service. We will post about it soon.