How do I monitor Tomcat6 with JVisualvm in Ubuntu Linux? - java

I'm trying to set up JVisualVm to monitor a Tomcat 6 instance (running on Ubuntu Server 10.04 LTS). I've seen other questions, but none of them directly answer my problem. I try to connect to Tomcat with JVisualvm and it comes back with a "Cannot connect" error - but there are TCP connections being made to the server; the server drops the connection after a short burst of traffic.
I have already added this to /etc/default/tomcat6 and restarted tomcat6
# This enables JMX in order to permit VisualVM to profile the JVM.
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
I started rmiregistry using default settings:
rmiregistry &
I haven't started jstatd; installing it on the server requires the full JDK which requires X libraries. I'm not about to install X just to get one single binary.
I wonder if not running jstatd would have something to do with it; I was of the impression that I needed neither RMI nor jstatd, as long as I could use JMX directly via the JMX port.
There is no firewall in between the server and the JVisualvm client, and the iptables host firewall is open. Using jconsole results in the same error.
Running JVisualVM against the local Ubuntu 10.04 machine (by using its IP address and JMX port) and adding a JMX instance works fine - and I'm running neither rmiregistry nor jstatd - though the monitor shows RMI threads running.
Question: What must I do (either on the server or the client) in order to be able to monitor Tomcat (and other Java programs) via JMX with JVisualVM?
Thanks in advance.

If there is no firewall, try to set java.rmi.server.hostname system property for your Tomcat. Add this to your Tomcat's JAVA_OPTS:
-Djava.rmi.server.hostname=<IP address of Ubuntu Server>
You don't need to start rmiregistry and you don't need to run jstatd to be able to monitor your Tomcat remotely.

For the record: jstatd does not require X libraries, it only depends on them via some other recommended package. You can make aptitude or apt-get skip installation of recommended packages and have jstatd installed without any X11 libraries.
For aptitude, go into options ➞ preferences ➞ Install recommended packages automatically. For apt-get, see this question on askubuntu.

Related

JProfiler: Cannot detect remote JVM

I'm running Tomcat 9 (as user tomcat) with OpenJDK 11 on an Ubuntu 18.04 server. I'd like to be able to attach JProfiler 11 to the Tomcat process.
In the past, I've simply used the option to connect to a remote JVM via ssh, and JProfiler locates the process. On this machine, JProfiler never finds the Tomcat process.
I've tried using both the su and sudo options to switch to the tomcat user. I've even enabled login directly as tomcat. No matter what, JProfiler cannot locate the JVM process.
I think this is because the /tmp/hsperfdata_tomcat folder is empty. I've set -XX:+UsePerfData even though it should be enabled by default (trying both JAVA_OPTS and CATALINA_OPTS) but that didn't solve anything. I've checked the tomcat command line, there is nothing there to disable UsePerfData. I've also monitored the folder to see if somehow the hsperfdata gets populated but then deleted - the file is never created.
How do I enable profiling with Tomcat 9 on Ubuntu 18.04 with OpenJDK 11?
UPDATE:
Using jps -l -m running as tomcat returns no output. However running it as root does list the tomcat java process, despite no entry in /tmp/hsperfdata_tomcat.
I just ran into this exact issue. I was unable to see the JVM started under tomcat user: in jprofiler (11), switching to the tomcat user via sudo showed no JVMs.
It was a permission problem on the uploaded by jprofiler. jpenable is uploaded under my remote home directory to which tomcat has no access to.
Solution was to:
ssh to remove node (with same user as what jprofiler will use)
chmod 555 ${HOME}
chmod 555 -R ${HOME}/.jprofiler11. Tomcat user needs to access ${HOME}/.jprofiler11/agent/11082_11.0.2/jprofiler11/bin/jpenable and jar file in the same dir.
Test: sudo -u tomcat ${HOME}/.jprofiler11/agent/11082_11.0.2/jprofiler11/bin/jpenable
Then you'll be able to connect your laptop jprofiler to that tomcat user via remote ssh + sudo tomcat.

Remote debugging(NOT localhost) tomcat using eclipse. Connection refused from remote machine

