Lesson 1: Core Metrics / Learn

Video Transcript (English)

Monitoring is essential to any production deployment but knowing what to monitor is even more important.

In this video, we’ll cover some core metrics to monitor and learn how these metrics can help you manage your deployment.

When it comes to monitoring we need to establish a few things: What we should monitor, What is a normal or baseline value, What is an acceptable burst value, What is out of range. 

Let’s start with what we should monitor.

MongoDB provides a rich set of metrics for us to monitor. So rich that it can become overwhelming.

However, the following metrics are considered core metrics: Query Targeting, Storage, CPU utilization, Memory, utilization, Replication lag. 

Let’s take a look at each one.

Query Targeting measures read efficiency by analyzing the ratio of documents scanned to documents returned by a read operation.

The ideal ratio is one to one; this means every document scanned was returned. As the ratio increases the efficiency of the query decreases. A very high ratio, for example 10000 documents scanned to 1 returned, negatively impacts the system performance.

This metric will help you determine whether you need to optimize your queries and indexes.

Here’s an example of what you might see for Query Targeting on our Atlas Metric Dashboard. Don’t worry if you don’t know where the Atlas Metric Dashboard is, we’ll show you how to access it later in the unit!

The y-axis represents the ratio while the x-axis shows this ratio over time.

The blue line shows the ratio of index keys scanned to documents returned.

The green line is the ratio of documents scanned to documents returned.

This chart shows that read operations are right around the ideal ratio of 1 to 1.

Storage metrics help to monitor disk space used by collections, databases, and indexes.

Writes are refused once the storage capacity is reached and the affected MongoDB instances could crash.

Some key metrics for storage capacity and performance include: Disk Space Percent Free, Disk IOPS, Disk Queue Depth and Disk Latency. 

Here’s an example of what you might see for storage metrics on our Atlas Metric Dashboard.

First up is free disk space percentage. Looks like we have over 70% available. Next, we have Disk IOPS or input/output operations per second. Looks like we are mostly writing in this case. Sometimes the disk or the storage subsystem can become a bottleneck such that operations are waiting to be serviced. This is where the Disk Queue Depth might be useful.

Here it shows a very low average queue depth which indicates operations are not really waiting. And finally, we have the Disk latency metric where we can see the number of milliseconds required to complete a storage operation. Storage operations are completed relatively quickly in this example.

Next up let’s talk about CPU utilization.

CPU metrics track CPU usage by your deployment and include the System CPU and Process CPU metrics.

Prolonged high CPU usage can lead to operation delays and often indicates poor query performance or inadequate hardware sizing.

Monitor these metrics to determine if you need to optimize query performance with indexes or if you need to upgrade your cluster.

Here’s an example of what you might see for CPU metrics on our Atlas Metric Dashboard.

This graph represents the System CPU metric and includes all of the items running on the host operating system.

By contrast, this graph represents the CPU metric for the MongoDB process only.

Both of these graphs include various CPU related items such as user, kernel, etc.

On to memory. 

Memory metrics provide information about the amount of system memory available for your workloads.

A MongoDB deployment will reserve most available system memory for its use. In fact, MongoDB recommends a system be sized with enough memory to hold all of the indexes.

Insufficient memory for your workloads can result in performance issues or even out of memory conditions.

Some key metrics for monitoring memory include: System Memory and Swap Usage. 

Here’s an example of what you might see for memory metrics on our Atlas Metric Dashboard.

The system memory graph shows us the amount of ram used as well as the amount available over time. Looks like we are currently using about 1GB and have another GB to spare.

Memory pressure can sometimes lead to increased swap usage and this graph shows how much swap we have configured and how much we are currently using.

Last but not least is replication lag.

This metric measures the delay between an operation on the primary and the application of that operation on the secondary.

The metric is expressed in seconds.

Some replication lag is acceptable, but excessive replication lag can be a significant issue that can negatively impact elections and distributed read consistency in replica sets.

Here’s an example of what you might see for replication lag on our Atlas Metric Dashboard.

This chart is showing a consistent value of 0 seconds on the y-axis so it looks like we don’t have any replication lag, great!

Let’s now talk a little bit about normal or baseline values.

Apart from query targeting, the baseline value for each of our metrics will vary depending on the workloads.

To establish such a value we recommend sampling each of the metrics during steady workload execution.

For example: A website application during normal traffic conditions.

How about burst values? Query targeting aside it’s normal for these metrics to have occasional spikes.

Excessive spiking or prolonged periods of sustained spikes could indicate an issue.

And trouble comes when these values go out of range.

For query targeting, an out of range condition would be a very high ratio of documents scanned to documents returned.

Replication lag can be considered out of range when a secondary is unable to keep up with a primary and eventually requires a resync.

For the rest of the metrics we have discussed, an out of range condition is resource exhaustion; which is typically 90% or above.

Great work! In this video, we discussed a core set of metrics to monitor. These include: Query Targeting, Storage, CPU utilization, Memory, utilization, Replication lag.

We also discussed baseline and burst values, as well as what is considered out of range for these metrics.