Monitoring

When we think of monitoring, the first thing that comes into our mind is observing and tracking the operations and activities of the software application regularly and setting up an alarm to trigger upon a system or application failure. Monitoring should begin right from the start of the development, in such instances as the monitoring of the speed of the application or monitoring how many resources a developed piece of code is using. This monitoring system should be coupled with a notification system, triggering a notification such as an email when memory is used beyond a defined threshold. 

But monitoring serverless functions is more tricky. In server monitoring, we monitor the performance of the server, network latency, and CPU, but these details are irrelevant with respect to serverless as the infrastructure is completely managed by the service provider. But then what should we monitor with respect to serverless? We can still monitor memory and concurrency rate. Although the service provider handles the provisioning and execution of Lambda functions, there is still a limit to the amount of memory that can be used and the concurrent executions allocated to the function. 

To perform serverless monitoring, there are number of tools available. There are a few out-of-the-box tools from AWS, such as AWS CloudWatch, which involves all the AWS resources feeding into AWS CloudWatch. CloudWatch will be our first tool to monitor the Lambda functions. CloudWatch tracks metrics such as the latency of execution, number of functions executed, and errors made during the execution. But we can go beyond this by setting up custom metrics within CloudWatch. We also looked at the CloudWatch dashboard for use with the Lambda function. 

AWS provides another powerful tool for the application performance of the lambda function, and that tool is X-ray. X-ray is a tracing tool that is integrated with AWS Lambda out of the box. It provides an end-to-end view of requests as they move. With X-ray, we can analyse how lambda functions and their connected services are performing. We can identify and troubleshoot the root causes of performance issues and errors, and with the map view of the application, we can see all of its components. 

Thundra is another monitoring tool that can be used as an application performance monitoring tool for AWS Lambda. It asynchronously publishes the data from CloudWatch into Thundra using functions and agents to send the monitoring data into the application. It has some really good charts that cover many metrics, such as the invocation counts, cold-start invocation counts and durations, error counts by error types and function names, and many more.