Using VisualVM to monitor remote application server
As you all know, you can use tools like VisualVM to monitor remote Java processes. Only problem with that is you can't use Sampler and Profiler options on remote Java process.
So, how can we use this tool to monitor our application server that is running somewhere else? We can use power of Linux and little something called X11 server.
The one thing that you will need is a local PC that is running Linux (this is presumably that your server is also running Linux, but headless).
Since VisualVM comes as .zip file, you can use:
unzip visualvm_137.zip
If are you using Java older than 1.7 on your server, you must also provide JDK 1.7 so you can run VisualVM. Since Java for Linux comes as tar.gz you can use:
tar xvzf jdk-7u67-linux-x64.gz
Note: VisualVM must be started as the user who is running the Java proces you are trying to monitor, so it would be the easiest to do all this as that same user.
After this you are done with "configuring" your server for monitoring. Now on your local Linux machine, you configure your X11 to accept connections from all sources by opening your terminal and typing:
xhost +
After that, you can use ssh to connect to your server, but use -Y as option:
ssh -Y user@remotemachine
When you login into your server, position yourself in bin folder where you unzipped VisualVM and start it the usual way:
./visualvm --jdkhome "PATH_TO_JDK"
Path to JDK home is required only if you don't have Java 1.7 (or higher) on your path.
After running this command you should get a VisualVM window in your desktop, but only difference it that it will be running locally on your server with all features enabled.
There is a not so rare problem with VisualVM, Oracles monitoring tool for Java processes. On some occasions VisualVM brings an error message on startup, stating it wouldn't be able to monitor local Java applications. It immediately provides an URL with a proposal to resolve the problem (http://java.net/projects/visualvm/content/troubleshooting.html#jpswin2). The troubleshooting article points to the fact, that on Windows the useraccountnames are not case sensitive, which causes some confusion with the internal performance monitoring. The article claims it should be sufficient ta make sure the %TMP%\hsperfdata_UserName is capitalized.
To make it short: this didn't work for me in that form, since my folder was already capitalized and it took me some googling for resource to help me troubleshoot this.
Anyway I did solve the problem by running this small Java-program (remember, you will have to include several libs from the VisualVm installation folder) which creates the helpful output — I do log on with a camelcased account, but an all lowercased is expected... m)