enable jmxremote on windows - java

I'm trying to enable remote monitoring by using jmxremote. When i set the options in a '.bat' file, things are ok (i can connect to the process using JConsole), but fail to do so when i try to do that when the process is ran as a service, although i use the exact properties that i use when the process runs as a '.bat' file (e.g. -Dcom.sun.management.jmxremote etc.) can you please let me know what am i missing?
(Please note, the behavior is with and withouth password/access files, with 'authenticate' and 'password' set to true and false).
Thanks
Guy

If you specify only com.sun.management.jmxremote then the connection will only work as long as the process to be monitored and the monitoring tool run under the same user.
Since services usually run under a system account that's not the case.
You will need to specify a port to listen on to enable connections from other users: use com.sun.management.jmxremote. port for this.

Related

How to define an argument when debugging a remote Java application in Ecilpse?

I am attempting to debug a remote Java application in a Linux environment with an argument. However, I can only find the option to define an argument when debugging a [local] Java application. The argument I am trying to define is java -Dsun.awt.disablegrab=true to avoid having the system hang when I debug in event handlers. Given the nature of this application, I cannot launch it locally; I can only debug it as a remote Java application and define the host as localhost. Is there a way to launch debug for a remote Java application with the aforementioned argument?
Thanks to everyone in advance!
In order to allow opening the port for remote debugging, the application (or its server)'s launch will be parametrized with Java command-line arguments already, e.g. something in the lines of:
-Djava.compiler=NONE -Xdebug -Xnoagent
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=[your desired port]
I would simply add your desired parameter to the list, when you launch the process in debug mode.
Where to find the launch configuration will depend on the type of application you're running.
Since you likely already know the port to connect to, you may want to grep it in your configuration files, in the targeted machine (i.e. in your local machine, in this specific case) - that might give you an idea what resource you need to make changes to.
Clarification
The idea here is that your local Eclipse is not launching the application when remote-debugging, it only connects to a socket of your own definition, with an open port to connect to your target machine.
Therefore, it it up to your application's launch configuration (i.e. how the java process is parametrized when launching your application) to define the socket for remote debugging if so required, and any launch parameters you may want.

Enable java remote debug in code

For example, we can enable java remote debug by adding following to command line.
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
But my application is running in yarn, I'm not sure which port is available.
So I want enable java debug in my code.
First I detect a available port and log in my program, then I can use this port to debug my application.
The address property specifies host (optionally) and port (only the port if host is left out). So address=5005 specifies the port 5005 in your case. If you want your program to wait until you connect your debugger, switch suspend=n to suspend=y.
Edit:
Maybe I misunderstood your question. In case you want to enable debugging programmatically, this won't be possible as the debugging facility JPDA is not exposing a Java API nor any other way to start and stop it programmatically.
I'm not sure this can be done from code; however according to an answer to this old question, it is possible to enable debugging for an already-running JVM using jsadebugd
As mentioned in said answer, the feature is marked experimental and unsupported so your mileage may vary.

console client for jstatd/visualgc

VisualVM/VisualGC provides quite a lot of useful GC-related metrics in real-time, but I want a command-line tool that can connect to a remote application via jstatd and record in CSV or XML ideally exactly the same metrics as VisualGC provides. It shouldn't be a problem to write my own, but from the first look I cannot find what protocol visualvm/jstatd use.
As I understand VisualGC is not open source: https://stackoverflow.com/questions/11096466/where-is-the-source-code-repository-for-visualgc, but are there any alternative open source tools? Are there any clues how about the protocol used?
I managed to connect to jstatd via RMI (default port 1099, JStatRemoteHost is the rmi-name), can attach to a particular VM - but http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/jvmstat/monitor/remote/RemoteVm.java#RemoteVm is rather a very low-level interface with jstatd.
I've checked out the VisualVM source code from https://svn.java.net/svn/visualvm~svn/trunk
and just started looking at the 5mb codebase, however it doesn't use neither RemoteHost nor RemoteVm RMI-classes.
Thanks.
First I looked at the source code of VisualVM (~5mb), created a command-line tool that registers JvmstatModelProvider on JvmstatModelFactory, gets an Application, creates JvmJvmstatModel and extracts all MonitoredValues - it connects to a remote application via jstatd and prints changed values in format timeMillis,name,value
1369270235646,sun.gc.generation.2.space.0.capacity,16777216
1369270236666,sun.os.hrt.ticks,2511500491
1369270237581,sun.gc.generation.0.space.0.used,641408
1369270237582,sun.os.hrt.ticks,2512502544
One hour later I found the right command-line tool for my task https://code.google.com/p/hatter-source-code/wiki/hotstat, that doesn't use jstatd - but fine, I can still run it remotely via ssh.

JMX client accessible locally only

I want to create a JMX agent that has to be accessible from local host only.
Please advise how can I do that.
Also help with a Simple JMX client on same machine that will connect to that JMX agent.
If somehow we can get away with specifying an explicit port, that will be helpful.
You might find this helpful. It uses the attach API for Oracle's JVM to connect to a running Java process and have it start a local only JMX agent. You would setup whatever MBeans you want to expose as usual. I get the impression that this code is similar to what JConsole does for connecting to local JVM processes. You might also want to investigate the source for Jmxterm which leverages JConsole for connecting to local JVM processes.

NativeProcess API Java Debugging?

What is your way to debug Java side when nativeProcess.standardInput.write method is invoked by Flex side? I know that it is possible but don't know how?
To be able to attach your Eclipse debugger to a running Java process you need to start that process with the following Java options…
-Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n
Once you have done this and have restarted the server, you can use your Eclipse to attach to the running process. From Eclipse go to the Debug manager and create a new Remote Java Application configuration for the process you want to connect to. Set the port number to 8001, the same as that of the options. You will also need to enter the hostname for the machine running the Java process. That is pretty much it…

Categories

Resources