Publishing custom metrics in CloudWatch
Once you get used to using CloudWatch, it is highly likely that you will want to see more than just the built-in AWS metrics.
One of the most common metrics users ask for after starting to run servers in EC2 is memory usage; the built-in metrics for EC2 instances are CPU utilization, network in/out, disk reads/writes, and status—memory is not included by default!
This recipe will show you how to feed the amount of memory inuse on your Linux instances to CloudWatch, so that you can see them alongside the other instance metrics.
Note
Knowing how utilized (or not) your instances are is a key component in choosing the right instance type to use for your workloads. Getting it wrong can cost you a lot of money!
Getting ready
You will need an EC2 instance running Linux, with the AWS CLI tool installed to perform this recipe. If you use an instance based on AWS Linux, you will have the AWS CLI tool installed for you.
The instance role or credentials you use to run...