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 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

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-:

  • namespace -: It resembles the unique namespace of your metric to differentiate with other custom or predefined metrics for ex-: –namespace “MyNameSpace”
  • metric-name -: It defines the metric name which we used to store our metric data for ex-: –metric-name “FREE RAM”
  • value -: it resembles the exact value of our metric at particular time period for ex-: –value 56
  • timestamp -: it helps to map the timestamp with the values of metrics for ex-: –timestamp 2016-06-14T12:00:00
  • region -: It define the region in which our server is running for ex-: –region us-west-2

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


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.


Category(s) aws cloudwatch logs metrics
. . .


Add Your Comment

Be the first to comment.