JMX connection using JMXMP hangs - jmx

I'm trying to establish a JMX connection to my tomcat instance from a java client using the below code.
JMXServiceURL url = new MXServiceURL("service:jmx:jmxmp://<host>:<port>"); //line 1
JMXConnector jmxc = JMXConnectorFactory.connect(url); //line 2
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
Where
host = remote machine where my tomcat instance is running
port = jmx enabled port. In my code it is 9840
My tomcat setenv.sh file is edited with below configurations to enable JMX
export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9840 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
But, when i execute the program, it hangs at line 2.
If i change line 1 as
JMXServiceURL target = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://<host>:<port>/jmxrmi")
to use RMI instead of JMXMP it executes and i'm able to access various MX beans.
So, i'm not able connect if i use JMXMP protocal. I'm able to connect if i use RMI protocol. What might have went wrong when i use JMXMP?
Thanks,
nks

In order to use the JMXMP client, you need to be running the JMXMP Connector Server. It cannot connect to the [default] RMI Connector Server.
Also see this question for a JMXMP agent that you can install into a running server.

Related

Unable to connect to AWS RDS instance from docker container

On my Windows 10 host machine I am able to connect to a private SQL Server RDS instance running in AWS. However, a Docker container running locally on the same machine is unable to connect with the same connection string.
From the Docker container I am able to telnet to the server on 1433 successfully. However, when I connect from code, it seems to be unable to create a connection. No exception is thrown, but this code hangs:
using (var conn = new SqlConnection(connectionString)){
// Do something
}
I am able to successfully connect to SQL Server when it is running on a EC2 instance. It appears to be specific to RDS.
Fails with both the name and IP address.
This was caused by a bug in SQLClient as described on GitHub. There were two fixes that worked:
Downgrade the project from Net Core 3.1 to 2.2
Update Docker file to use aspnet:3.1-bionic instead of aspnet:3.1-buster-slim and sdk:3.1-bionic instead of sdk:3.1-buster

Even after installing jenkins as a windows service, i have to start it through command line before accessing it through browser

I have installed jenkins as windows service but every time after starting the machine i have to execute it through command line using $ java -jar jenkins.war
I am not able to directly open it into web browser at http://localhost:8080/
Am i missing something? Any help will be really appreciated.
Copy original 'jenkins.war' into 'jenkins' directory and restart service
Clear the Windows event viewer logs for Application and System
Please ensure your services are running and up
Firewall Issue:The easiest way to track down firewall issues is to use tcpdump. Just run the following command on the Jenkins server, which is trying to connect to the slave.
More Info on firewall part:
By default, Windows Firewall prevents the TCP connections necessary to make this mechanism work. The firewall on the slave must allow the following exceptions (see List of TCP&UDP port numbers):
TCP Port 135 (DCE/RPC Locator service)
TCP Port 139 (NetBIOS Session Service)
TCP Port 445 (Windows shares)
C:\WINDOWS\system32\dllhost.exe (dllhost.exe seems to use a random port number)
C:\WINDOWS\system32\javaw.exe (Jenkins also uses a random port number)
File and Printer sharing (TCP 139, TCP 445, UDP 137, UDP 138 (possibly only a subset of these is required))
The issue is fixed now. I have changed the service properties. In service properties -> Log On->Select Local system account and select the checkbox for allow the service to interact with desktop

Remote JMX Technology

anybody work on Remote Monitoring in java (JMX).
I have to monitor Remote Tomcat instance on Linux system and i need to monitor on local window machine.
i am accessing Remote Tomcat using Putty through VPN.
Please help..
I have tried by give jmx port in catalina.sh file of tomcat with variable JAVA_OPT and further tunneling in Putty ,but i m not able to access via localhost with port ,
also by using service jmx command.
please help !!!
Thanks for your time and support in advance ..
Remote JMX needs two ports to operate properly. And the second one (the RMI registry port) is by default picked randomly causing problems with firewalls etc.
Since JDK7u4 you can use
-Dcom.sun.management.jmxremote.rmi.port=<port>
to set the RMI port to be used.
See this blog for more detailed steps.

call jmx operation on a local running process

