in geode-core/src/main/java/org/apache/geode/internal/stats50/VMStats50.java [150:387]
static {
clBean = ManagementFactory.getClassLoadingMXBean();
memBean = ManagementFactory.getMemoryMXBean();
osBean = ManagementFactory.getOperatingSystemMXBean();
{
Method m1 = null;
Method m2 = null;
Method m3 = null;
Object bean = null;
try {
Class c =
ClassPathLoader.getLatest().forName("com.sun.management.UnixOperatingSystemMXBean");
if (c.isInstance(osBean)) {
m1 = c.getMethod("getMaxFileDescriptorCount");
m2 = c.getMethod("getOpenFileDescriptorCount");
bean = osBean;
} else {
// leave them null
}
// Always set ProcessCpuTime
m3 = osBean.getClass().getMethod("getProcessCpuTime");
if (m3 != null) {
m3.setAccessible(true);
}
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// If this ever returns, rethrow the error. We're poisoned
// now, so don't let this thread continue.
throw err;
} catch (Throwable ex) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
logger.warn(ex.getMessage());
SystemFailure.checkFailure();
// must be on a platform that does not support unix mxbean
bean = null;
m1 = null;
m2 = null;
m3 = null;
} finally {
unixBean = bean;
getMaxFileDescriptorCount = m1;
getOpenFileDescriptorCount = m2;
getProcessCpuTime = m3;
}
}
threadBean = ManagementFactory.getThreadMXBean();
if (THREAD_STATS_ENABLED) {
if (threadBean.isThreadCpuTimeSupported()) {
if (!threadBean.isThreadCpuTimeEnabled()) {
if (Boolean.getBoolean(GeodeGlossary.GEMFIRE_PREFIX + "enableCpuTime")) {
threadBean.setThreadCpuTimeEnabled(true);
}
}
}
if (threadBean.isThreadContentionMonitoringSupported()) {
if (!threadBean.isThreadContentionMonitoringEnabled()) {
if (Boolean.getBoolean(GeodeGlossary.GEMFIRE_PREFIX + "enableContentionTime")) {
threadBean.setThreadContentionMonitoringEnabled(true);
}
}
}
}
StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton();
List<StatisticDescriptor> sds = new ArrayList<>();
sds.add(f.createIntGauge("pendingFinalization",
"Number of objects that are pending finalization in the java VM.", "objects"));
sds.add(f.createIntGauge("daemonThreads", "Current number of live daemon threads in this VM.",
"threads"));
sds.add(f.createIntGauge("threads",
"Current number of live threads (both daemon and non-daemon) in this VM.", "threads"));
sds.add(
f.createIntGauge("peakThreads", "High water mark of live threads in this VM.", "threads"));
sds.add(f.createLongCounter("threadStarts",
"Total number of times a thread has been started since this vm started.", "threads"));
sds.add(f.createIntGauge("cpus", "Number of cpus available to the java VM on its machine.",
"cpus", true));
sds.add(f.createLongCounter("loadedClasses", "Total number of classes loaded since vm started.",
"classes"));
sds.add(f.createLongCounter("unloadedClasses",
"Total number of classes unloaded since vm started.", "classes", true));
sds.add(f.createLongGauge("freeMemory",
"An approximation of the total amount of memory currently available for future allocated objects, measured in bytes.",
"bytes", true));
sds.add(f.createLongGauge("totalMemory",
"The total amount of memory currently available for current and future objects, measured in bytes.",
"bytes"));
sds.add(f.createLongGauge("maxMemory",
"The maximum amount of memory that the VM will attempt to use, measured in bytes.", "bytes",
true));
sds.add(f.createLongCounter("processCpuTime", "CPU timed used by the process in nanoseconds.",
"nanoseconds"));
if (unixBean != null) {
sds.add(f.createLongGauge("fdLimit", "Maximum number of file descriptors", "fds", true));
sds.add(f.createLongGauge("fdsOpen", "Current number of open file descriptors", "fds"));
}
vmType = f.createType("VMStats", "Stats available on a 1.5 java virtual machine.",
sds.toArray(new StatisticDescriptor[0]));
pendingFinalizationCountId = vmType.nameToId("pendingFinalization");
loadedClassesId = vmType.nameToId("loadedClasses");
unloadedClassesId = vmType.nameToId("unloadedClasses");
daemonThreadsId = vmType.nameToId("daemonThreads");
peakThreadsId = vmType.nameToId("peakThreads");
threadsId = vmType.nameToId("threads");
threadStartsId = vmType.nameToId("threadStarts");
cpusId = vmType.nameToId("cpus");
freeMemoryId = vmType.nameToId("freeMemory");
totalMemoryId = vmType.nameToId("totalMemory");
maxMemoryId = vmType.nameToId("maxMemory");
processCpuTimeId = vmType.nameToId("processCpuTime");
if (unixBean != null) {
unix_fdLimitId = vmType.nameToId("fdLimit");
unix_fdsOpenId = vmType.nameToId("fdsOpen");
} else {
unix_fdLimitId = -1;
unix_fdsOpenId = -1;
}
memoryUsageType =
f.createType("VMMemoryUsageStats", "Stats available on a 1.5 memory usage area",
new StatisticDescriptor[] {f.createLongGauge("initMemory",
"Initial memory the vm requested from the operating system for this area", "bytes"),
f.createLongGauge("maxMemory",
"The maximum amount of memory this area can have in bytes.", "bytes"),
f.createLongGauge("usedMemory",
"The amount of used memory for this area, measured in bytes.", "bytes"),
f.createLongGauge("committedMemory",
"The amount of committed memory for this area, measured in bytes.", "bytes")});
mu_initMemoryId = memoryUsageType.nameToId("initMemory");
mu_maxMemoryId = memoryUsageType.nameToId("maxMemory");
mu_usedMemoryId = memoryUsageType.nameToId("usedMemory");
mu_committedMemoryId = memoryUsageType.nameToId("committedMemory");
gcType = f.createType("VMGCStats", "Stats available on a 1.5 garbage collector",
new StatisticDescriptor[] {
f.createLongCounter("collections",
"Total number of collections this garbage collector has done.", "operations"),
f.createLongCounter("collectionTime",
"Approximate elapsed time spent doing collections by this garbage collector.",
"milliseconds"),});
gc_collectionsId = gcType.nameToId("collections");
gc_collectionTimeId = gcType.nameToId("collectionTime");
mpType =
f.createType("VMMemoryPoolStats", "Stats available on a 1.5 memory pool",
new StatisticDescriptor[] {f.createLongGauge("currentInitMemory",
"Initial memory the vm requested from the operating system for this pool", "bytes"),
f.createLongGauge("currentMaxMemory",
"The maximum amount of memory this pool can have in bytes.", "bytes"),
f.createLongGauge("currentUsedMemory",
"The estimated amount of used memory currently in use for this pool, measured in bytes.",
"bytes"),
f.createLongGauge("currentCommittedMemory",
"The amount of committed memory for this pool, measured in bytes.", "bytes"),
// f.createLongGauge("collectionInitMemory",
// "Initial memory the vm requested from the operating system for this pool",
// "bytes"),
// f.createLongGauge("collectionMaxMemory",
// "The maximum amount of memory this pool can have in bytes.",
// "bytes"),
f.createLongGauge("collectionUsedMemory",
"The estimated amount of used memory after that last garbage collection of this pool, measured in bytes.",
"bytes"),
// f.createLongGauge("collectionCommittedMemory",
// "The amount of committed memory for this pool, measured in bytes.",
// "bytes"),
f.createLongGauge("collectionUsageThreshold",
"The collection usage threshold for this pool in bytes", "bytes"),
f.createLongCounter("collectionUsageExceeded",
"Total number of times the garbage collector detected that memory usage in this pool exceeded the collectionUsageThreshold",
"exceptions"),
f.createLongGauge("usageThreshold", "The usage threshold for this pool in bytes",
"bytes"),
f.createLongCounter("usageExceeded",
"Total number of times that memory usage in this pool exceeded the usageThreshold",
"exceptions")});
mp_l_initMemoryId = mpType.nameToId("currentInitMemory");
mp_l_maxMemoryId = mpType.nameToId("currentMaxMemory");
mp_l_usedMemoryId = mpType.nameToId("currentUsedMemory");
mp_l_committedMemoryId = mpType.nameToId("currentCommittedMemory");
// mp_gc_initMemoryId = mpType.nameToId("collectionInitMemory");
// mp_gc_maxMemoryId = mpType.nameToId("collectionMaxMemory");
mp_gc_usedMemoryId = mpType.nameToId("collectionUsedMemory");
// mp_gc_committedMemoryId = mpType.nameToId("collectionCommittedMemory");
mp_usageThresholdId = mpType.nameToId("usageThreshold");
mp_collectionUsageThresholdId = mpType.nameToId("collectionUsageThreshold");
mp_usageExceededId = mpType.nameToId("usageExceeded");
mp_collectionUsageExceededId = mpType.nameToId("collectionUsageExceeded");
if (THREAD_STATS_ENABLED) {
threadType = f.createType("VMThreadStats", "Stats available on a 1.5 thread",
new StatisticDescriptor[] {
f.createLongCounter("blocked",
"Total number of times this thread blocked to enter or reenter a monitor",
"operations"),
f.createLongCounter("blockedTime",
"Total amount of elapsed time, approximately, that this thread has spent blocked to enter or reenter a monitor. May need to be enabled by setting -Dgemfire.enableContentionTime=true",
"milliseconds"),
f.createLongGauge("lockOwner",
"The thread id that owns the lock that this thread is blocking on.", "threadId"),
f.createIntGauge("inNative", "1 if the thread is in native code.", "boolean"),
f.createIntGauge("suspended", "1 if this thread is suspended", "boolean"),
f.createLongCounter("waited",
"Total number of times this thread waited for notification.", "operations"),
f.createLongCounter("waitedTime",
"Total amount of elapsed time, approximately, that this thread has spent waiting for notification. May need to be enabled by setting -Dgemfire.enableContentionTime=true",
"milliseconds"),
f.createLongCounter("cpuTime",
"Total cpu time for this thread. May need to be enabled by setting -Dgemfire.enableCpuTime=true.",
"nanoseconds"),
f.createLongCounter("userTime",
"Total user time for this thread. May need to be enabled by setting -Dgemfire.enableCpuTime=true.",
"nanoseconds"),});
thread_blockedId = threadType.nameToId("blocked");
thread_waitedId = threadType.nameToId("waited");
thread_lockOwnerId = threadType.nameToId("lockOwner");
thread_inNativeId = threadType.nameToId("inNative");
thread_suspendedId = threadType.nameToId("suspended");
thread_blockedTimeId = threadType.nameToId("blockedTime");
thread_waitedTimeId = threadType.nameToId("waitedTime");
thread_cpuTimeId = threadType.nameToId("cpuTime");
thread_userTimeId = threadType.nameToId("userTime");
} else {
threadType = null;
thread_blockedId = -1;
thread_waitedId = -1;
thread_lockOwnerId = -1;
thread_inNativeId = -1;
thread_suspendedId = -1;
thread_blockedTimeId = -1;
thread_waitedTimeId = -1;
thread_cpuTimeId = -1;
thread_userTimeId = -1;
}
}