How to get percentage of CPU usage of OS from java

In Java 7 you can get it like so: public static double getProcessCpuLoad() throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName name = ObjectName.getInstance(“java.lang:type=OperatingSystem”); AttributeList list = mbs.getAttributes(name, new String[]{ “ProcessCpuLoad” }); if (list.isEmpty()) return Double.NaN; Attribute att = (Attribute)list.get(0); Double value = (Double)att.getValue(); // usually takes a couple of seconds before we get real … Read more

How to access JMX interface in docker from outside?

For completeness, the following solution worked. The JVM should be run with specific parameters established to enable remote docker JMX monitoring were as followed: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=<PORT> -Dcom.sun.management.jmxremote.rmi.port=<PORT> -Djava.rmi.server.hostname=<IP> where: <IP> is the IP address of the host that where you executed ‘docker run’ <PORT> is the port that must be published from docker … Read more

JConsole over ssh local port forwarding

There’s an even nicer way to do this using an SSH socks tunnel, since JConsole supports SOCKS: Create the SSH socks proxy locally on some free port (e.g. 7777): ssh -fN -D 7777 user@firewalled-host Run JConsole by specifying the SOCKS proxy (e.g. localhost:7777) and the address for the JMX server (e.g. localhost:2147) jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=7777 … Read more

How do you enable JMX in Websphere?

Following information is for Websphere 6.1 on Windows. First of all, the magic URL to connect to the MBean server is: service:jmx:iiop://<host>:<port>/jndi/JMXConnector If you have a default Websphere installation, the JNDI port number will likely be 2809, 2810, … depending on how many servers there are installed on one system and the specific one you … Read more

How to access Spring-boot JMX remotely

By default JMX is automatically accessible locally, so running jconsole locally would detect all your local java apps without port exposure. To access an app via JMX remotely you have to specify an RMI Registry port. The thing to know is that when connecting, JMX initializes on that port and then establishes a data connection … Read more

Why Java opens 3 ports when JMX is configured?

Contrary to common belief JMX/RMI doesn’t need to open all these ports. You can actually force them to be same which will mean that at the end of the day you’ll only need to punch one hole in the firewall (if firewall is your concern). Try setting System Properties: com.sun.management.jmxremote.port com.sun.management.jmxremote.rmi.port to the same value!! … Read more

How do I access memory usage programmatically via JMX?

You need to setup a JMXConnector. Here is a code snippet that will get the committed heap memory usage on a remote machine. String host =”myHost”; int port = 1234; HashMap map = new HashMap(); String[] credentials = new String[2]; credentials[0] = user; credentials[1] = password; map.put(“jmx.remote.credentials”, credentials); JMXConnector c = JMXConnectorFactory.newJMXConnector(createConnectionURL(host, port), map); c.connect(); … Read more

Remote JMX connection

Had it been on Linux the problem would be that localhost is the loopback interface, you need to application to bind to your network interface. You can use the netstat to confirm that it is not bound to the expected network interface. You can make this work by invoking the program with the system parameter … Read more