I have started tomcat with jpda option in a remote machine(not localhost). I was not able to access the port. It throws a connection refused. I was able to do this in localhost successfully. Then why not from a remote machine. I am using tomcat 9.X and ubuntu 16.04 and java 8
Edit 1:
The JDWP port 8000 listens only to 127.0.0.1. Is it possible to change this?
Finally, I found the issue. By default Catalina.sh(Tomcat script) binds only to localhost. If you want to access from another machine, then do
export JPDA_ADDRESS=0.0.0.0:8000
sh catalina.sh jpda start
0.0.0.0 allows from all the interfaces. You can also configure to one IP.
Another working solution is to do ssh tunnel from the remote machine to debugger machine.
ssh -L 8000:localhost:8000 user#remotemachine
If you still face any issues, then check the firewall. In ubuntu you can do it using UFW(Uncomplicated firewall)
sudo ufw enable
sudo ufw allow 8000

Tomcat does not listen on configured JMX port

On my Windows 10 PC I try to get JMX working on my local Tomcat9 installation which I start via Netbeans.
I added this line to catalina.bat
set CATALINA_OPTS="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
but without success. netstat /an does not show port 9000 listening and of course I can't connect using VisualVM.
When I check the local tomcat in VisualVM, I can see that my options are used though.
Tomcat overview in Visual VM
What am I missing to get access to JMX? Any hints are highly welcome.
Harry.

Adding Java to Boot2Docker Linux VM?

I have images which are based on Alpine Linux with only JRE, and I'd like to be able to debug some through the host machine on Boot2Docker's Tiny Core Linux VM. Is this possible, or is there a better way, besides adding JDK right into the container? I'm having trouble finding out how to get Java working in this
There's no need to install Java in the boot2docker VM. You can attach a remote debugger running on your host directly to the JVM running in your docker container. You'll need to bind the container port to the boot2docker VM (for example: docker run -p 4000:4000 myimage:latest), then connect your debugger to the exposed port on the VM (e.g. 192.168.99.100:4000).

Jconsole cannot connect to java processes running as Windows 7 Services

We have a Java process which we run as a Windows service (using srvany). It runs with Java 1.6 (1.6.0.23 at the moment).
In the past (Windows XP), I could connect JConsole to the processes, on Windows 7 I cannot do this anymore.
If I run jconsole <pid> I get “Invalid process id:4488”. The services are running as SYSTEM user.
If I make the service run as my desktop user (using “Log On as This Account”) the services process ID appear in JConsole, but they are grayed out and I cannot connect.
Is it impossible to dynamically connect to Java processes when they are running as a Windows 7 service?
Perhaps it is a 64bit/32bit problem, I have several applications compiled with 32bit JDK, which could not be opened with JConsole from 64bit JDK on Windows 7 64bit, after I downloaded the 32bit JDK it worked.
Others have been able to run jstack on 2008r2 which may provide some insight on how to get jconsole to connect on Windows 7. As you noted in your comment, the permissions are important. If the service and jconsole can't access the temp directory to write to the appropriate hsperf subdirectory, it won't work. What is also important is the location of the temp directory, the user the service is running, and the user that is running jconsole.
Running SysInternals psexec -s -i <jdk_home>\bin\jconsole <PID> can be used to run jconsole as Local System, the same user that I believe you are using to run your service.
My experience running jconsole from JDK 1.5 in Server 2008 as a system user was unsuccessful. With permissions that I thought should have been sufficient, I got a Could Not Open PerfMemory error. Java 1.6 may be a different story.
In light of all the challenges with running jconsole locally, you would probably have better luck setting it up to accept remote connections. You could set it up for local-only access with your firewall blocking that port from external access.
Add the following to JAVA_OPTION
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
Then,
Use JConsole to connecet remote session:
localhost:8086
I am currently facing the same problem but on Windows 2003 R2 (SP2). There is on open bug in Oracle Bug database (bug id 6399729)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6399729
Also there is a work-around posted towards the end. It talks about installing java in "install" mode :-), but didn't work for me on Windows 2003 though. But your mileage may vary!!
Change Environment Variable TEMP and Tmp to a different folder that you created.
Like c:\theTemp
It might be a problem with the folder %TMP%/hsperfdata_{USER_NAME}.
In my case, it worked after I :
close all applications running over the JVM
delete the folder %TMP%/hsperfdata_{USER_NAME} (exemple: C:/Temp/hsperfdata_MyUser)
reopen JConsole (it recreates the folder)
Hope it helps. You can also take a look at this thread in Oracle community.

Categories