Package: jccjmx
Abstract========SSH-tunnel friendly monitoring of embedded Java Runtimes using MBeans, JavaManagement Extensions (JMX) and Remote Method Invocation (RMI) for Python andPyLucenet.Rationale=========jccjmx is a convenience helper for JCC and PyLucene to create a JMX RMIconnector at runtime. The usual way to a connector with vmargs'-Dcom.sun.management.jmxremote' (or similar) works only on startup. Alsothis opens two ports (one for the connector and one for the RMI registry).The RMI registry port is assigned dynamically which makes firewall rulesor SSH/SSL tunnels impossible.jccjmx allows you to start a RMI and JMX connector programmatically withoutrestarting your Python application. The platform MBean server provides livemonitoring of JRE's memory usage (heap, caches), JRE's CPU usage, Java threads,attached Python threads and more. The JDK is shipped with two GUI programsfor monitoring: jconsole and jvisualvm.jccjmx is based on Daniel Fuchs' examples from his blog at Sun (now Oracle).I've modified his code and ported it from a premain agent to a standaloneclass.Usage=====The import order is crucial! You must import and init lucene and jccjmx inthe correct order. Otherwise your process will segfault.>>> import lucene>>> import jccjmxInitialize the VM for both packages. The second initVM() just adds the CLASSPATHof jccjmx.>>> lucene.initVM() # doctest: +ELLIPSIS<jcc.JCCEnv object at 0x...>>>> jccjmx.initVM() # doctest: +ELLIPSIS<jcc.JCCEnv object at 0x...>Create an agent that listens on port 12345. You should create just oneinstane of JccJmxAgent during the life time of your application.>>> agent = jccjmx.JccJmxAgent(12345)By default the agent is bound to 127.0.0.1. You can specificy another hostname orIP address with jccjmx.JccJmxAgent("hostname", portnumber).A RMI is created immediately and bound to "*:port" but no agent is listening yet. Youhave to activate is explicitly. This allows you to delay the agent.>>> agent.isActive()False>>> agent.start()>>> agent.isActive()True>>> agent.stop()>>> agent.isActive()FalseIn order to connect from a remote host you need to know the service URL:>>> agent.getServiceURL()u'service:jmx:rmi://127.0.0.1:12345/jndi/rmi://127.0.0.1:12345/jmxrmi'From a remote host:$ ssh -L12345:127.0.0.1:12345 server$ jconsole service:jmx:rmi://127.0.0.1:12345/jndi/rmi://127.0.0.1:12345/jmxrmiSecurity========The RMI registry is always bound to all possible network devices. Thisshouldn't be an issue but I can't guarantee it.jccjmx doesn't use SSL to authenticate clients and encrypt the connection. It'sup to you to use an encrypted tunnel. Future versions of jccjmx may supportSSL.Trouble shooting================Connection refused------------------You may get a connection refused error when the RMI hostname isn't setcorrectly. jccjmx sets the system property unless it is already set. You canforce a correct hostname with e.g.-Djava.rmi.server.hostname=127.0.0.1IPv4 vs. IPv6-------------Java prefers IPv6 connections over IPv4 connections and usually binds toIPv6 TCP. If you are having trouble with a mixed network you can force theJRE to prefer IPv4 with-Djava.net.preferIPv4Stack=trueSources=======https://blogs.oracle.com/jmxetc/entry/connecting_through_firewall_using_jmxhttps://blogs.oracle.com/jmxetc/entry/more_on_premain_and_jmxhttps://blogs.oracle.com/jmxetc/entry/jmx_connecting_through_firewalls_usingAuthors=======Christian HeimesDaniel Fuchs (original author of the JMX agent)Copyright=========Original java code::Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.JCC wrapper, start/stop features::Copyright (C) 2012 semantics GmbHsemanticsKommunikationsmanagement GmbHViktoriaallee 45D-52066 AachenGermanyTel.: +49 241 89 49 89 29eMail: info(at)semantics.dehttp://www.semantics.de/