I just successfully used Flight Recorder (part of Java Mission Control) to debug some memory-related issues. So how to use it?
First of all you application must be started with
-XX:+UnlockCommercialFeatures -XX:+FlightRecorder (you can also put it into JAVA_OPTS). Then run JAVA_HOME/bin/jmc.exe, select your application, right click on "Flight Recorder" and select "Start Flight Recording ...". On Linux it will store into /tmp/CURRENT_TIMESTAMP/ files ending with jfr (on Windows it will be in some temp directory). Any time you may right click on your recording and select "Dump ..." and it will construct from these jfr files the diagnostic information and print out the results. In case your application crashes on OutOfMemory (like mine did), you can open the jfr files directly.
There are other ways how to start the recording, see documentation.
In documentation isn't described monitoring of a remote server. How to do that? Run your server with these options (or put them to JAVA_OPTS):
Note: if you leave 7091 port open, anybody will be able to gain access!!! I have it closed. When I need to gain access, I ssh to the server using:
ssh -L 7091:SERVER_NAME:7091 USER_NAME@SERVER_NAME (I'm using port forwarding), then to connect to the server I connect to localhost on port 7091.
Made better & faster using https://www.yourkit.com/ Java Profiler