Exemplo n.º 1
0
  /**
   * Create the JVM information
   *
   * @return
   */
  private JsonValue getJVMInformation() {
    JsonObject report = JsonValueBuilder.jsonValue();

    // Arguments
    List<String> arguments = runtimeMxBean.getInputArguments();
    JsonArray argumentsJson = report.array(JVM_ARGUMENTS_LABEL);
    for (String argument : arguments) {
      argumentsJson.add(argument);
    }

    // some useful jvm properties
    JsonObject propertiesJson = JsonValueBuilder.jsonValue();

    propertiesJson.put("java.vm.info", System.getProperty("java.vm.info"));
    propertiesJson.put("java.vm.name", System.getProperty("java.vm.info"));
    propertiesJson.put(
        "java.vm.specification.name", System.getProperty("java.vm.specification.name"));
    propertiesJson.put(
        "java.vm.specification.vendor", System.getProperty("java.vm.specification.vendor"));
    propertiesJson.put(
        "java.vm.specification.version", System.getProperty("java.vm.specification.version"));
    propertiesJson.put("java.vm.vendor", System.getProperty("java.vm.vendor"));
    propertiesJson.put("java.vm.version", System.getProperty("java.vm.version"));

    report.put(JVM_PROPERTIES_LABEL, propertiesJson.build().asMap());

    report.put(JVM_JAVA_VERSION_LABEL, System.getProperty("java.version"));

    // Memory
    JsonObject memoryJson = JsonValueBuilder.jsonValue();
    memoryJson.put(JVM_UNIT_MEMORY_LABEL, FileSizeUnit.MB);

    // Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();

    // Print used memory
    memoryJson.put(
        JVM_USED_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.totalMemory() - runtime.freeMemory()));

    // Print free memory
    memoryJson.put(JVM_FREE_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.freeMemory()));

    // Print total available memory
    memoryJson.put(JVM_TOTAL_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.totalMemory()));

    // Print Maximum available memory
    memoryJson.put(JVM_MAX_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.maxMemory()));

    // GNU systems don't support the "sun.arch.data.model" property, so we print both
    memoryJson.put(JVM_BIT_SIZE_GNU_LABEL, System.getProperty("sun.arch.data.model"));
    memoryJson.put(JVM_BIT_SIZE_LABEL, System.getProperty("os.arch"));

    report.put(JVM_MEMORY_LABEL, memoryJson.build().asMap());

    return report.build();
  }