Monitoring Custom Spring Boot Application Logs

Using AWS CloudWatch

Nasi Jofche
Level Up Coding
Published in
4 min readApr 10, 2020

--

Photo by Luke Chesser on Unsplash

When your application is ready to roll out in production, monitoring every single activity related to it has a significant impact on its performance. You might need to analyze the server’s CPU utilization, network bandwidth, number of connections that it serves at the same time and so on.

AWS provides a monitoring service called CloudWatch, which would enable you to monitor different metrics for the servers your application is hosted on and store these metrics for later analysis. However, your application might be generating custom internal logs that are related to different business events: are they executing as expected, how long each business event is running for, etc. and you want to centralize the log monitoring process by pushing every log to the same monitor as well as aggregate the data for further analysis.

To demonstrate this capability of CloudWatch, I will utilize the AWS Java SDK to build a simple Spring Boot application that would measure the time it takes for an action to be performed and will publish the metrics to CloudWatch. Note that the metrics will be available to CloudWatch as time series that you can further analyze. This use case could be useful when you are architecting a MicroService solution, and you want to measure the time it takes for a business event that involves multiple invocations to other services in order to be completed.

It’s worth noting that, by default, we have permissions to post metrics through the AWS CLI or API. To demonstrate this, I have created a custom policy that will give explicitly deny the permission to publish metrics to CloudWatch, as shown below, and if I assign this policy to the IAM user, I won’t be able to publish the custom metrics data through the CLI or the SDK.

I have initially created an IAM user with EC2 permissions (as I am also collecting metrics from EC2 instances but won’t be showing that in this article).I have also created a simple Spring Boot application, with the AWS CloudWatch…

--

--