user246392
user246392

Reputation: 3018

Is there a way to easily track CosmosDB RU/s in Azure Functions?

I've combined Azure Functions with CosmosDB and need to track how many RU/s every function consumes. Is there an easy way to track this information? Some of my functions make trips to several containers to aggregate data, and so it's difficult to get RequestCharge from every operation and calculate the sum without accidentally skipping RU/s. I'm wondering if there is an existing integration with Functions.

If not, is it possible to define a static variable only for the current execution context so that I could leverage it in different classes for counting RU/s? Due to the serverless nature of Functions, I'm not sure how to define a static variable that won't be overwritten by another concurrent execution.

Upvotes: 0

Views: 250

Answers (1)

Mark Brown
Mark Brown

Reputation: 8763

It is not recommended to implement this kind of monitoring inside Azure Functions to do processing as it introduces a vector for processing of the item to fail.

If you are looking to monitor usage of Cosmos DB containers you should use one of the monitoring options in the Monitoring Azure Cosmos DB article.

However, given that your Functions are calling multiple containers another possible option is to manually measure each of the operations performed by each Azure Function and then monitor the execution counts in Azure Monitor on the Functions themselves and multiply by the RU/s you manually calculated.

Upvotes: 1

Related Questions