public MemoryHealthCheck(final double threshold) { if (threshold < 0 || threshold > 1) { throw new IllegalArgumentException("Threshold percentage must be between [0-1]. Current: " + threshold); } this.threshold = threshold; this.mbean = (OperatingSystemMXBean) ManagementFactoryHelper.getOperatingSystemMXBean(); }
private AbstractStatistic createSyncronizationStatistics() { return new SynchronizationStatistics(ManagementFactoryHelper.getHotspotRuntimeMBean()); }
private AbstractStatistic createThreadStatistics() { return new HotspotThreadStatistics(ManagementFactory.getThreadMXBean(), ManagementFactoryHelper.getHotspotThreadMBean()); }
private AbstractStatistic createCompilationStatistics() { return new HotspotCompilationStatistics(ManagementFactory.getCompilationMXBean(), ManagementFactoryHelper.getHotspotCompilationMBean()); }
private AbstractStatistic createClassStatistics() { return new HotspotClassStatistics(ManagementFactory.getClassLoadingMXBean(), ManagementFactoryHelper.getHotspotClassLoadingMBean()); }
private AbstractStatistic createSafepointStatistic() { return new SafepointStatistics(ManagementFactoryHelper.getHotspotRuntimeMBean()); }
public CPUHealthCheck(final double threshold) { if (threshold < 0 || threshold > 1) { throw new IllegalArgumentException("Threshold percentage must be between [0-1]. Current: " + threshold); } this.threshold = threshold; this.mbean = (com.sun.management.OperatingSystemMXBean) ManagementFactoryHelper.getOperatingSystemMXBean(); }
import sun.management.ManagementFactoryHelper; import sun.management.counter.Counter; import java.util.NoSuchElementException; public class Test { public static void main(String[] args) { System.out.println(getContendedLockAttempts()); } private static long getContendedLockAttempts() { for (Counter counter : ManagementFactoryHelper.getHotspotRuntimeMBean().getInternalRuntimeCounters()) { if ("sun.rt._sync_ContendedLockAttempts".equals(counter.getName())) { return (long) counter.getValue(); } } throw new NoSuchElementException(); } }
private void baselineCounters() { this.lastSystemTime = System.nanoTime(); if (getOperatingSystemMXBean() instanceof OperatingSystemMXBean) { this.lastProcessCpuTime = ((OperatingSystemMXBean) getOperatingSystemMXBean()).getProcessCpuTime(); } } }
private AbstractStatistic createFileDescriptorStatistics() { java.lang.management.OperatingSystemMXBean os = ManagementFactoryHelper.getOperatingSystemMXBean(); if (os instanceof UnixOperatingSystemMXBean) { UnixOperatingSystemMXBean unixOs = (UnixOperatingSystemMXBean) os; return new FileDescriptorStatistics(unixOs); } return null; }
public synchronized double getCpuUsage() { if (this.lastSystemTime == 0) { this.baselineCounters(); return 0; } long systemTime = System.nanoTime(); long processCpuTime = 0; if (getOperatingSystemMXBean() instanceof OperatingSystemMXBean) { processCpuTime = ((OperatingSystemMXBean) getOperatingSystemMXBean()).getProcessCpuTime(); } double cpuUsage = ((double) (processCpuTime - this.lastProcessCpuTime)) / ((double) (systemTime - this.lastSystemTime)); this.lastSystemTime = systemTime; this.lastProcessCpuTime = processCpuTime; return cpuUsage; }