Installing JMX Exporter as a Debian Package

Posted on Tuesday, April 25, 2017

I already got a JMX Exporter installed and working on a simple Kafka server see [1].

Now I want to see if I can simplify it a little by installing the tool via a Debian package. 

The JMX Exporter build will also build a debian installation package.

Download and build

Install maven

  > sudo apt-get install maven

Clone the JMX exporter repo.

  > git clone

Head into the repo and build it.

  > cd jmx_exporter/
  > mvn package

This should create a debian package at jmx_prometheus_httpserver/target/

Check the debian package info

  > cd jmx_prometheus_httpserver/target/
  > dpkg-deb --info \

Now install it!

  > sudo dpkg -i \

Now you should have this tool installed at /usr/bin/jmx_exporter

  > ls -alh /usr/bin/jmx_exporter

This looks for its yaml file at

  > ls -alh /etc/jmx_exporter/jmx_exporter.yaml


Looking at it

  > vi /etc/jmx_exporter/jmx_exporter.yaml

The default is very basic and it listens on port 5555.

Getting it connected to Kafka

Now that I have this installed how do I get it working with some java app? 

For my simple Kafka install I need to edit the script adding in a javaagent

  > sudo vi /opt/kafka/kafka_2.11-

And add the following to the top  (Basically turn on jmx remote management)

#Should retrieve local IP address
IP_ADDR=`ip route get | awk '{print $NF; exit}'`
export KAFKA_OPTS="$KAFKA_OPTS -Djava.rmi.server.hostname=$IP_ADDR"

After you do that restart Kafka (In my particular case I run this command on the server.

  > sudo /opt/kafka/kafka_2.11- /opt/kafka/kafka_2.11-

Now that is started up start up the jmx exporter web server.

  > jmx_exporter \

Now that it has been started it should be gathering data from the kafka server via JMX remote.   Then showing all that data at localhost:9999/metrics

As a test I can run this curl.

  > curl -s

As a further test I want to see how many metrics I get

  > curl -s | grep -v ^# | wc -l

That is too much for me I want to update the .yaml file.

Let me update the yaml file.

  > vi /etc/jmx_exporter/jmx_exporter.yaml

lowercaseOutputName: true
whitelistObjectNames: [













#kafka.controller rules
  - pattern: kafka.controller<type=(KafkaController*), name=(ActiveControllerCount.*)><>(Value)
    name: kafka_controller_$1_$2_$3
    type: GAUGE

#kafka.server rules
  - pattern: kafka.server<type=(.+), name=(.+)><>(Count)
    name: kafka_server_$1_$2_$3
    type: COUNTER
  - pattern: kafka.server<type=(.+), name=(.+)><>(FiveMinuteRate)
    name: kafka_server_$1_$2_$3
    type: GAUGE
  - pattern: kafka.server<type=(ReplicaManager.*), name=((Leader|Partition)Count.*|UnderReplicatedPartitions.*)><>(Value)
    name: kafka_server_$1_$2_$3
    type: GAUGE
  - pattern: kafka.server<type=(ReplicaFetcherManager.*), name=(MaxLag.*)><>(Value)
    name: kafka_server_$1_$2_$3
    type: GAUGE
  - pattern: kafka.server<type=(DelayedOperationPurgatory.*), name=(PurgatorySize.*)><>(Value)
    name: kafka_server_$1_$2_$3
    type: GAUGE rules
 # name=TotalTimeMs -- ??Not sure why (TotalTimeMs) does not work??#
  - pattern:<type=(.+), name=(TotalTimeMs.*|RequestQueueTimeMs.*|LocalTimeMs.*|RemoteTimeMs.*|ResponseQueueTimeMs.*|ResponseSendTimeMs.*)><>(Count)
    name: kafka_network_$1_$2_$3
    type: COUNTER
  - pattern:<type=(.+), name=(TotalTimeMs.*|RequestQueueTimeMs.*|LocalTimeMs.*|RemoteTimeMs.*|ResponseQueueTimeMs.*|RepsonseSendTimeMs.*)><>(Min|Max|Mean|50th*|99th*)
    name: kafka_network_$1_$2_$3
    type: GAUGE
  - pattern:<type=(.+), name=(NetworkProcessorAvgIdlePercent.*)><>(Value)
    name: kafka_network_$1_$2_$3
    type: GAUGE

Start the JMX Exporter again

  > jmx_exporter \

  > curl -s | grep -v ^# | wc -l

With a single topic on the kafka server I get 516 data points.

If I filter down just to the kafka data points

  > curl -s | grep -v ^# | grep kafka | wc -l

So that works… but I think I prefer agent versus the web server.

But I do like having the debian package installer because not only does it install the

·        /etc/jmx_exporter/jmx_exporter.yaml
·        /usr/bin/jmx_exporter

It also installs the jar file

·         /usr/share/jmx_exporter/jmx_prometheus_httpserver-0.10-SNAPSHOT-jar-with-dependencies.jar

This gives me a good default location to put the jmx java agent exporter jar file.

Setting up the agent

Let me download the latest maven build of the jmx_prometheus_javaagent-0.9.jar file and place it in the /usr/share/jmx_exporter/ folder

  > sudo wget -P /usr/share/jmx_exporter \

Let me go back and edit my kafka start script

  > sudo vi /opt/kafka/kafka_2.11-

I am going to leave the remote jmx on as I will still use that for other reason.

Add this to the beginning


Now restart Kafka (in my case I run this)

  > sudo /opt/kafka/kafka_2.11- /opt/kafka/kafka_2.11-

Now the JMX Exporter agent should be running and I should be able to get my data out at localhost:9999/metrics

  > curl -s localhost:9999/metrics | grep -v ^# | grep kafka | wc -l

Yep worked just fine.


[1]        Prometheus and JMX

No comments:

Post a Comment