Start a Project

Create Custom metrics on AWS Cloudwatch

 

Cloudwatch service of AWS is very useful for the developers as well as for server admins because it helps them to find the bottleneck in their application architecture. AWS provide lots of pre-defined metrics to detect the issues regarding system and predifined services like CPU Limit, Disk Usage, Network Data etc. But if you want to monitor your system on the basis of other specifications then you can achieve it with the help of custom metrics.

To create a custom metric for your system you have to use the aws cli because it helps you to put data on the cloudwatch panel. You can download the aws cli for your OS distribution from here https://aws.amazon.com/cli/ and configure it by “aws configure” command which ask you for following parameters-:

After installing the aws cli on your system, now you need to grab the value which you want to send for creating the metrics for example we want to create a custom metrics for FREE RAM of the server, To grab the value of FREE RAM you can use the following bash script-:

SAVE this script with script.sh

In the script we have included the aws cli command as well which is used to put the data on AWS Cloudwatch panel, lets understand some of there parameters which are as follows-:

Now create a crontab entry of script.sh in your server for every minute so that it will send data to cloudwatch periodically every minute.

CRONTAB ENTRY

Now go to the cloudwatch panel and observe the graph of your metrics.

Now you can automate various tasks on the basis of your own custom metrics for ex-:

  1. You can create an alarm on cloudwatch custom metrics to detect any abnormal activity.
  2. You can also create an alarm to autoscale your EC2 instances on the basis of your own custom metrics.

Cloudwatch custom metrics help you to manage your server’s need according to your own created parameters and it helps you to analyze the logs more efficiently in graphical way.

 


Exit mobile version