When Java is running in a container many of the OperatingSystemMXBean accessor methods return host based information rather than container specific data.
jdk/open/src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java contains these native methods which extract Host specific data. These methods should be examine to determine if there is a container specific source of this information.
private native long getCommittedVirtualMemorySize0();
private native long getFreePhysicalMemorySize0();
private native long getFreeSwapSpaceSize0();
private native long getMaxFileDescriptorCount0();
private native long getOpenFileDescriptorCount0();
private native long getProcessCpuTime0();
private native double getProcessCpuLoad0();
private native double getSystemCpuLoad0();
private native long getTotalPhysicalMemorySize0();
private native long getTotalSwapSpaceSize0();
These Java methods should first try to extract this information from the internal container Metrics API, if available. Otherwise it should call these existing native methods.
Here are the Container Metrics implementation classes: