Aegis Java application development team is sharing this post with global developers and java development community to let them know about the concept of Cloud Watch and AWS. Experts have also discussed Architecture of Amazon Cloud Watch. To know further, read this article.
What is Cloudwatch?
Cloud was basically invented to separate the content from the device and storing it in central trusted servers thus enabling the users to access their data from any where and everywhere from any device. The Amazon Cloud (AWS) takes a leap further than just storing the data. As the concept of a Cloud evolved, things started drifting from just storing the data to storing entire application, to even sharing of computer resources like memory, hard disk, database. And hence came to birth the concept of Platform as a Service (PaaS), Application as a Service (AaaS) and SaaS (Software as a Service). This truly defines the cloud in the modern days. Hence in a layman language, the Cloud is watching you. But then who watches the Cloud?
The answer to this is CloudWatch. CloudWatch is another awesome service provided by AWS that helps to monitor the entire cloud for its different parameters such as memory usage, database usage, cpu utilization, etc. This helps the developer to analyze and monitor the performance of their application and the servers, the performance of the database and hence fine tune it in any way manner possible that will reduce the costs to run the application in the cloud. And also its just not about costs, sometimes the application needs to determine the performance of different services of AWS that it is using to draw out analytics and important conclusions from it. Cloudwatch can be accessed using many programming languages, the most prominent being Java. Java development being the strong part, the article will mainly focus on accessing cloudwatch using Java.
AWS and Cloudwatch?
Amazon Web Services (AWS) is a Cloud Service and it is one of the largest Cloud providers amongst all those who are available. AWS comes with a bunch of services, all of them catering to the cloud model, that allows any application to use the powerful advantages that the Cloud model suggests. Starting from sharing of the processing power, to the database, to the security system, to the sharing of computer hardware, it is one-stop-shop for any cloud requiring application. One of the most famous and widely used service is that of Cloudwatch: A cloud monitoring system.
The operations on Cloudwatch can either be performed using the AWS UI, AWS CLI (Command Line Interface), or the AWS SDK. The SDK comes for a variety of languages enabling a wide variety of developers to code the applications performing operations on the service. We shall be discussing the Java approach to the system, because the Java team in the company has had a long experience developing the applications using Cloudwatch to monitor the system. The per-requisites for operating in Java would be a JAVA SDK and Maven installed on the machine.
Some of the advantages of using Cloudwatch are as follows:
- Monitor EC2 – Helps monitor the EC2 instances for its memory usage, network bandwidth usage, disk usage activity etc. Consists of Basi
- Monitor Other AWS Resources – Monitor metrics on Amazon DynamoDB tables, Amazon EBS volumes, Amazon RDS DB instances and many of other services
- Monitor Custom Metrics – It is possible to create custom metrics from our application or via the UI and have Cloudwatch monitor them for custom purposes
- Monitor and Store Logs – It is possible to store the logs generated by cloudwatch and then monitor to analyze the performance of the application and its different components. This can help understand the system better and improve the deficiencies of the same.
- Set Alarms – Cloudwatch provides a services to set alarms on the different metrics, such that when they are triggered, a notification is sent which helps in taking automated actions.
- View Graphs and Statistics – The AWS UI can be used to view graphs and statistics of the different alarms and keep a check on how are they performing.
How to use Amazon CloudWatch?
To use AWS Cloudwatch, or as a matter of fact, any of AWS Services, one must download the awssdk to use its features. In case of Maven usage, the following snippets of code are used to download the sdk. If Maven is not present, one can manually download the aws-java-sdk from the Internet. The versions can be changed to suit the needs.
Amazon CloudWatch Architecture
Before proceeding further it would be nice to understand some technical jargon associated with Cloudwatch. The architecture of Amazon Cloudwatch is as follows:
Amazon Cloudwacth is basically a repository for metrics. AWS resources adds metrics into the repository and the cloudwatch service provides statistics based on those metrics as depicted in the above figure.
- Metrics – A metric is the base concept of cloudwatch. It represents a set of data points ordered by time. The data points, either from other services in AWS or the custom ones, are meant to serve as a means of information when statistics are down about these data points. Metrics are region dependent i.e., a metric in one region is not available for another region.
- Namespaces – A container for a metric are namespaces. The namespaces are isolated from one other, which in turns means metrics in different namespaces from different applications are not mistakenly integrated into the same statistics.
- Dimensions – A metric is characterized by a set of specific characteristics and dimensions can be thought of categories for those characteristics. In specific terms, a Dimension is a key/value pair that helps uniquely identify a dimension.
- Time Stamps – Each metric has to be associated with a timestamp in cloudwatch. The range for the timestamp is up to 2 weeks in the past and up to 2 hours in the future. If the timestamp is not provided, the service creates a timestamp based on the time the data was received.
- Units – It represents the statistical unit of measure. Some of the common units supported by the service include Seconds, Bytes, Bits/second, Count/second.
- Statistics – Statistics represent the kind of information that one intends to receive from Cloudwatch. Some of the examples include Minimum, Maximum, Average, etc.
- Periods – A period is the duration associated with each Statistic. Although periods are expressed in seconds, the minimum granularity for a period is one minute. Accordingly, you specify period values as multiples of 60. For eg, minimum for a period of 360 seconds, maximum for a period of 60 seconds, etc.
Following are the most important Cloudwatch API calls that are used very frequently and are the ones that we have been using in our projects.
1. PutMetricAlarm: This is the API call that is used to create an alarm in an aws account in a particular region.
The alarm created above is for Kinesis stream. It says, if more than 0 (Threshold) records are being put (Metric Name) into Kinesis (Namespace) stream (Dimension) for more (Comparison Operator) for more than 60 (Period x Evaluation Period) seconds, then trigger the Alarm.
One has to specify the region when creating the stream. AWS, with all of its services, is distributed in many different regions around the globe. The region is specified as follows:
The endpoint can be one of the many values as defined below:
- DescribeAlarms: This is the API call used to describe any/all of the alarms of Cloudwatch. It is used to describe the alarm in terms of what state the alarm is in, its last modified timestamp and so on.
- DeleteAlarms: This is the API call used to delete the Alarms from the Cloudwatch
- SetAlarmState: This is the API call used to set the state of the Alarm, for any reason, programmatically.
Aegis Java website application development team has shared the above post in order to acknowledge global java development community about Amazon CloudWatch and its architecture and use. You can leave your comments regarding this article and share your reviews with experts.