Monitoring and Optimization

Learn how to monitor Cosmos DB accounts and tweak them to keep costs down and improve performance.

Introduction

Maintaining a database is extremely important to keep performance high and costs down. However, before optimization, we need to identify what needs improvement. Let’s see what we can do about it.

Metrics

Metrics are at the core of Cosmos DB monitoring. We can get metrics of anything related to the account, from RUs, requests to databases created, and integrated cache hits.

The Azure portal

Our first stop is the account’s “Insightspanel. Here is an overview of the major metrics; we can customize the view and check individual databases.

Press + to interact
Metrics view from the “Insights” panel
Metrics view from the “Insights” panel

Another useful place is the account’s “Metrics” panel. Here, we can do the following:

  • Display multiple metrics.

  • Apply filters.

  • Choose a chart representation.

  • Split the data by property.

Press + to interact
Metrics view from the “Monitor” panel
Metrics view from the “Monitor” panel

If we need a higher-level view, even from multiple subscriptions, we can use the Azure Cosmos DB panel in Azure Monitor.

Press + to interact
Metrics view from Azure Monitor
Metrics view from Azure Monitor

Finally, when running a query in the “Data Explorer” panel, we can check the “Query Stats” tab for more details.

Press + to interact
“Query Stats” tab in the “Data Explorer” panel
“Query Stats” tab in the “Data Explorer” panel

Note: When using the SDK, we can get the request charge too. Each response object has a RequestCharge property we can use.

Azure Log Analytics

For the most detailed data, for example, we can use Azure Log Analytics to get precise usage of individual partitions. ...