dgildeh / JMXQuery

A simple command line too and Python module to query and collect Java metrics via JMX
https://www.outlyer.com
61 stars 35 forks source link

python27 support missing #15

Open chorejasbob opened 5 years ago

chorejasbob commented 5 years ago

The current python init.py module is not python27 compatible. Would it be possible to add support for python 2.7? I've created the following diff, which adds python2.7 support:

https://gist.github.com/chorejasbob/25ae63bc008e78d712e80daba986a6ef

chorejasbob commented 5 years ago

I've verified that the patch works on 2.7:

$ ipython
Python 2.7.15+ (default, Nov 27 2018, 23:36:35)
Type "copyright", "credits" or "license" for more information.

IPython 5.8.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:import jmxquery
jmxConnection = jmxquery.JMXConnection("service:jmx:rmi:///jndi/rmi://<dummyIP>:12347/jmxrmi")
jmxQuery = [jmxquery.JMXQuery("com.bea:ServerRuntime=AdminServer,Type=ThreadPoolRuntime,Name=ThreadPoolRuntime")]
metrics = jmxConnect:ion.query(jmxQuery)::
:--

In [2]: metrics
Out[2]:
[<jmxquery.JMXQuery instance at 0x7f80134d2ef0>,
 <jmxquery.JMXQuery instance at 0x7f80134d2f38>,
 <jmxquery.JMXQuery instance at 0x7f80134d2f80>,
 <jmxquery.JMXQuery instance at 0x7f80134d2fc8>,
 <jmxquery.JMXQuery instance at 0x7f80134ed050>,
 <jmxquery.JMXQuery instance at 0x7f80134ed098>,
 <jmxquery.JMXQuery instance at 0x7f80134ed0e0>,
 <jmxquery.JMXQuery instance at 0x7f80134ed128>,
 <jmxquery.JMXQuery instance at 0x7f80134ed170>,
 <jmxquery.JMXQuery instance at 0x7f80134ed1b8>,
 <jmxquery.JMXQuery instance at 0x7f80134ed200>,
 <jmxquery.JMXQuery instance at 0x7f80134ed248>,
 <jmxquery.JMXQuery instance at 0x7f80134ed290>,
 <jmxquery.JMXQuery instance at 0x7f80134ed2d8>,
 <jmxquery.JMXQuery instance at 0x7f80134ed320>,
 <jmxquery.JMXQuery instance at 0x7f80134ed368>,
 <jmxquery.JMXQuery instance at 0x7f80134ed3b0>,
 <jmxquery.JMXQuery instance at 0x7f80134ed3f8>,
 <jmxquery.JMXQuery instance at 0x7f80134ed440>]

In [3]: quit()
dgildeh commented 5 years ago

Hi @chorejasbob this isn't something I'm planning to do anytime soon. If you do a PR with the fix I can review and test then I'll look into merging it. Not sure what the clean way of supporting both versions in a single module is so will also need to do some research!

chorejasbob commented 5 years ago

Hi @dgildeh I've updated the 2.7 code to include the 'subprocess32' module, since it backports all of the newer functionality available in the python 3 version of the subprocess module. You can read more about it here: https://pypi.org/project/subprocess32/

I've created a new local branch and will start testing using this module. I'll create a PR once I can test and verify functionality works on both 2.7 and 3.x.