Jmx4Perl on OS X

March 23, 2015

The HTTP-JMX Bridge Jolokia allows easy access to JMX. It exposes all JMX information and operations via an REST-like interface and has tons of nifty features. Jmx4Perl on the other side is a client for Jolokia, which beside Perl access modules also provides quite some nice CLI tools for accessing and installing Jolokia. This post explains how install these tools on OS X.

Jmx4Perl provides some nice CLI commands:

  • jmx4perl is a simple access tool which is useful for quick queries and ideal for inclusion in shell scripts.
  • j4psh is a powerful interactive, readline based JMX shell with tab completion and syntax highlighting.
  • jolokia is a tool for managing Jolokia agents (downloading, changing init properties etc.)

All this tools are very helpful in order to explore the JMX namespace and installing the agent. They all are fairly good documented and each of them probably deserves an own blog post.

However, the installation or Perl modules and programs is a bit tedious. Although cpan helps here and also resolves transitive dependencies it’s still a lengthy process, which fails from time to time. Native Linux packages are planned, but don’t hold your breath ;-).

For OS X users with Homebrew can install Jmx4Perl quite easily, though:

$ brew install cpanm
$ cpanm --sudo install JMX::Jmx4Perl

This will do all the heavy lifting for you and at the end all the fine Jmx4Perl tools are installed and available under /usr/local/bin.

j4psh uses libreadline for the input handling. For the best user experience GNU ReadLine is recommended. Unfortunately, OS X doesn’t ship with a true libreadline but with libedit which is a stripped down version of libreadline. In order to use GNU readline, some tricks are needed which are described in this recipe. For me, the following steps worked (but are probably a bit “dirty”):

$ brew install readline
$ brew link --force readline
$ sudo mv /usr/lib/libreadline.dylib /tmp/libreadline.dylib 
$ cpanm --sudo Term::ReadLine::Gnu
$ sudo mv /tmp/libreadline.dylib /usr/lib/libreadline.dylib
$ brew unlink readline

These steps are really only necessary if you need advanced readline functionality (or a coloured prompt in j4psh ;-).