private void checkMemory(RoutingContext routingContext) {
    OperatingSystemMXBean bean =
        (OperatingSystemMXBean) ManagementFactoryHelper.getOperatingSystemMXBean();
    long max = bean.getTotalPhysicalMemorySize();
    long free = bean.getFreePhysicalMemorySize();

    routingContext
        .response()
        .putHeader("Content-Type", "text/plain")
        .setStatusCode(HttpResponseStatus.OK.code())
        .end(String.valueOf(max - free));
  }
Esempio n. 2
0
 /**
  * Returns a list of {@link GarbageCollectorMXBean} objects in the Java virtual machine. The Java
  * virtual machine may have one or more <tt>GarbageCollectorMXBean</tt> objects. It may add or
  * remove <tt>GarbageCollectorMXBean</tt> during execution.
  *
  * @return a list of <tt>GarbageCollectorMXBean</tt> objects.
  */
 public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
   return ManagementFactoryHelper.getGarbageCollectorMXBeans();
 }
Esempio n. 3
0
 /**
  * Returns a list of {@link MemoryManagerMXBean} objects in the Java virtual machine. The Java
  * virtual machine can have one or more memory managers. It may add or remove memory managers
  * during execution.
  *
  * @return a list of <tt>MemoryManagerMXBean</tt> objects.
  */
 public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
   return ManagementFactoryHelper.getMemoryManagerMXBeans();
 }
Esempio n. 4
0
 /**
  * Returns the managed bean for the operating system on which the Java virtual machine is running.
  *
  * @return an {@link OperatingSystemMXBean} object for the Java virtual machine.
  */
 public static OperatingSystemMXBean getOperatingSystemMXBean() {
   return ManagementFactoryHelper.getOperatingSystemMXBean();
 }
Esempio n. 5
0
 /**
  * Returns the managed bean for the compilation system of the Java virtual machine. This method
  * returns <tt>null</tt> if the Java virtual machine has no compilation system.
  *
  * @return a {@link CompilationMXBean} object for the Java virtual machine or <tt>null</tt> if the
  *     Java virtual machine has no compilation system.
  */
 public static CompilationMXBean getCompilationMXBean() {
   return ManagementFactoryHelper.getCompilationMXBean();
 }
Esempio n. 6
0
 /**
  * Returns the managed bean for the runtime system of the Java virtual machine.
  *
  * @return a {@link RuntimeMXBean} object for the Java virtual machine.
  */
 public static RuntimeMXBean getRuntimeMXBean() {
   return ManagementFactoryHelper.getRuntimeMXBean();
 }
Esempio n. 7
0
 /**
  * Returns the managed bean for the thread system of the Java virtual machine.
  *
  * @return a {@link ThreadMXBean} object for the Java virtual machine.
  */
 public static ThreadMXBean getThreadMXBean() {
   return ManagementFactoryHelper.getThreadMXBean();
 }
Esempio n. 8
0
 /**
  * Returns the managed bean for the memory system of the Java virtual machine.
  *
  * @return a {@link MemoryMXBean} object for the Java virtual machine.
  */
 public static MemoryMXBean getMemoryMXBean() {
   return ManagementFactoryHelper.getMemoryMXBean();
 }
Esempio n. 9
0
 /**
  * Returns the managed bean for the class loading system of the Java virtual machine.
  *
  * @return a {@link ClassLoadingMXBean} object for the Java virtual machine.
  */
 public static ClassLoadingMXBean getClassLoadingMXBean() {
   return ManagementFactoryHelper.getClassLoadingMXBean();
 }
Esempio n. 10
0
public class GetTotalSafepointTime {

  private static HotspotRuntimeMBean mbean =
      (HotspotRuntimeMBean) ManagementFactoryHelper.getHotspotRuntimeMBean();

  private static final long NUM_THREAD_DUMPS = 100;

  // Careful with these values.
  private static final long MIN_VALUE_FOR_PASS = 1;
  private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE;

  private static boolean trace = false;

  public static void main(String args[]) throws Exception {
    if (args.length > 0 && args[0].equals("trace")) {
      trace = true;
    }

    // Thread.getAllStackTraces() should cause safepoints.
    // If this test is failing because it doesn't,
    // MIN_VALUE_FOR_PASS should be reset to 0
    for (int i = 0; i < NUM_THREAD_DUMPS; i++) {
      Thread.getAllStackTraces();
    }

    long value = mbean.getTotalSafepointTime();

    if (trace) {
      System.out.println("Total safepoint time (ms): " + value);
    }

    if (value < MIN_VALUE_FOR_PASS || value > MAX_VALUE_FOR_PASS) {
      throw new RuntimeException(
          "Total safepoint time "
              + "illegal value: "
              + value
              + " ms "
              + "(MIN = "
              + MIN_VALUE_FOR_PASS
              + "; "
              + "MAX = "
              + MAX_VALUE_FOR_PASS
              + ")");
    }

    for (int i = 0; i < 2 * NUM_THREAD_DUMPS; i++) {
      Thread.getAllStackTraces();
    }
    long value2 = mbean.getTotalSafepointTime();

    if (trace) {
      System.out.println("Total safepoint time2 (ms): " + value2);
    }

    if (value2 <= value) {
      throw new RuntimeException(
          "Total safepoint time "
              + "did not increase "
              + "(value = "
              + value
              + "; "
              + "value2 = "
              + value2
              + ")");
    }

    System.out.println("Test passed.");
  }
}