Using JMX with Solr

Java Management Extensions (JMX) is a technology that makes it possible for complex systems to be controlled by tools without the systems and tools having any previous knowledge of each other. In essence, it is a standard interface by which complex systems can be viewed and manipulated.

Solr, like any other good citizen of the Java universe, can be controlled via a JMX interface. You can enable JMX support by adding lines to solrconfig.xml. You can use a JMX client, like jconsole, to connect with Solr. Check out the Wiki page http://wiki.apache.org/solr/SolrJmx for more information. You may also find the following overview of JMX to be useful: http://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html.

Configuring JMX

JMX configuration is provided in solrconfig.xml. Please see the JMX Technology Home Page for more details.

A rootName attribute can be used when configuring <jmx /> in solrconfig.xml. If this attribute is set, Solr uses it as the root name for all the MBeans that Solr exposes via JMX. The default name is "solr" followed by the core name.

Enabling/disabling JMX and securing access to MBeanServers is left up to the user by specifying appropriate JVM parameters and configuration. Please explore the JMX Technology Home Page for more details.

Configuring an Existing MBeanServer

The command:

<jmx />

enables JMX support in Solr if and only if an existing MBeanServer is found. Use this if you want to configure JMX with JVM parameters. Remove this to disable exposing Solr configuration and statistics to JMX. If this is specified, Solr will try to list all available MBeanServers and use the first one to register MBeans.

Configuring an Existing MBeanServer with agentId

The command:

<jmx agentId="myMBeanServer" />

enables JMX support in Solr if and only if an existing MBeanServer is found matching the given agentId. If multiple servers are found, the first one is used. If none is found, an exception is raised and depending on the configuration, Solr may refuse to start.

Configuring a New MBeanServer

The command:

<jmx serviceUrl="service:jmx:rmi:///jndi/rmi://localhost:9999/solrjmx" />

creates a new MBeanServer exposed for remote monitoring at the specific service URL. If the JMXConnectorServer can’t be started (probably because the serviceUrl is bad), an exception is thrown.

Example

Solr’s sample_techproducts_configs config set uses the simple <jmx /> configuration option. If you start the example with the necessary JVM system properties to launch an internal MBeanServer, Solr will register with it and you can connect using a tool like jconsole:

  1. Launch the techproducts example with JMX enabled:

    bin/solr -e techproducts -Dcom.sun.management.jmxremote
  2. Start jconsole (provided with the Sun JDK in the bin directory).

  3. Connect to the “start.jar” shown in the list of local processes.

  4. Switch to the "MBeans" tab. You should be able to see “solr/techproducts” listed there, at which point you can drill down and see details of every solr plugin.

Configuring a Remote Connection to Solr JMX

If you need to attach a JMX-enabled Java profiling tool, such as JConsole or VisualVM, to a remote Solr server, then you need to enable remote JMX access when starting the Solr server. Simply change the ENABLE_REMOTE_JMX_OPTS property in the include file to true. You’ll also need to choose a port for the JMX RMI connector to bind to, such as 18983. For example, if your Solr include script sets:

ENABLE_REMOTE_JMX_OPTS=true
RMI_PORT=18983

The JMX RMI connector will allow Java profiling tools to attach to port 18983. When enabled, the following properties are passed to the JVM when starting Solr:

-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.port=18983 \
-Dcom.sun.management.jmxremote.rmi.port=18983

We don’t recommend enabling remote JMX access in production, but it can sometimes be useful when doing performance and user-acceptance testing prior to going into production.

For more information about these settings, see:

Making JMX connections into machines running behind NATs (e.g. Amazon’s EC2 service) is not a simple task. The java.rmi.server.hostname system property may help, but running jconsole on the server itself and using a remote desktop is often the simplest solution. See http://web.archive.org/web/20130525022506/http://jmsbrdy.com/monitoring-java-applications-running-on-ec2-i.