Better monitoring metrics on Elastic Beanstalk Instances

Hero background

In one of my side-projects I have decided to explore how I can improve monitoring of different aspects of my infrastructure. 

After not long, I discovered the Elastic Beanstalk instances I'm using aren't emitting amazingly useful information. This is probably because it is assumed they are supposed to be mostly stateless and therefore shouldn't have to expose information about disk space, memory being free etc. 

After a little Google I discovered an excellent article by Emile Nijssen, go read the original here, it has all kinds of great details.

His solution is a YAML file that you'd push into the `.ebextensions` folder of your ElasticBeanstalk. Unfortunately, this approach has been deprecated with the introduction of Amazon Linux 2. Now you have to mash your deployment hooks into a `.platform` folder. I resolved to convert his script to the new structure. Please find it below.

All you have to do is:

  • download the script from the gist here;
  • add it to a folder called `.platform/hooks/postdeploy` in your project
  • make the cloudwatch.sh script executable (chmod +x cloudwatch.sh)
  • deploy your application that now has improved system metrics.