Data traffic is a major cost driver in a MongoDB Atlas cluster. Being able to break down traffic by collection name or even query type could help to identify inefficient queries and operations that cause high data traffic as a first step to optimize them.
According to MongoDB Atlas support (as of March 2022) there is currently no native way to break down data traffic by anything other than a cluster node. So the solution can only be somewhere on the client side, in my specific case the server that uses the MongoDB Node.js driver on make requests to the MongoDB Atlas cluster.
The obvious approach would be to build a layer on top of the MongoDB Node.js driver to log the data sizes for all sent and received request data and calculate the metrics from that.
However, the server that is making the requests runs in a Node.js environment on a EC2 instance in AWS, so I wonder whether there is a more elegant approach using AWS CloudWatch? The challenge is that the requests need to be broken down per MongoDB collection and MongoDB query type, which is information that is encoded in the request body, not the URL.