I have a java process on a linux server, which runs with this option: -Dcom.sun.management.jmxremote
So I cannot just connect to this process via jconsole running on my local pc (because neither port nor -Dcom.sun.management.jmxremote.ssl=false options are set up).
But still, how can I connect to the application and run some operations over some of its MBeans? It this possible? I have a ssh access to the server and would be able to run it "locally" on the server (but not changing the options unfortunately)
According to JMX documentation the -Dcom.sun.management.jmxremote option
Enables the JMX remote agent and local monitoring via JMX connector published on a private
interface used by jconsole. The jconsole tool can use this connector if it is executed by
the same user ID as the user ID that started the agent. No password or access files are
checked for requests coming via this connector.
The naming is a bit unfortunate because it in fact enables the local monitoring only.
Since you can not change the options but can access the server via SSH the only option is to use X server forwarding (ssh -X ...) and run jconsole (or better yet jvisualvm which has specific optimisations for running remotely).

Not able to Connect a Remote Host to the VisualVM

I am new to Java and I'm facing a problem in connecting a Remote Host to the JVisualVM.
I've searched the Internet and followed all the steps mentioned there but still am not able to resolve the issue. The steps I followed are:
I started the jstatd on the remote server by first creating a jstatd.all.policy file in the $JAVA_HOME/bin. The file contained: grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission;};
I started the Jstatd as jstatd -J-Djava.security.policy=jstatd.all.policy
I started the Java application on the remote host as :
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false application_name
I then started as instance of the JVisualVM on my local machine and as I added the remote host, it got connected but i wasn't able to see any of the Java processes.
Can anyone please help me with this.
Thanks.
I encountered similar problems when connecting to Glassfish application server. See solutions that worked for me as they can be same for You:
Try setting on your application:
-Djava.rmi.server.hostname=*Remote_Server_External_IP_Address*
The mentioned IP address should be server external IP (may sound silly but it worked for me). The main problem in my case was JMX pointing to the localhost and looping. In config files the exact IP address should be set to the remote host. I described it as 'Problem 2' In my blog: handling connection problems
If Firewall block is an issue then I recommend trying XMing with SSH tunnel (which is simple to set). Here is instruction, if You encounter problems setting it:
Remote use of VisualVM with Xming (my blog)
Biggest advantage of using XMing is that it will work almost always when SSH is enabled. You just have to place VisualVM files on the remote host and run it from command line. XWindow will show VisualVM Window on Your local computer.
There is a chance that it is VisualVM issue - try using some other tool just to verify what is wrong. I recommend JConsole. It works similar to VisualVM and I also described details on my blog
You need to start jstatd with the additional option that points to the server's external IP or hostname:
statd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=my_server_ip/hostname
Answer based on: https://java.net/projects/visualvm/lists/users/archive/2010-03/message/8
To connect to a remote VM you have to start that remote VM with specific options:
java
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9000
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
class
After the VM is started, go to your VisualVM and do the following:
File -> Add JMX Connection
Type: yourHostName:9000 and click OK
On the left you will have the added JMX connection, double click on it and that's it!
More details on the Java Monitoring and Management Platform can be found here.
Here are the steps to do this:
Launch an ejstatd in your remote host this way (in ejstatd folder): mvn exec:java -Djava.rmi.server.hostname=<remote_host_name> -Dexec.args="-pr 1099 -ph 1100 -pv 1101" (used for "jstatd" type connection) (only specify -Djava.rmi.server.hostname if the hostname of your remote host does not match with the one you are seeing from your local network)
Launch your Java application with those additional Java parameters: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1102 -Dcom.sun.management.jmxremote.rmi.port=1102 -Djava.rmi.server.hostname=<remote_host_name> (used for "JMX" type connection) (same remark as the previous point for -Djava.rmi.server.hostname)
Open those 4 ports on your remote host and make them available to your local machine: 1099, 1100, 1101 and 1102
Launch JVisualVM
Right-click on "Remote" > "Add Remote Host..." and enter your remote host name in "Host name" (if you don't use the port 1099, you can change this in the "Advanced Settings")
Right-click on the remote host you've just created > "Add JMX Connection..." and enter "<remote_host_name>:1102" in "Connection" input, and check "Do not require SSL connection"
Your Java process will appear twice: one from the "jstatd" connection type, and one from the "JMX" connection type.
Disclaimer: I'm the author of the open source ejstatd tool.
Start jstatd in nohup on the server which needs to be monitored and connect VisualVM to the jstatd port, following below steps:
Step 1 : Create start-jstatd.sh and copy the below content:
nohup jstatd -p 1099 -J-Djava.security.policy=<(echo 'grant codebase "file:${java.home}/../lib/tools.jar" {permission java.security.AllPermission;};') &
Step 2: Give executable permission to the file:
$ chmod a+rwx start-jstatd.sh
Step 3: Start jstatd:
$ sh start-jstatd.sh
Step 4: Add Remote Host in VisualVM:
Step 5: Add JMX Connection to the Remote Host, as shown in the below image and Click OK button:

Resources