Create Custom metrics on AWS Cloudwatch

Updated 7 February 2025

The Cloudwatch service of AWS is very useful for developers as well as for server admins because it helps them find the bottleneck in their application architecture.

AWS provides lots of pre-defined metrics to detect the issues regarding the system and predefined services like CPU Limit, Disk Usage, Network Data, etc.

But if you want to monitor your system based on 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 and configure it with the “aws configure” command which asks you for the following parameters-:

After installing the AWS CLI, grab the value you want to create metrics for, such as the server’s free RAM.

To grab the value of FREE RAM you can use the following bash script-:

SAVE this script with script.sh

The script includes the AWS CLI command to send data to CloudWatch. Let’s review its parameters:

  • namespace -: It resembles the unique namespace of your metric to differentiate from 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 a particular 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 defines the region in which our server is running for ex-: –region us-west-2

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 based on your 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 based on your custom metrics.

CloudWatch custom metrics let you manage server needs based on your parameters and analyze logs more efficiently with graphs.

Need Support?

Thank You for reading this Blog!

For further more interesting blogs, keep in touch with us. If you need any kind of support, simply raise a ticket at https://webkul.uvdesk.com/en/.

For further help or queries, please contact us or raise a ticket.


Category(s) AWS cloudwatch logs metrics
author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home