to start the application with the JMX enabled for remote connection and then configure port forwarding for to let the traffic pass through the firewall.
And it just does not work. Whatever you do you can not get that connection working. It's really annoying, frustrating and infuriating. And you did everything right ...
The dark secret is that there is a second port in play. The port for the RMI registry which is, by default, generated randomly each time you start the application. Without this port the JMX can not locate the stub required for proper remoting and fails. This makes JMX practically unusable in environments with firewalls between the monitored application and the monitoring tool.
This was fixed in JDK7u4 (and later) where you can use the following system property
to define the RMI registry port to be used. After that the only step left is to define the port forwarding for the RMI registry port and you are done. You can access your JMX enabled system through firewall. Yippie!
What brought this article to my attention (except of the well known name of Dr. Heinz M.Kabutz) was the fact that monitoring Java sockets would be the right task for BTrace - a tool I happen to be involved with.
Indeed, Dr.Kabutz does mention BTrace among the various tools he would use to achieve the objective. Unfortunately, without an example. I took this as a great opportunity to show-off :) and give the audience a working example of monitoring Java sockets using only BTrace.
You can see that with not that much coding you can completely monitor the Java socket subsystem. The code does take advantage of the built-in aggregations in BTrace to summarize the data traffic according to the socket and the direction data moves.
Also, exposing the measured data as a property of JMX bean is just the matter of annotating the accumulator variable with @Property annotation. Unfortunately, this doesn't work from the aggregations - yet.
I hope you enjoyed this small excursion to BTrace scripting and I hope I will be able to feed you with more of the interesting stuff in the time to come.