There are several options to put JMX data into Elasticsearch.

An alternative would be to directly poll the JMX data from the JVM

This way, every component has its own responsibility, there’s not much performance overhead and the metric-handling part can fail while the main app is still available.

Have a dedicated app poll the endpoint and send data to Elasticsearch

Have a feature expose JMX data on an HTTP endpoint using Jolokia

Let the application send metrics to the JVM - there’s the Spring Boot actuator for that, the overhead is pretty limited

Alternatively, one can hack his own micro-service architecture:

The most straightforward way is to use Logstash with the JMX plugin

Unfortunate setback

Any architect worth his salt (read lazy) should always consider the out-of-the-box option. The Logstash JMX plugin looks promising. After installing the plugin, the jmx input can be configured into the Logstash configuration file:

input { jmx { path => "/var/logstash/jmxconf" polling_frequency => 5 type => "jmx" } } output { stdout { codec => rubydebug } }

The plugin is designed to read JVM parameters (such as host and port), as well as the metrics to handle from JSON configuration files. In the above example, they will be watched in the /var/logstash/jmxconf folder. Moreover, they can be added, removed and updated on the fly.

Here’s an example of such configuration file:

{ "host" : "localhost", "port" : 1616, "alias" : "petclinic", "queries" : [ { "object_name" : "org.springframework.metrics:name=*,type=*,value=*", "object_alias" : "${type}.${name}.${value}" }] }

A MBean’s ObjectName can be determined from inside the jconsole:

The plugin allows wildcard in the metric’s name and usage of captured values in the alias. Also, by default, all attributes will be read (those can be restricted if necessary).

Note: when starting the business app, it’s highly recommended to set the JMX port through the com.sun.management.jmxremote.port system property.

Unfortunately, at the time of this writing, running the above configuration fails with messages of this kind:

[WARN][logstash.inputs.jmx] Failed retrieving metrics for attribute Value on object blah blah blah [WARN][logstash.inputs.jmx] undefined method `event' for =<LogStash::Inputs::Jmx:0x70836e5d>