[[search-monitoring]]
== Monitoring

Hibernate Search offers access to a `Statistics` object via `SearchFactory.getStatistics()`.
It allows you for example to determine which classes are indexed and how many entities are in the index.
This information is always available. However, by specifying the
`hibernate.search.generate_statistics` property in your configuration you can also collect total
and average Lucene query and object loading timings.

=== JMX

You can also enable access to the statistics via JMX.
Setting the property `hibernate.search.jmx_enabled` will automatically register the `StatisticsInfoMBean`.
Depending on your the configuration the `IndexControlMBean` and `IndexingProgressMonitorMBean` will also be
registered. In case you are having more than one JMX enabled Hibernate Search instance running
within a single JVM, you should also set `hibernate.search.jmx_bean_suffix` to a different value for
each of the instances. The specified suffix will be used to distinguish between the different MBean
instances. Let's have a closer look at the mentioned MBeans.

[TIP]
====
If you want to access your JMX beans remotely via JConsole make sure to set the system property
`com.sun.management.jmxremote` to true.
====

==== StatisticsInfoMBean

This MBean gives you access to Statistics object as described in the previous section.

==== IndexControlMBean

This MBean allows to build, optimize and purge the index for a given entity. Indexing occurs via the
mass indexing API (see <<search-batchindex-massindexer>>). A requirement for this bean to be
registered in JMX is, that the Hibernate SessionFactory is bound to JNDI via the
`hibernate.session_factory_name` property. Refer to the Hibernate Core manual for more
information on how to configure JNDI.

==== IndexingProgressMonitorMBean

This MBean is an implementation MassIndexerProgressMonitor interface.
If `hibernate.search.jmx_enabled` is enabled and the mass indexer API is used the indexing progress
can be followed via this bean. The bean will only be bound to JMX while indexing is in progress.
Once indexing is completed the MBean is not longer available.

