jmx monitoring of java containers on same physical host

As per official Java documentation, JMX client can use attach api to manage and monitor live java processes on the same host as JMX client. Now lets try to understand how this functionality holds in a containerized environment. Suppose I run multiple pods/containers on a single physical/virtual machine. Can a JMX client in a separate pod on the same host discover and connect to Java applications in neighboring pods on the host?

Is there an agent available as open source that does this? I would like to leverage it to auto discover Java processes on the same host run in containers or as bare-metal and collect JMX metrics. Ultimately, I want to run this agent across all physical hosts to collect JMX metrics across applications. I don't want to impose clients to expose JMX port explicitly using RMI to other hosts and manually configure them in agent.

static final String CONNECTOR_ADDRESS =
 "com.sun.management.jmxremote.localConnectorAddress";
 
// attach to the target application
// get pid of java application in neighboring pod on same host?
VirtualMachine vm = VirtualMachine.attach(pid);
 
// get the connector address
String connectorAddress =
    vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS);

// establish connection to connector server
JMXServiceURL url = new JMXServiceURL(connectorAddress);
JMXConnector = JMXConnectorFactory.connect(url);
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum