CloudWatch Custom Metrics Part One

CloudWatch Custom Metrics Part One

CloudWatch custom metrics part one

Hello Everyone

Welcome to CloudAffaire and this is Debjeet

In the last blog posts, we have discussed the basics of CloudWatch.

https://cloudaffaire.com/cloudwatch/

In this blog post, we are going to create custom matrices for EC2 instance in CloudWatch. By default, AWS provides a set of default metrics for your EC2 instance monitoring. But you can always create your metrics and publish to the CloudWatch. There are several ways to create and publish your custom metrics in CloudWatch. In this demo, we are going to use AWS provided Perl scripts to create our own custom metrics.

Prerequisite for this demo:

  • One running EC2 instance.
  • IAM role with proper access to CloudWatch.

Create CloudWatch custom metrics for EC2 instance:

Step 1: Select your EC2 instance and click from ‘Actions’ click ‘Attach/Replace IAM Role’.

CloudWatch Custom Metrics Part One

Click ‘Create new IAM role’. You will be navigated to IAM page.

CloudWatch Custom Metrics Part One

Note: If you already have an IAM role with proper access the select it from the drop-down. In this demo, we will create an IAM role as well.

Click ‘Create Role’.

CloudWatch Custom Metrics Part One

Select ‘EC2’ as service and click ‘Next:Permission’

CloudWatch Custom Metrics Part One

Click ‘Create policy’.

CloudWatch Custom Metrics Part One

Provide below JSON block under JSON and click ‘Review Policy’.

CloudWatch Custom Metrics Part One

Provide a name to your Policy and click ‘Create Policy’.

CloudWatch Custom Metrics Part One

Select the policy and click ‘Next: Tags’.

CloudWatch Custom Metrics Part One

Provide a name to the IAM role and click ‘Review’.

CloudWatch Custom Metrics Part One

Click ‘Create role’.

CloudWatch Custom Metrics Part One

One success message will be displayed.

CloudWatch Custom Metrics Part One

Next, select the IAM role and click ‘Attach’.

CloudWatch Custom Metrics Part One

Our instance is ready for deployment of custom scripts provided by AWS.

Step 2: Login to your EC2 instance install some Perl packages required to run the Perl script.

CloudWatch Custom Metrics Part One

Step 3: Download the AWS provided Perl scripts.

CloudWatch Custom Metrics Part One

Step 4: Unzip the Perl script.

CloudWatch Custom Metrics Part One

Step 5: Test if the script is working

CloudWatch Custom Metrics Part One

Note: For complete parameter list, please refer below AWS documentation

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html

Try to publish a single data point in CloudWatch

CloudWatch Custom Metrics Part One

Note: We have successfully published a single data point in CloudWatch using AWS provided Perl script. You can also check the CloudWatch console under Metrics.

Before custom metrics publication:

CloudWatch Custom Metrics Part One

After custom metrics publication:

CloudWatch Custom Metrics Part One

CloudWatch Custom Metrics Part One

You can also put the script under a cron job to continually get custom metrics data in CloudWatch.

CloudWatch Custom Metrics Part One

CloudWatch Custom Metrics Part One

Hope you have enjoyed this article. In the next blog post, we will use our own script to monitor and publish metrics data in CloudWatch using AWS CLI.

To get more details on CloudWatch, please refer below AWS documentation

https://docs.aws.amazon.com/cloudwatch/index.html

Leave a Reply

Close Menu