get our stats back by reflecting mxbeans correctly

This commit is contained in:
Robert Muir 2015-09-11 22:28:37 -04:00
parent 8be7fde181
commit 3ec5cf6263
2 changed files with 19 additions and 10 deletions

View File

@ -157,12 +157,10 @@ public class OsProbe {
*/
private static Method getMethod(String methodName) {
try {
Method method = osMxBean.getClass().getMethod(methodName);
method.setAccessible(true);
return method;
return Class.forName("com.sun.management.OperatingSystemMXBean").getMethod(methodName);
} catch (Throwable t) {
// not available
}
return null;
}
}
}

View File

@ -38,8 +38,8 @@ public class ProcessProbe {
private static final Method getCommittedVirtualMemorySize;
static {
getMaxFileDescriptorCountField = getMethod("getMaxFileDescriptorCount");
getOpenFileDescriptorCountField = getMethod("getOpenFileDescriptorCount");
getMaxFileDescriptorCountField = getUnixMethod("getMaxFileDescriptorCount");
getOpenFileDescriptorCountField = getUnixMethod("getOpenFileDescriptorCount");
getProcessCpuLoad = getMethod("getProcessCpuLoad");
getProcessCpuTime = getMethod("getProcessCpuTime");
getCommittedVirtualMemorySize = getMethod("getCommittedVirtualMemorySize");
@ -163,12 +163,23 @@ public class ProcessProbe {
*/
private static Method getMethod(String methodName) {
try {
Method method = osMxBean.getClass().getDeclaredMethod(methodName);
method.setAccessible(true);
return method;
return Class.forName("com.sun.management.OperatingSystemMXBean").getMethod(methodName);
} catch (Throwable t) {
// not available
}
return null;
}
}
/**
* Returns a given method of the UnixOperatingSystemMXBean,
* or null if the method is not found or unavailable.
*/
private static Method getUnixMethod(String methodName) {
try {
return Class.forName("com.sun.management.UnixOperatingSystemMXBean").getMethod(methodName);
} catch (Throwable t) {
// not available
return null;
}
}
}