getting insight in Neo4j’s JMX beans when running embedded

Neo4j exposes a lot of valuable information via JMX. Sometimes you want to gain some insight in some JMX beans when running Neo4j in embedded mode. For this it’s crucial to have the neo4j-jmx-[version].jar file on the classpath.

The following short Groovy script demos this by using the @Grab annotation to fetch dependencies:

@Grab(group="org.neo4j", module="neo4j-kernel", version="2.0.1")
@Grab(group="org.neo4j", module="neo4j-lucene-index", version="2.0.1")
@Grab(group='org.neo4j', module='neo4j-jmx', version='2.0.1')

import org.neo4j.graphdb.factory.GraphDatabaseFactory
import org.neo4j.jmx.JmxUtils
def db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder("/tmp/graph.db")
  .newGraphDatabase()

println "started embedded graph db"

def objectName = JmxUtils.getObjectName(db, "Primitive count")
def numberOfNodesIds = JmxUtils.getAttribute(objectName, "NumberOfNodeIdsInUse")

println "JMX says, we have $numberOfNodesIds node ids in use"

println "shutting down embedded graph db now"
db.shutdown()

For a full reference of all available JMX beans, see the Neo4j manual.

One thought on “getting insight in Neo4j’s JMX beans when running embedded

  1. admin

    Your question is totally unrelated to the article. Consider an appropriate way to ask your questions, e.g. stackoverflow.com.

Leave a Reply

Your email address will not be published. Required fields are marked *