Jython

Jython, an implementation of python which runs on java, is a great tool to use to access java applications thru JMX and directly calling java classes.  We wrote here earlier about monitoring Cassandra using JMX and mentioned some command-line tools that can be used within scripts to access JMX.  Depending on exactly what you’re doing, jython may be a better way to go. Certainly the command-line tools are great for browsing mbeans and also for wrapping into scripts, and for ad-hoc administrative tasks, but a language like jython is probably a better way to go if you need to employ more complex logic.

Here are advantages to using jython, that may give it an advantage for building java monitoring scripts and agents:

  1. With jython, you can directly access JMX by calling the javax.management.remote.JMXConnectorFactory java class directly.
  2. With jython, you can directly access any java classes that your application uses. This gives you a lot of power and flexibility, especially for monitoring your custom java apps.
  3. Jython code (since it’s basically python code) is very elegant, readable and hence, maintainable.
  4. Not only is jython code elegant and readable, it’s very concise. Many monitoring scripts are 100-200 lines of code; some even less than 100.
  5. You can run jython anywhere you can run java. This may make it the best option for monitoring mobile devices and the like.

The only real downside to jython is that it’s not extremely fast, but the command line tools are about the same speed. Next we’ll check into “JPype” which is another way to access java from within python, to see if that has any clear advantage.

© Copyright 2020 Rex Consulting, Inc. – All rights reserved