Solr Key Metrics to Monitor
Tags: solr, observability, metrics, devops
Published: 2019-05-20 12:07:09

---
title: Solr Key Metrics to Monitor
published: true
description: The key metrics to monitor when using Apache Solr search engine based on Apache Lucene. 
tags: #solr #observability #metrics #devops
series: Monitoring Solr
cover_image: https://thepracticaldev.s3.amazonaws.com/i/17rczv5t9d2fuden0fkj.png
---


As the first part of the three-part series on monitoring [Apache Solr](http://lucene.apache.org/solr/), this article explores which Solr metrics are important to monitor and why. The second part of the series covers [Solr open source monitoring tools](https://sematext.com/blog/solr-open-source-monitoring-tools/) and identify the tools and techniques you need to help you monitor and administer Solr and SolrCloud in production.

#Two Architectures

When first thinking about installing Solr you usually ask yourself a question - should I go with the [master-slave environment](https://lucene.apache.org/solr/guide/7_7/legacy-scaling-and-distribution.html) or should I dedicate myself to [SolrCloud](https://lucene.apache.org/solr/guide/7_7/solrcloud.html)? This question will remain unanswered in this blog post, but what we want to mention is that it is important to know which architecture you will monitor. When dealing with SolrCloud clusters you not only want to monitor per node metrics but also cluster-wide information and the [metrics related to Zookeeper](https://sematext.com/docs/integration/zookeeper/).

#Why Monitor Solr?

When running Solr it is usually a crucial part of the system. It is used as a search and analysis engine for your data - part of it or all. Such a critical part of the whole architecture is needed to be both fault tolerant and highly available. Solr approaches that in two ways. The legacy architecture also called master-slave - it is based on a clear distinction between the master server which is responsible for indexing the data and the slave servers responsible for delivering the search and analysis results.

![Solr master-slave architecture](https://thepracticaldev.s3.amazonaws.com/i/tkd86dmzjrxyey7kwz95.jpg)

When the data is pushed to the master it is transformed into a so-called inverted index based on the configuration that we provide. The disk-based inverted index is divided into smaller, immutable pieces called segments, which are then used for searching. The segments can also be combined together into larger segments in a process called [segment merging](https://sematext.com/blog/solr-optimize-is-not-bad-for-you-lucene-solr-revolution/) for performance reasons - the more segments you have, the slower your searches can be and vice versa.

Once the data has been written in the form of segments on the master’s disk, it can be replicated to the slave servers. This is done in a pull model. The slave servers use an HTTP protocol to copy the binary data from the master node. Each node does that on its own and works separately copying the changed data over the network. We already see a dozen of places that we should monitor and have knowledge about.

Having a single master node is not something that we would call fault tolerant, because of having a single point of failure. Because of that, the second type of architecture was introduced with Solr 4.0 release - the [SolrCloud](https://sematext.com/blog/scaling-solr-with-solrcloud/). It is based on the assumption that the data is distributed among a virtually unlimited number of nodes and each node can perform indexing and search processing roles. Physical copies of the data, placed in so-called [shards](https://sematext.com/blog/handling-shards-in-solrcloud/) can be created on demand in the form of physical replicas and replicated between them in a near real-time manner allowing for true fault tolerance and high availability. However, for that to happen we need an additional piece of software - [Apache Zookeeper](https://zookeeper.apache.org/) cluster to help Solr manage and configure its nodes.

![SolrCloud architecture](https://thepracticaldev.s3.amazonaws.com/i/shzislaoxw0hv5hw5shq.png)

When the data is pushed to any of the Solr nodes that are part of the cluster, the first thing that is done is forwarding the data to a leader shard. The leader stores the data in the write-ahead log called [transaction log](https://lucene.apache.org/solr/guide/7_7/updatehandlers-in-solrconfig.html#transaction-log) and, depending on the [replica type](https://sematext.com/blog/solr-7-new-replica-types/), send the data to the replica for processing. The data is then indexed and written onto the disk into the inverted index format. This can cause additional I/O requirements - as the data indexing may also cause [segment merging](https://sematext.com/blog/solr-optimize-is-not-bad-for-you-lucene-solr-revolution/) and finally it needs to be refreshed in order to be visible for searching, which requires yet another I/O operation.

When you send a search query to SolrCloud cluster, the node that is hit by the query initially [propagates the data to shards that are needed to be queried](https://sematext.com/blog/solrcloud-large-tenants-and-routing/) in order to provide full data visibility. Each distributed search is done in two phases - scatter and gather. The scatter phase is dedicated to finding which shards have the matching documents, the identifier of those documents and their score. The gather phase is dedicated to rendering the search results by retrieving the needed documents from the shards that have them indexed. Each search phase requires I/O to read the data from disk, memory to store the results and intermediate steps required to perform the search, CPU cycles to calculate everything and network to transport the data.

Let's now look at how we can monitor all those metrics that are crucial to our indexing and searching.

#Monitoring Solr Metrics via JMX

One of the tools that come out of the box with the Java Development Kit and can come in handy when you need quick, ad-hoc monitoring is jconsole. A GUI tool that allows one to get basic metrics about your [JVM](https://sematext.com/java-monitoring/), like [memory usage](https://sematext.com/java-monitoring/), CPU utilization, [JVM threads](https://sematext.com/java-monitoring/), loaded classes. In addition to that, it also allows us to read metrics exposed by Solr itself in the form of JMX MBeans. Whatever metrics were exposed by Solr creators in that form can be read using jconsole. Things like average query response time for a given search handler, number of indexing requests or number of errors - all can be read via the [JMX MBeans](https://sematext.com/java-monitoring/). The problem with jconsole is that it doesn't show us the history of the measurements.

![JMX monitoring](https://thepracticaldev.s3.amazonaws.com/i/032s9ygwn3uko2hm47ck.png)

*Jconsole* is not the only way of reading the JMX MBean values - there are other tools that can do that, like the open sourced [JMXC](https://github.com/sematext/jmxc) or our open-source [Sematext Java Agent](https://github.com/sematext/sematext-agent-java). Unlike the tools that export the data in text format, our Sematext Java Agent can ship the data to [Sematext Cloud](https://sematext.com/cloud/) - a full stack observability solution which can help you get detailed insight into your Solr metrics.

![Solr metrics overview](https://thepracticaldev.s3.amazonaws.com/i/yhvbl9pu70w6rj3hdl3x.png)

#Monitoring Solr Metrics via Metrics API

The second option for gathering Solr metrics is an API introduced in Solr 6.4 - the [Solr Metrics API](https://sematext.com/blog/solr-new-metrics-api-solr-64/). It supports on-demand metrics retrieval using the HTTP based API for cores, collections, nodes, and the JVM. However, the flexibility of the API doesn't come from it being available on-demand, but it being able to report the data to various destinations by using Reporters. Right now, out of the box the data can be exported with a little configuration to:
1. JMX - JMX MBeans, something we already discussed
2. SLF4J - logs or any destination that SLF4J supports
3. [Graphite](https://graphiteapp.org/)
4. [Ganglia](http://ganglia.sourceforge.net/)

We will cover the open source Solr monitoring solutions in greater details in the second part of this three-part monitoring series.

#Key Solr Metrics to Monitor

Having knowledge about how we can monitor Solr, let's now look into top Solr metrics that we should keep an eye on.

##Request Rate

Each handler in Solr provides information about the rate of the requests that are sent to it. Knowing how many requests in total and per handler are handled by your Solr node or cluster may be crucial to diagnose if the operations are going properly or not. A sudden drop or spike in the request rate may point out failure in one of the components of your system. Cross-referencing the request rate metric with the request latency can give you information on how fast your requests are at the given rate or show potential issues that are coming your way when the number of requests is the same, but the latency starts to grow.

![Request rate](https://thepracticaldev.s3.amazonaws.com/i/pcqas6vli0o88h8lwkqm.png)

##Request Latency

A measurement of how fast your requests are, similar to the request rate, is available for each of the handlers separately. It means that we are able to easily see the latency of our queries and update requests. If you have various search handlers dedicated to different search needs, i.e. one for product search, one for articles search, you can easily measure the latency of each of the handlers and see how fast the results for a given type of data are returned. Cross-referencing the latency of the request with metrics like garbage collector work, JVM memory utilization, I/O utilization, and CPU utilization allows for easy diagnostics of performance problems.

![Request latency](https://thepracticaldev.s3.amazonaws.com/i/k7wrpnb4f3mj31fntvz0.png)

##Commit Events
Commit events in Solr come in various flavors. There manual commits, send with or without the indexing requests. There are [automatic commits](https://lucene.apache.org/solr/guide/7_7/updatehandlers-in-solrconfig.html#autocommit) - ones that are fired after certain criteria are met - either the time has passed or the number of documents was greater than the threshold. Why are they important? They are responsible for data persistence and data visibility. The hard commit flushes the data to the disk and clears the transaction log. The soft commit reopens the searcher object allowing Solr to see new segments and thus serve new data to your users. However, it is crucial to balance the number of commits and the time between them - they are not free and we need to be sure that our commits are not too frequent as well as not too far apart.

![Commit events](https://thepracticaldev.s3.amazonaws.com/i/zfwudc6hf09d41hr3kdw.png)

##Caches Utilization

[Caches](https://lucene.apache.org/solr/guide/7_7/query-settings-in-solrconfig.html#caches) play a crucial role in Solr performance, especially when it comes to Solr master-slave architecture. The data that is cached can be easily accessed without the need for expensive disk operations. The caches are not free - they require memory and the more information you would like to cache, the more memory it will require. That's why it is important to monitor the size and hit rate of the caches. If your caches are too small, the hit rate will be low and you will see lots of evictions - removal of the data from the caches causing CPU usage and garbage collection effectively reducing your node performance. Caches that are too large on the other hand will increase the amount of data on the JVM heap pushing the garbage collector even further and again lowering the effective performance of your nodes. You can also cross-reference the utilization of the cache with commit events - remember, each commit event discards the entries inside the cache causing its refresh and warm up which uses resources such as CPU and I/O.

The above are the key Solr metrics to pay attention to, although there are [other useful Solr metrics](https://sematext.com/docs/integration/solr), too.

#Key OS & JVM Metrics to Monitor

Apache Solr is a Java software and as such is greatly dependent on the performance of the whole Java Virtual Machine and its parts, such as [garbage collector](https://sematext.com/java-monitoring/). The JVM itself doesn’t work in isolation and is dependent on the operating system, such as available [physical memory](https://sematext.com/server-monitoring/), number of CPU cores and their speed and the [speed of the I/O](https://sematext.com/server-monitoring/) subsystem. Let's look into crucial metrics that we should be aware of.

##CPU Utilization

Majority of the operations performed by Solr are in some degree dependent on the processing power of the CPU. When you index data it needs to be processed before it is written to the disk - the more complicated the analysis configuration, the more [CPU](https://sematext.com/java-monitoring/) cycles will be needed for each document. Query time analytics - facets, need to process a vast amount of documents in a subsecond time for Solr to be able to return query results in a timely manner. The Java virtual machine also requires CPU processing power for operations such as garbage collection. Correlating the CPU utilization with other metrics, i.e. request rate or request latency may reveal potential bottlenecks or point us to potential improvements.

![CPU details](https://thepracticaldev.s3.amazonaws.com/i/1mbhp1vbvrd11vf4fc8x.png)

##Memory, JVM Memory & Swap

[Free memory](https://sematext.com/java-monitoring/) and [swap space](https://sematext.com/java-monitoring/) are very important when you care about performance. The swap space is used by the operating system when there is not enough physical memory available and there is a need for assigning some more memory for applications. In such case memory pages may be swapped, which means that those will be taken out of the physical memory and written to the dedicated swap partition on the hard drive. When the data from those swapped memory pages are needed the operating system loads it from the swap space back to the physical memory. You can imagine that such an operation takes time, even the fastest solid-state drives are magnitude slower compared to RAM memory. Being aware of the implications of swapping the memory we can now easily say that the JVM applications don't like to be swapped - it kills performance. Because of that, you want to avoid you [Solr JVM heap memory](https://sematext.com/java-monitoring/) to be swapped. You should closely monitor your memory usage and swap usage and correlate that with your Solr performance or completely disable swapping.

![Swap details](https://thepracticaldev.s3.amazonaws.com/i/le08d0sce6493ycyinhd.png)

In addition to the monitoring the system memory you should also keep close attention to JVM memory and utilization of its various pools. Having the [JVM memory pools](https://sematext.com/java-monitoring/) fully utilized, especially the old generation space will result in extensive garbage collection and your Solr being completely unusable.

![JVM memory pools utilization](https://thepracticaldev.s3.amazonaws.com/i/l0ms6lsc6qha60vbdy0y.png)

##Disk Utilization

[Apache Solr is a very I/O based application](https://sematext.com/java-monitoring/) - it writes the data when indexing and reads the data when the search is performed. The more data you have the higher the utilization of your I/O subsystem will be and of course the performance of the I/O subsystem will have a direct connection to your Solr performance. Correlating the I/O read and write metrics to request latency and CPU usage can highlight potential bottlenecks in your system allowing you to scale the whole deployment better.

![IO Utilization](https://thepracticaldev.s3.amazonaws.com/i/kkesrtq8rzlitspqu3t9.png)

##Garbage Collector Statistics

When data is used inside JVM based application it is put onto the heap. First into smaller your generation, later moved to usually larger old generation heap space. Assigning an object to an appropriate heap space is one of the garbage collector responsibilities. The major responsibility and the one we are most interested in is the cleaning of the objects that are not used. When the object inside the Java code is no longer in use it can be taken out of the heap in the process of garbage collection. That process is run from time to time, like few times a second for the young generation and every now and then for the old generation heap. We need to know how fast they are, how often they are and if everything is healthy.

If your garbage collection process is not stopping the whole application and the old generation garbage collection is not constant - it is good, it usually means you have a healthy environment. Keep in mind that correlating garbage collector metrics with memory utilization and performance measurements like request latency may reveal memory issues.

![GC statistics](https://thepracticaldev.s3.amazonaws.com/i/u7wutyuinq9x05ziabfu.png)

#SolrCloud and Zookeeper

Having a healthy Zookeeper ensemble is crucial when running a SolrCloud cluster. It is responsible for keeping collection configurations, collection state required for the SolrCloud cluster to work, help with leader election and so on. When Zookeeper is in trouble, your SolrCloud cluster will not be able to accept new data, move shards around or accept new nodes joining the cluster - the only thing that may work are queries, but only to some extent.

Because healthy Zookeeper cluster is a required piece of every SolrCloud cluster it is crucial to have [full observability of the Zookeeper ensemble](https://sematext.com/java-monitoring/). You should keep an eye on metrics like:
1. Statistics of connections established with Zookeeper
2. Requests latency
3. Memory and JVM memory utilization
4. Garbage collector time and count
5. CPU utilization
6. Quorum status

![Zookeeper monitoring dashboard example](https://thepracticaldev.s3.amazonaws.com/i/8odia8rlxvb667rkalb9.png)

See a [more complete list of ZooKeeper metrics](https://sematext.com/docs/integration/zookeeper) in Sematext [docs](https://sematext.com/docs).

#Conclusion

Solr is an awesome search engine and analytics platform, allowing for blazingly fast data indexing and retrieval. Keeping all the relevant [Solr](https://sematext.com/integrations/solr-monitoring/) and [OS](https://sematext.com/server-monitoring/) metrics under observation is way easier when used with the right monitoring tool. That's why in the second part of the monitoring Solr series, we take a look at the possible options when it comes to [monitoring Solr using open source tools](https://sematext.com/blog/solr-open-source-monitoring-tools/). The last part of the series will cover [production ready Solr monitoring with Sematext](https://sematext.com/blog/solr-monitoring-made-easy-with-sematext/).